2 # vim:set ts=4 sw=4 expandtab:
3 # NodeManager plugin to support mapping unused raw disks into a slice
4 # that has the rawdisk sliver tag
7 Raw disk support for NodeManager.
9 Copies all unused devices into slices with the rawdisk attribute set.
20 def start(options, config):
21 logger.log("rawdisk plugin starting up...")
23 def get_unused_devices():
25 if os.path.exists("/dev/mapper/planetlab-rawdisk"):
26 devices.append("/dev/mapper/planetlab-rawdisk")
27 # Figure out which partitions are part of the VG
29 for i in os.listdir("/sys/block"):
30 if not i.startswith("dm-"):
32 in_vg.extend(map(lambda x: x.replace("!", "/"),
33 os.listdir("/sys/block/%s/slaves" % i)))
34 # Read the list of partitions
35 partitions = file("/proc/partitions", "r")
36 pat = re.compile("\s+")
38 buf = partitions.readline()
42 fields = re.split(pat, buf)
44 if (not dev.startswith("dm-") and dev not in in_vg and
45 os.path.exists("/dev/%s" % dev) and
46 (os.minor(os.stat("/dev/%s" % dev).st_rdev) % 2) != 0):
47 devices.append("/dev/%s" % dev)
51 def GetSlivers(data, config=None, plc=None):
52 if 'slivers' not in data:
53 logger.log("sliverauth: getslivers data lack's sliver information. IGNORING!")
56 devices = get_unused_devices()
57 for sliver in data['slivers']:
58 for attribute in sliver['attributes']:
59 name = attribute.get('tagname',attribute.get('name',''))
63 path = "/vservers/%s%s" % (sliver['name'], i)
64 if os.path.exists(path):
65 # should check whether its the proper type of device
68 logger.log("Copying %s to %s" % (i, path))
70 if os.path.exists(path):
75 os.makedirs(os.path.dirname(path), 0755)
78 os.mknod(path, st.st_mode, st.st_rdev)