2 # vim:set ts=4 sw=4 expandtab:
7 # NodeManager plugin to support mapping unused raw disks into a slice
8 # that has the rawdisk sliver tag
11 Raw disk support for NodeManager.
13 Copies all unused devices into slices with the rawdisk attribute set.
25 logger.log("rawdisk: plugin starting up...")
27 def get_unused_devices():
29 if os.path.exists("/dev/mapper/planetlab-rawdisk"):
30 devices.append("/dev/mapper/planetlab-rawdisk")
31 # Figure out which partitions are part of the VG
33 for i in os.listdir("/sys/block"):
34 if not i.startswith("dm-"):
36 in_vg.extend(map(lambda x: x.replace("!", "/"),
37 os.listdir("/sys/block/%s/slaves" % i)))
38 # Read the list of partitions
39 partitions = file("/proc/partitions", "r")
40 pat = re.compile("\s+")
42 buf = partitions.readline()
46 fields = re.split(pat, buf)
48 if (not dev.startswith("dm-") and dev not in in_vg and
49 os.path.exists("/dev/%s" % dev) and
50 (os.minor(os.stat("/dev/%s" % dev).st_rdev) % 2) != 0):
51 devices.append("/dev/%s" % dev)
55 def GetSlivers(data, config=None, plc=None):
56 if 'slivers' not in data:
57 logger.log_missing_data("rawdisk.GetSlivers",'slivers')
60 devices = get_unused_devices()
61 for sliver in data['slivers']:
62 for attribute in sliver['attributes']:
63 name = attribute.get('tagname',attribute.get('name',''))
67 path = "/vservers/%s%s" % (sliver['name'], i)
68 if os.path.exists(path):
69 # should check whether its the proper type of device
72 logger.log("rawdisk: Copying %s to %s" % (i, path))
74 if os.path.exists(path):
79 os.makedirs(os.path.dirname(path), 0755)
82 os.mknod(path, st.st_mode, st.st_rdev)