3 import InstallPartitionDisks
4 from Exceptions import *
5 from systeminfo import systeminfo
13 Find any new large block devices we can add to the vservers volume group
15 Expect the following variables to be set:
16 SYSIMG_PATH the path where the system image will be mounted
17 BOOT_CD_VERSION A tuple of the current bootcd version
18 MINIMUM_DISK_SIZE any disks smaller than this size, in GB, are not used
20 Set the following variables upon successfully running:
21 ROOT_MOUNTED the node root file system is mounted
24 log.write( "\n\nStep: Checking for unused disks to add to LVM.\n" )
26 # make sure we have the variables we need
28 BOOT_CD_VERSION= vars["BOOT_CD_VERSION"]
29 if BOOT_CD_VERSION == "":
30 raise ValueError, "BOOT_CD_VERSION"
32 SYSIMG_PATH= vars["SYSIMG_PATH"]
34 raise ValueError, "SYSIMG_PATH"
36 MINIMUM_DISK_SIZE= int(vars["MINIMUM_DISK_SIZE"])
39 raise BootManagerException, "Missing variable in vars: %s\n" % var
40 except ValueError, var:
41 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
45 all_devices= sysinfo.get_block_device_list()
47 # find out if there are unused disks in all_devices that are greater
48 # than old cds need extra utilities to run lvm
49 if BOOT_CD_VERSION[0] == 2:
50 compatibility.setup_lvm_2x_cd( vars, log )
52 # will contain the new devices to add to the volume group
55 # total amount of new space in gb
58 for device in all_devices.keys():
60 (major,minor,blocks,gb_size,readonly)= all_devices[device]
62 if device[:14] == "/dev/planetlab":
63 log.write( "Skipping device %s in volume group.\n" % device )
67 log.write( "Skipping read only device %s\n" % device )
70 if gb_size < MINIMUM_DISK_SIZE:
71 log.write( "Skipping too small device %s (%4.2f)\n" %
75 log.write( "Checking device %s to see if it is part " \
76 "of the volume group.\n" % device )
78 # this is the lvm partition, if it exists on that device
79 lvm_partition= "%s1" % device
80 already_added= utils.sysexec_noerr( "pvdisplay %s | grep -q 'planetlab'" %
84 log.write( "It appears %s is part of the volume group, continuing.\n" %
88 # just to be extra paranoid, ignore the device if it already has
89 # an lvm partition on it (new disks won't have this, and that is
90 # what this code is for, so it should be ok).
91 has_lvm= utils.sysexec_noerr( "sfdisk -l %s | grep -q 'Linux LVM'" %
94 log.write( "It appears %s has/had lvm already setup on "\
95 "it, continuing.\n" % device )
99 log.write( "Attempting to add %s to the volume group\n" % device )
101 if not InstallPartitionDisks.single_partition_device( device, vars, log ):
102 log.write( "Unable to partition %s, not using it.\n" % device )
105 log.write( "Successfully initialized %s\n" % device )
107 part_path= InstallPartitionDisks.get_partition_path_from_device( device,
109 if not InstallPartitionDisks.create_lvm_physical_volume( part_path,
111 log.write( "Unable to create lvm physical volume %s, not using it.\n" %
115 log.write( "Adding %s to list of devices to add to " \
116 "planetlab volume group.\n" % device )
118 extended_gb_size= extended_gb_size + gb_size
119 new_devices.append( part_path )
122 if len(new_devices) > 0:
124 log.write( "Extending planetlab volume group.\n" )
126 log.write( "Unmounting disks.\n" )
128 # backwards compat, though, we should never hit this case post PL 3.2
129 os.stat("%s/rcfs/taskclass"%SYSIMG_PATH)
130 utils.sysexec_noerr( "chroot %s umount /rcfs" % SYSIMG_PATH, log )
134 utils.sysexec_noerr( "umount /dev/planetlab/vservers", log )
135 utils.sysexec_noerr( "umount /dev/planetlab/root", log )
136 utils.sysexec( "vgchange -an", log )
138 vars['ROOT_MOUNTED']= 0
140 if not utils.sysexec_noerr( "vgextend planetlab %s" %
141 string.join(new_devices," "), log ):
142 log.write( "Failed to add physical volumes %s to " \
143 "volume group, continuing.\n" % string.join(new_devices," "))
146 # now, get the number of unused extents, and extend the vserver
147 # logical volume by that much.
149 InstallPartitionDisks.get_remaining_extents_on_vg( vars, log )
151 log.write( "Extending vservers logical volume.\n" )
153 if not utils.sysexec_noerr("lvextend -l +%s /dev/planetlab/vservers" %
154 remaining_extents, log):
155 log.write( "Failed to extend vservers logical volume, continuing\n" )
158 log.write( "making the ext3 filesystem match new logical volume size.\n" )
159 if not utils.sysexec_noerr("resize2fs /dev/planetlab/vservers",log):
160 log.write( "Failed to make ext3 file system match, continuing\n" )
163 log.write( "Succesfully extended vservers partition by %4.2f GB\n" %
166 log.write( "No new disk devices to add to volume group.\n" )