2 # vim:set ts=4 sw=4 expandtab:
4 # NodeManager plugin to support mapping unused raw disks into a slice
5 # that has the rawdisk sliver tag
8 Raw disk support for NodeManager.
10 Copies all unused devices into slices with the rawdisk attribute set.
22 logger.log("rawdisk: plugin starting up...")
24 def get_unused_devices():
26 if os.path.exists("/dev/mapper/planetlab-rawdisk"):
27 devices.append("/dev/mapper/planetlab-rawdisk")
28 # Figure out which partitions are part of the VG
30 for i in os.listdir("/sys/block"):
31 if not i.startswith("dm-"):
33 in_vg.extend(map(lambda x: x.replace("!", "/"),
34 os.listdir("/sys/block/%s/slaves" % i)))
35 # Read the list of partitions
36 partitions = file("/proc/partitions", "r")
37 pat = re.compile("\s+")
39 buf = partitions.readline()
43 fields = re.split(pat, buf)
45 if (not dev.startswith("dm-") and dev not in in_vg and
46 os.path.exists("/dev/%s" % dev) and
47 (os.minor(os.stat("/dev/%s" % dev).st_rdev) % 2) != 0):
48 devices.append("/dev/%s" % dev)
52 def GetSlivers(data, config=None, plc=None):
53 if 'slivers' not in data:
54 logger.log_missing_data("rawdisk.GetSlivers",'slivers')
57 devices = get_unused_devices()
58 for sliver in data['slivers']:
59 for attribute in sliver['attributes']:
60 name = attribute.get('tagname',attribute.get('name',''))
64 path = "/vservers/%s%s" % (sliver['name'], i)
65 if os.path.exists(path):
66 # should check whether its the proper type of device
69 logger.log("rawdisk: Copying %s to %s" % (i, path))
71 if os.path.exists(path):
76 os.makedirs(os.path.dirname(path), 0755)
79 os.mknod(path, st.st_mode, st.st_rdev)