def run_ansible(ansible_path, ansible_hash, playbook_name, log):
try:
if (ansible_hash):
- hash_arg = '-U %s'%ansible_hash
+ hash_arg = '-U {}'.format(ansible_hash)
else:
hash_arg = ''
- utils.sysexec_noerr('ansible-pull -i hosts %s %s %s' % (ansible_path, hash_arg, playbook_name), log )
+ utils.sysexec_noerr('ansible-pull -i hosts {} {} {}'.format(ansible_path, hash_arg, playbook_name), log )
except:
pass
-def Run( vars, log ):
- log.write( "\n\nStep: Running Ansible Hook\n" )
+def Run(vars, log):
+ log.write("\n\nStep: Running Ansible Hook\n")
# make sure we have the variables we need
try:
ansible_path = vars["ANSIBLE_PATH"]
ansible_hash = None
if (ansible_path):
- run_ansible(ansible_path, ansible_hash, "%s.yml"%run_level, log)
- except KeyError, var:
- log.write( "No Ansible directive. Skipping.\n");
+ run_ansible(ansible_path, ansible_hash, "{}.yml".format(run_level), log)
+ except KeyError as var:
+ log.write("No Ansible directive. Skipping.\n");
pass
import BootAPI
-AUTH_FAILURE_COUNT_FILE= "/tmp/authfailurecount"
+AUTH_FAILURE_COUNT_FILE = "/tmp/authfailurecount"
-def Run( vars, log ):
+def Run(vars, log):
"""
Authenticate this node with PLC. This ensures that the node can operate
as normal, and that our management authority has authorized it.
NUM_AUTH_FAILURES_BEFORE_DEBUG How many failures before debug
"""
- log.write( "\n\nStep: Authenticating node with PLC.\n" )
+ log.write("\n\nStep: Authenticating node with PLC.\n")
# make sure we have the variables we need
try:
- NUM_AUTH_FAILURES_BEFORE_DEBUG= int(vars["NUM_AUTH_FAILURES_BEFORE_DEBUG"])
- except KeyError, var:
- raise BootManagerException, "Missing variable in vars: %s\n" % var
- except ValueError, var:
- raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
+ NUM_AUTH_FAILURES_BEFORE_DEBUG = int(vars["NUM_AUTH_FAILURES_BEFORE_DEBUG"])
+ except KeyError as var:
+ raise BootManagerException("Missing variable in vars: {}\n".format(var))
+ except ValueError as var:
+ raise BootManagerException("Variable in vars, shouldn't be: {}\n".format(var))
try:
- authorized= BootAPI.call_api_function( vars, "BootCheckAuthentication", () )
+ authorized = BootAPI.call_api_function(vars, "BootCheckAuthentication", ())
if authorized == 1:
- log.write( "Authentication successful.\n" )
+ log.write("Authentication successful.\n")
try:
- os.unlink( AUTH_FAILURE_COUNT_FILE )
- except OSError, e:
+ os.unlink(AUTH_FAILURE_COUNT_FILE)
+ except OSError as e:
pass
return 1
- except BootManagerException, e:
- log.write( "Authentication failed: %s.\n" % e )
+ except BootManagerException as e:
+ log.write("Authentication failed: {}.\n".format(e))
except:
# This is ugly.
if vars['DISCONNECTED_OPERATION']:
- vars['API_SERVER_INST']= None
+ vars['API_SERVER_INST'] = None
return 1
else:
raise
# increment auth failure
- auth_failure_count= 0
+ auth_failure_count = 0
try:
- auth_failure_count= int(file(AUTH_FAILURE_COUNT_FILE,"r").read().strip())
+ auth_failure_count = int(file(AUTH_FAILURE_COUNT_FILE, "r").read().strip())
except IOError:
pass
except ValueError:
auth_failure_count += 1
try:
- fail_file= file(AUTH_FAILURE_COUNT_FILE,"w")
- fail_file.write( str(auth_failure_count) )
+ fail_file = file(AUTH_FAILURE_COUNT_FILE, "w")
+ fail_file.write(str(auth_failure_count))
fail_file.close()
except IOError:
pass
if auth_failure_count >= NUM_AUTH_FAILURES_BEFORE_DEBUG:
- log.write( "Maximum number of authentication failures reached.\n" )
- log.write( "Canceling boot process and going into debug mode.\n" )
+ log.write("Maximum number of authentication failures reached.\n")
+ log.write("Canceling boot process and going into debug mode.\n")
- raise BootManagerException, "Unable to authenticate node."
+ raise BootManagerException("Unable to authenticate node.")
import StopRunlevelAgent
import MakeInitrd
-def Run( vars, log ):
+def Run(vars, log):
"""
Load the kernel off of a node and boot to it.
This step assumes the disks are mounted on SYSIMG_PATH.
ROOT_MOUNTED the node root file system is mounted
"""
- log.write( "\n\nStep: Chain booting node.\n" )
+ log.write("\n\nStep: Chain booting node.\n")
# make sure we have the variables we need
try:
- SYSIMG_PATH= vars["SYSIMG_PATH"]
+ SYSIMG_PATH = vars["SYSIMG_PATH"]
if SYSIMG_PATH == "":
- raise ValueError, "SYSIMG_PATH"
+ raise ValueError("SYSIMG_PATH")
- PLCONF_DIR= vars["PLCONF_DIR"]
+ PLCONF_DIR = vars["PLCONF_DIR"]
if PLCONF_DIR == "":
- raise ValueError, "PLCONF_DIR"
+ raise ValueError("PLCONF_DIR")
# its ok if this is blank
- NODE_SESSION= vars["NODE_SESSION"]
+ NODE_SESSION = vars["NODE_SESSION"]
- NODE_MODEL_OPTIONS= vars["NODE_MODEL_OPTIONS"]
+ NODE_MODEL_OPTIONS = vars["NODE_MODEL_OPTIONS"]
- PARTITIONS= vars["PARTITIONS"]
+ PARTITIONS = vars["PARTITIONS"]
if PARTITIONS == None:
- raise ValueError, "PARTITIONS"
+ raise ValueError("PARTITIONS")
- except KeyError, var:
- raise BootManagerException, "Missing variable in vars: %s\n" % var
- except ValueError, var:
- raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
+ except KeyError as var:
+ raise BootManagerException("Missing variable in vars: {}\n".format(var))
+ except ValueError as var:
+ raise BootManagerException("Variable in vars, shouldn't be: {}\n".format(var))
- ROOT_MOUNTED= 0
+ ROOT_MOUNTED = 0
if vars.has_key('ROOT_MOUNTED'):
- ROOT_MOUNTED= vars['ROOT_MOUNTED']
+ ROOT_MOUNTED = vars['ROOT_MOUNTED']
if ROOT_MOUNTED == 0:
- log.write( "Mounting node partitions\n" )
+ log.write("Mounting node partitions\n")
# simply creating an instance of this class and listing the system
# block devices will make them show up so vgscan can find the planetlab
# volume group
systeminfo.get_block_device_list(vars, log)
- utils.sysexec( "vgscan", log )
- utils.sysexec( "vgchange -ay planetlab", log )
+ utils.sysexec("vgscan", log)
+ utils.sysexec("vgchange -ay planetlab", log)
- utils.makedirs( SYSIMG_PATH )
+ utils.makedirs(SYSIMG_PATH)
- cmd = "mount %s %s" % (PARTITIONS["root"],SYSIMG_PATH)
- utils.sysexec( cmd, log )
- cmd = "mount -t proc none %s/proc" % SYSIMG_PATH
- utils.sysexec( cmd, log )
- cmd = "mount %s %s/vservers" % (PARTITIONS["vservers"],SYSIMG_PATH)
- utils.sysexec( cmd, log )
+ cmd = "mount {} {}".format(PARTITIONS["root"], SYSIMG_PATH)
+ utils.sysexec(cmd, log)
+ cmd = "mount -t proc none {}/proc".format(SYSIMG_PATH)
+ utils.sysexec(cmd, log)
+ cmd = "mount {} {}/vservers".format(PARTITIONS["vservers"], SYSIMG_PATH)
+ utils.sysexec(cmd, log)
- ROOT_MOUNTED= 1
- vars['ROOT_MOUNTED']= 1
+ ROOT_MOUNTED = 1
+ vars['ROOT_MOUNTED'] = 1
# write out the session value /etc/planetlab/session
try:
- session_file_path= "%s/%s/session" % (SYSIMG_PATH,PLCONF_DIR)
- session_file= file( session_file_path, "w" )
- session_file.write( str(NODE_SESSION) )
+ session_file_path = "{}/{}/session".format(SYSIMG_PATH, PLCONF_DIR)
+ session_file = file(session_file_path, "w")
+ session_file.write(str(NODE_SESSION))
session_file.close()
- session_file= None
- log.write( "Updated /etc/planetlab/session\n" )
- except IOError, e:
- log.write( "Unable to write out /etc/planetlab/session, continuing anyway\n" )
+ session_file = None
+ log.write("Updated /etc/planetlab/session\n")
+ except IOError as e:
+ log.write("Unable to write out /etc/planetlab/session, continuing anyway\n")
# update configuration files
- log.write( "Updating configuration files.\n" )
+ log.write("Updating configuration files.\n")
# avoid using conf_files initscript as we're moving to systemd on some platforms
- if (vars['ONE_PARTITION']!='1'):
+ if (vars['ONE_PARTITION'] != '1'):
try:
cmd = "/usr/bin/env python /usr/share/NodeManager/conf_files.py --noscripts"
- utils.sysexec_chroot( SYSIMG_PATH, cmd, log )
- except IOError, e:
- log.write("conf_files failed with \n %s" % e)
+ utils.sysexec_chroot(SYSIMG_PATH, cmd, log)
+ except IOError as e:
+ log.write("conf_files failed with \n {}".format(e))
# update node packages
- log.write( "Running node update.\n" )
- if os.path.exists( SYSIMG_PATH + "/usr/bin/NodeUpdate.py" ):
+ log.write("Running node update.\n")
+ if os.path.exists(SYSIMG_PATH + "/usr/bin/NodeUpdate.py"):
cmd = "/usr/bin/NodeUpdate.py start noreboot"
else:
# for backwards compatibility
cmd = "/usr/local/planetlab/bin/NodeUpdate.py start noreboot"
- utils.sysexec_chroot( SYSIMG_PATH, cmd, log )
+ utils.sysexec_chroot(SYSIMG_PATH, cmd, log)
# Re-generate initrd right before kexec call
# this is not required anymore on recent depls.
if vars['virt'] == 'vs':
- MakeInitrd.Run( vars, log )
+ MakeInitrd.Run(vars, log)
# the following step should be done by NM
- UpdateNodeConfiguration.Run( vars, log )
+ UpdateNodeConfiguration.Run(vars, log)
- log.write( "Updating ssh public host key with PLC.\n" )
- ssh_host_key= ""
+ log.write("Updating ssh public host key with PLC.\n")
+ ssh_host_key = ""
try:
- ssh_host_key_file= file("%s/etc/ssh/ssh_host_rsa_key.pub"%SYSIMG_PATH,"r")
- ssh_host_key= ssh_host_key_file.read().strip()
+ ssh_host_key_file = file("{}/etc/ssh/ssh_host_rsa_key.pub".format(SYSIMG_PATH), "r")
+ ssh_host_key = ssh_host_key_file.read().strip()
ssh_host_key_file.close()
- ssh_host_key_file= None
- except IOError, e:
+ ssh_host_key_file = None
+ except IOError as e:
pass
- update_vals= {}
- update_vals['ssh_rsa_key']= ssh_host_key
- BootAPI.call_api_function( vars, "BootUpdateNode", (update_vals,) )
+ update_vals = {}
+ update_vals['ssh_rsa_key'] = ssh_host_key
+ BootAPI.call_api_function(vars, "BootUpdateNode", (update_vals,))
# get the kernel version
if NODE_MODEL_OPTIONS & ModelOptions.SMP:
option = 'smp'
- log.write( "Copying kernel and initrd for booting.\n" )
+ log.write("Copying kernel and initrd for booting.\n")
if vars['virt'] == 'vs':
- utils.sysexec( "cp %s/boot/kernel-boot%s /tmp/kernel" % (SYSIMG_PATH,option), log )
- utils.sysexec( "cp %s/boot/initrd-boot%s /tmp/initrd" % (SYSIMG_PATH,option), log )
+ utils.sysexec("cp {}/boot/kernel-boot{} /tmp/kernel".format(SYSIMG_PATH, option), log)
+ utils.sysexec("cp {}/boot/initrd-boot{} /tmp/initrd".format(SYSIMG_PATH, option), log)
else:
# Use chroot to call rpm, b/c the bootimage&nodeimage rpm-versions may not work together
try:
- kversion = os.popen("chroot %s rpm -qa kernel | tail -1 | cut -c 8-" % SYSIMG_PATH).read().rstrip()
+ kversion = os.popen("chroot {} rpm -qa kernel | tail -1 | cut -c 8-"\
+ .format(SYSIMG_PATH)).read().rstrip()
major_version = int(kversion[0]) # Check if the string looks like a kernel version
except:
# Try a different method for non-rpm-based distributions
- kversion = os.popen("ls -lrt %s/lib/modules | tail -1 | awk '{print $9;}'"%SYSIMG_PATH).read().rstrip()
+ kversion = os.popen("ls -lrt {}/lib/modules | tail -1 | awk '{print $9;}'"\
+ .format(SYSIMG_PATH)).read().rstrip()
- utils.sysexec( "cp %s/boot/vmlinuz-%s /tmp/kernel" % (SYSIMG_PATH,kversion), log )
- candidates=[]
+ utils.sysexec("cp {}/boot/vmlinuz-{} /tmp/kernel".format(SYSIMG_PATH, kversion), log)
+ candidates = []
# f16/18: expect initramfs image here
- candidates.append ("/boot/initramfs-%s.img"%(kversion))
+ candidates.append ("/boot/initramfs-{}.img".format(kversion))
# f20: uses a uid of some kind, e.g. /boot/543f88c129de443baaa65800cf3927ce/<kversion>/initrd
- candidates.append ("/boot/*/%s/initrd"%(kversion))
+ candidates.append ("/boot/*/{}/initrd".format(kversion))
# Ubuntu:
- candidates.append ("/boot/initrd.img-%s"%(kversion))
+ candidates.append ("/boot/initrd.img-{}".format(kversion))
def find_file_in_sysimg (candidates):
import glob
for pattern in candidates:
- matches=glob.glob(SYSIMG_PATH+pattern)
- log.write("locating initrd: found %d matches in %s\n"%(len(matches),pattern))
- if matches: return matches[0]
- initrd=find_file_in_sysimg(candidates)
+ matches = glob.glob(SYSIMG_PATH+pattern)
+ log.write("locating initrd: found {} matches in {}\n".format(len(matches), pattern))
+ if matches:
+ return matches[0]
+ initrd = find_file_in_sysimg(candidates)
if initrd:
- utils.sysexec( "cp %s /tmp/initrd" % initrd, log )
+ utils.sysexec("cp {} /tmp/initrd".format(initrd), log)
else:
- raise Exception,"Unable to locate initrd - bailing out"
+ raise Exception("Unable to locate initrd - bailing out")
BootAPI.save(vars)
- log.write( "Unmounting disks.\n" )
+ log.write("Unmounting disks.\n")
- if (vars['ONE_PARTITION']!='1'):
- utils.sysexec( "umount %s/vservers" % SYSIMG_PATH, log )
- utils.sysexec( "umount %s/proc" % SYSIMG_PATH, log )
- utils.sysexec_noerr( "umount %s/dev" % SYSIMG_PATH, log )
- utils.sysexec_noerr( "umount %s/sys" % SYSIMG_PATH, log )
- utils.sysexec( "umount %s" % SYSIMG_PATH, log )
- utils.sysexec( "vgchange -an", log )
+ if (vars['ONE_PARTITION'] != '1'):
+ utils.sysexec("umount {}/vservers".format(SYSIMG_PATH), log)
+ utils.sysexec("umount {}s/proc".format(SYSIMG_PATH), log)
+ utils.sysexec_noerr("umount {}s/dev".format(SYSIMG_PATH), log)
+ utils.sysexec_noerr("umount {}s/sys".format(SYSIMG_PATH), log)
+ utils.sysexec("umount {}s".format(SYSIMG_PATH), log)
+ utils.sysexec("vgchange -an", log)
- ROOT_MOUNTED= 0
- vars['ROOT_MOUNTED']= 0
+ ROOT_MOUNTED = 0
+ vars['ROOT_MOUNTED'] = 0
# Change runlevel to 'boot' prior to kexec.
- StopRunlevelAgent.Run( vars, log )
+ StopRunlevelAgent.Run(vars, log)
- log.write( "Unloading modules and chain booting to new kernel.\n" )
+ log.write("Unloading modules and chain booting to new kernel.\n")
# further use of log after Upload will only output to screen
log.Upload("/root/.bash_eternal_history")
# regardless of whether kexec works or not, we need to stop trying to
# run anything
- cancel_boot_flag= "/tmp/CANCEL_BOOT"
- utils.sysexec( "touch %s" % cancel_boot_flag, log )
+ cancel_boot_flag = "/tmp/CANCEL_BOOT"
+ utils.sysexec("touch {}".format(cancel_boot_flag), log)
# on 2.x cds (2.4 kernel) for sure, we need to shutdown everything
# to get kexec to work correctly. Even on 3.x cds (2.6 kernel),
# there are a few buggy drivers that don't disable their hardware
# correctly unless they are first unloaded.
- utils.sysexec_noerr( "ifconfig eth0 down", log )
+ utils.sysexec_noerr("ifconfig eth0 down", log)
- utils.sysexec_noerr( "killall dhclient", log )
+ utils.sysexec_noerr("killall dhclient", log)
if vars['virt'] == 'vs':
- utils.sysexec_noerr( "umount -a -r -t ext2,ext3", log )
+ utils.sysexec_noerr("umount -a -r -t ext2,ext3", log)
else:
- utils.sysexec_noerr( "umount -a -r -t ext2,ext3,btrfs", log )
- utils.sysexec_noerr( "modprobe -r lvm-mod", log )
+ utils.sysexec_noerr("umount -a -r -t ext2,ext3,btrfs", log)
+ utils.sysexec_noerr("modprobe -r lvm-mod", log)
# modules that should not get unloaded
# unloading cpqphp causes a kernel panic
blacklist = [ "floppy", "cpqphp", "i82875p_edac", "mptspi"]
try:
- modules= file("/tmp/loadedmodules","r")
+ modules = file("/tmp/loadedmodules","r")
for line in modules:
- module= string.strip(line)
+ module = string.strip(line)
if module in blacklist :
- log.write("Skipping unload of kernel module '%s'.\n"%module)
+ log.write("Skipping unload of kernel module '{}'.\n".format(module))
elif module != "":
- log.write( "Unloading %s\n" % module )
- utils.sysexec_noerr( "modprobe -r %s" % module, log )
+ log.write("Unloading {}\n".format(module))
+ utils.sysexec_noerr("modprobe -r {}".format(module), log)
if "e1000" in module:
log.write("Unloading e1000 driver; sleeping 4 seconds...\n")
time.sleep(4)
modules.close()
except IOError:
- log.write( "Couldn't read /tmp/loadedmodules, continuing.\n" )
+ log.write("Couldn't read /tmp/loadedmodules, continuing.\n")
try:
- modules= file("/proc/modules", "r")
+ modules = file("/proc/modules", "r")
# Get usage count for USB
usb_usage = 0
for line in modules:
try:
# Module Size UsageCount UsedBy State LoadAddress
- parts= string.split(line)
+ parts = string.split(line)
if parts[0] == "usb_storage":
usb_usage += int(parts[2])
- except IndexError, e:
- log.write( "Couldn't parse /proc/modules, continuing.\n" )
+ except IndexError as e:
+ log.write("Couldn't parse /proc/modules, continuing.\n")
modules.seek(0)
for line in modules:
try:
# Module Size UsageCount UsedBy State LoadAddress
- parts= string.split(line)
+ parts = string.split(line)
# While we would like to remove all "unused" modules,
# you can't trust usage count, especially for things
# if int(parts[2]) == 0:
if False and re.search('_hcd$', parts[0]):
if usb_usage > 0:
- log.write( "NOT unloading %s since USB may be in use\n" % parts[0] )
+ log.write("NOT unloading {} since USB may be in use\n".format(parts[0]))
else:
- log.write( "Unloading %s\n" % parts[0] )
- utils.sysexec_noerr( "modprobe -r %s" % parts[0], log )
- except IndexError, e:
- log.write( "Couldn't parse /proc/modules, continuing.\n" )
+ log.write("Unloading {}\n".format(parts[0]))
+ utils.sysexec_noerr("modprobe -r {}".format(parts[0]), log)
+ except IndexError as e:
+ log.write("Couldn't parse /proc/modules, continuing.\n")
except IOError:
- log.write( "Couldn't read /proc/modules, continuing.\n" )
+ log.write("Couldn't read /proc/modules, continuing.\n")
- kargs = "root=%s ramdisk_size=8192" % PARTITIONS["mapper-root"]
+ kargs = "root={} ramdisk_size=8192".format(PARTITIONS["mapper-root"])
if NODE_MODEL_OPTIONS & ModelOptions.SMP:
kargs = kargs + " " + "acpi=off"
try:
moreargs = kargsfb.readline()
kargsfb.close()
moreargs = moreargs.strip()
- log.write( 'Parsed in "%s" kexec args from /kargs.txt\n' % moreargs )
+ log.write('Parsed in "{}" kexec args from /kargs.txt\n'.format(moreargs))
kargs = kargs + " " + moreargs
except IOError:
# /kargs.txt does not exist, which is fine. Just kexec with default
# kargs, which is ramdisk_size=8192
pass
- utils.sysexec_noerr( 'hwclock --systohc --utc ', log )
+ utils.sysexec_noerr('hwclock --systohc --utc ', log)
utils.breakpoint ("Before kexec");
try:
- utils.sysexec( 'kexec --force --initrd=/tmp/initrd --append="%s" /tmp/kernel' % kargs, log)
- except BootManagerException, e:
+ utils.sysexec('kexec --force --initrd=/tmp/initrd --append="{}" /tmp/kernel'.format(kargs), log)
+ except BootManagerException as e:
# if kexec fails, we've shut the machine down to a point where nothing
# can run usefully anymore (network down, all modules unloaded, file
# systems unmounted. write out the error, and cancel the boot process
- log.write( "\n\n" )
- log.write( "-------------------------------------------------------\n" )
- log.write( "kexec failed with the following error. Please report\n" )
- log.write( "this problem to support@planet-lab.org.\n\n" )
- log.write( str(e) + "\n\n" )
- log.write( "The boot process has been canceled.\n" )
- log.write( "-------------------------------------------------------\n\n" )
+ log.write("\n\n")
+ log.write("-------------------------------------------------------\n")
+ log.write("kexec failed with the following error. Please report\n")
+ log.write("this problem to support@planet-lab.org.\n\n")
+ log.write(str(e) + "\n\n")
+ log.write("The boot process has been canceled.\n")
+ log.write("-------------------------------------------------------\n\n")
return
import ModelOptions
-def Run( vars, log ):
+def Run(vars, log):
"""
Find any new large block devices we can add to the vservers volume group
ROOT_MOUNTED the node root file system is mounted
"""
- log.write( "\n\nStep: Checking for unused disks to add to LVM.\n" )
+ log.write("\n\nStep: Checking for unused disks to add to LVM.\n")
# make sure we have the variables we need
try:
- SYSIMG_PATH= vars["SYSIMG_PATH"]
+ SYSIMG_PATH = vars["SYSIMG_PATH"]
if SYSIMG_PATH == "":
- raise ValueError, "SYSIMG_PATH"
+ raise ValueError("SYSIMG_PATH")
- MINIMUM_DISK_SIZE= int(vars["MINIMUM_DISK_SIZE"])
+ MINIMUM_DISK_SIZE = int(vars["MINIMUM_DISK_SIZE"])
- PARTITIONS= vars["PARTITIONS"]
+ PARTITIONS = vars["PARTITIONS"]
if PARTITIONS == None:
- raise ValueError, "PARTITIONS"
+ raise ValueError("PARTITIONS")
- NODE_MODEL_OPTIONS= vars["NODE_MODEL_OPTIONS"]
- except KeyError, var:
- raise BootManagerException, "Missing variable in vars: %s\n" % var
- except ValueError, var:
- raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
+ NODE_MODEL_OPTIONS = vars["NODE_MODEL_OPTIONS"]
+ except KeyError as var:
+ raise BootManagerException("Missing variable in vars: {}\n".format(var))
+ except ValueError as var:
+ raise BootManagerException("Variable in vars, shouldn't be: {}\n".format(var))
- all_devices= systeminfo.get_block_device_list(vars, log)
+ all_devices = systeminfo.get_block_device_list(vars, log)
# will contain the new devices to add to the volume group
- new_devices= []
+ new_devices = []
# total amount of new space in gb
- extended_gb_size= 0
+ extended_gb_size = 0
for device in all_devices.keys():
- (major,minor,blocks,gb_size,readonly)= all_devices[device]
+ (major,minor,blocks,gb_size,readonly) = all_devices[device]
if device[:14] == "/dev/planetlab":
- log.write( "Skipping device %s in volume group.\n" % device )
+ log.write("Skipping device {} in volume group.\n".format(device))
continue
if readonly:
- log.write( "Skipping read only device %s\n" % device )
+ log.write("Skipping read only device {}\n".format(device))
continue
if gb_size < MINIMUM_DISK_SIZE:
- log.write( "Skipping too small device %s (%4.2f)\n" %
- (device,gb_size) )
+ log.write("Skipping too small device {} ({:4.2f}) Gb\n"\
+ .format(device, gb_size))
continue
- log.write( "Checking device %s to see if it is part " \
- "of the volume group.\n" % device )
+ log.write("Checking device {} to see if it is part " \
+ "of the volume group.\n".format(device))
# this is the lvm partition, if it exists on that device
- lvm_partition= InstallPartitionDisks.get_partition_path_from_device( device, vars, log )
- cmd = "pvdisplay %s | grep -q 'planetlab'" % lvm_partition
+ lvm_partition = InstallPartitionDisks.get_partition_path_from_device(device, vars, log)
+ cmd = "pvdisplay {} | grep -q 'planetlab'".format(lvm_partition)
already_added = utils.sysexec_noerr(cmd, log, shell=True)
if already_added:
- log.write( "It appears %s is part of the volume group, continuing.\n" %
- device )
+ log.write("It appears {} is part of the volume group, continuing.\n"\
+ .format(device))
continue
# just to be extra paranoid, ignore the device if it already has
# an lvm partition on it (new disks won't have this, and that is
# what this code is for, so it should be ok).
- cmd = "parted --script --list %s | grep -q lvm$" % device
- has_lvm= utils.sysexec_noerr(cmd, log)
+ cmd = "parted --script --list {} | grep -q lvm$".format(device)
+ has_lvm = utils.sysexec_noerr(cmd, log)
if has_lvm:
- log.write( "It appears %s has lvm already setup on it.\n" % device)
+ log.write("It appears {} has lvm already setup on it.\n".format(device))
paranoid = False
if paranoid:
- log.write("To paranoid to add %s to vservers lvm.\n" % device)
+ log.write("Too paranoid to add {} to vservers lvm.\n".format(device))
continue
- if not InstallPartitionDisks.single_partition_device( device, vars, log ):
- log.write( "Unable to partition %s, not using it.\n" % device )
+ if not InstallPartitionDisks.single_partition_device(device, vars, log):
+ log.write("Unable to partition {}, not using it.\n".format(device))
continue
- log.write( "Successfully partitioned %s\n" % device )
+ log.write("Successfully partitioned {}\n".format(device))
if NODE_MODEL_OPTIONS & ModelOptions.RAWDISK:
- log.write( "Running on a raw disk node, not using it.\n" )
+ log.write("Running on a raw disk node, not using it.\n")
continue
- part_path= InstallPartitionDisks.get_partition_path_from_device( device,
- vars, log )
+ part_path = InstallPartitionDisks.get_partition_path_from_device(device,
+ vars, log)
- log.write( "Attempting to add %s to the volume group\n" % device )
+ log.write("Attempting to add {} to the volume group\n".format(device))
- if not InstallPartitionDisks.create_lvm_physical_volume( part_path,
- vars, log ):
- log.write( "Unable to create lvm physical volume %s, not using it.\n" %
- part_path )
+ if not InstallPartitionDisks.create_lvm_physical_volume(part_path,
+ vars, log):
+ log.write("Unable to create lvm physical volume {}, not using it.\n"\
+ .format(part_path))
continue
- log.write( "Adding %s to list of devices to add to " \
- "planetlab volume group.\n" % device )
+ log.write("Adding {} to list of devices to add to "
+ "planetlab volume group.\n".format(device))
- extended_gb_size= extended_gb_size + gb_size
- new_devices.append( part_path )
+ extended_gb_size = extended_gb_size + gb_size
+ new_devices.append(part_path)
if len(new_devices) > 0:
- log.write( "Extending planetlab volume group.\n" )
+ log.write("Extending planetlab volume group.\n")
- log.write( "Unmounting disks.\n" )
+ log.write("Unmounting disks.\n")
try:
# backwards compat, though, we should never hit this case post PL 3.2
- os.stat("%s/rcfs/taskclass"%SYSIMG_PATH)
- utils.sysexec_chroot_noerr( SYSIMG_PATH, "umount /rcfs", log )
- except OSError, e:
+ os.stat("{}/rcfs/taskclass".format(SYSIMG_PATH))
+ utils.sysexec_chroot_noerr(SYSIMG_PATH, "umount /rcfs", log)
+ except OSError as e:
pass
# umount in order to extend disk size
- utils.sysexec_noerr( "umount %s/proc" % SYSIMG_PATH, log )
- utils.sysexec_noerr( "umount %s/vservers" % SYSIMG_PATH, log )
- utils.sysexec_noerr( "umount %s" % SYSIMG_PATH, log )
- utils.sysexec( "vgchange -an", log )
+ utils.sysexec_noerr("umount {}/proc".format(SYSIMG_PATH), log)
+ utils.sysexec_noerr("umount {}/vservers".format(SYSIMG_PATH), log)
+ utils.sysexec_noerr("umount {}".format(SYSIMG_PATH), log)
+ utils.sysexec("vgchange -an", log)
- vars['ROOT_MOUNTED']= 0
+ vars['ROOT_MOUNTED'] = 0
while True:
- cmd = "vgextend planetlab %s" % string.join(new_devices," ")
- if not utils.sysexec_noerr( cmd, log ):
- log.write( "Failed to add physical volumes %s to " \
- "volume group, continuing.\n" % string.join(new_devices," "))
+ cmd = "vgextend planetlab {}".format(" ".join(new_devices))
+ if not utils.sysexec_noerr(cmd, log):
+ log.write("Failed to add physical volumes {} to "\
+ "volume group, continuing.\n".format(" ".join(new_devices)))
res = 1
break
# now, get the number of unused extents, and extend the vserver
# logical volume by that much.
- remaining_extents= \
- InstallPartitionDisks.get_remaining_extents_on_vg( vars, log )
+ remaining_extents = \
+ InstallPartitionDisks.get_remaining_extents_on_vg(vars, log)
- log.write( "Extending vservers logical volume.\n" )
- utils.sysexec( "vgchange -ay", log )
- cmd = "lvextend -l +%s %s" % (remaining_extents, PARTITIONS["vservers"])
+ log.write("Extending vservers logical volume.\n")
+ utils.sysexec("vgchange -ay", log)
+ cmd = "lvextend -l +{} {}".format(remaining_extents, PARTITIONS["vservers"])
if not utils.sysexec_noerr(cmd, log):
- log.write( "Failed to extend vservers logical volume, continuing\n" )
+ log.write("Failed to extend vservers logical volume, continuing\n")
res = 1
break
- log.write( "making the ext filesystem match new logical volume size.\n" )
+ log.write("making the ext filesystem match new logical volume size.\n")
- vars['ROOT_MOUNTED']= 1
- cmd = "mount %s %s" % (PARTITIONS["root"],SYSIMG_PATH)
- utils.sysexec_noerr( cmd, log )
- cmd = "mount %s %s/vservers" % \
- (PARTITIONS["vservers"],SYSIMG_PATH)
- utils.sysexec_noerr( cmd, log )
- cmd = "resize2fs %s" % PARTITIONS["vservers"]
+ vars['ROOT_MOUNTED'] = 1
+ cmd = "mount {} {}".format(PARTITIONS["root"], SYSIMG_PATH)
+ utils.sysexec_noerr(cmd, log)
+ cmd = "mount {} {}/vservers".format(PARTITIONS["vservers"], SYSIMG_PATH)
+ utils.sysexec_noerr(cmd, log)
+ cmd = "resize2fs {}".format(PARTITIONS["vservers"])
resize = utils.sysexec_noerr(cmd,log)
- utils.sysexec_noerr( "umount %s/vservers" % SYSIMG_PATH, log )
- utils.sysexec_noerr( "umount %s" % SYSIMG_PATH, log )
- vars['ROOT_MOUNTED']= 0
+ utils.sysexec_noerr("umount {}/vservers".format(SYSIMG_PATH), log)
+ utils.sysexec_noerr("umount {}".format(SYSIMG_PATH), log)
+ vars['ROOT_MOUNTED'] = 0
- utils.sysexec( "vgchange -an", log )
+ utils.sysexec("vgchange -an", log)
if not resize:
- log.write( "Failed to resize vservers partition, continuing.\n" )
+ log.write("Failed to resize vservers partition, continuing.\n")
res = 1
break
else:
- log.write( "Extended vservers partition by %4.2f GB\n" %
- extended_gb_size )
+ log.write("Extended vservers partition by {:4.2f} Gb\n"\
+ .format(extended_gb_size))
res = 1
break
else:
- log.write( "No new disk devices to add to volume group.\n" )
+ log.write("No new disk devices to add to volume group.\n")
res = 1
return res
import BootAPI
-def Run( vars, log ):
+def Run(vars, log):
"""
Make sure the hardware we are running on is sufficient for
the PlanetLab OS to be installed on. In the process, identify
INSTALL_BLOCK_DEVICES list of block devices to install onto
"""
- log.write( "\n\nStep: Checking if hardware requirements met.\n" )
+ log.write("\n\nStep: Checking if hardware requirements met.\n")
try:
- MINIMUM_MEMORY= int(vars["MINIMUM_MEMORY"])
+ MINIMUM_MEMORY = int(vars["MINIMUM_MEMORY"])
if MINIMUM_MEMORY == "":
- raise ValueError, "MINIMUM_MEMORY"
+ raise ValueError("MINIMUM_MEMORY")
- NODE_ID= vars["NODE_ID"]
+ NODE_ID = vars["NODE_ID"]
if NODE_ID == "":
raise ValueError("NODE_ID")
- MINIMUM_DISK_SIZE= int(vars["MINIMUM_DISK_SIZE"])
+ MINIMUM_DISK_SIZE = int(vars["MINIMUM_DISK_SIZE"])
# use vs_ or lxc_variants
- varname=vars['virt']+"_TOTAL_MINIMUM_DISK_SIZE"
- TOTAL_MINIMUM_DISK_SIZE= int(vars[varname])
+ varname = vars['virt'] + "_TOTAL_MINIMUM_DISK_SIZE"
+ TOTAL_MINIMUM_DISK_SIZE = int(vars[varname])
- SKIP_HARDWARE_REQUIREMENT_CHECK= \
- int(vars["SKIP_HARDWARE_REQUIREMENT_CHECK"])
+ SKIP_HARDWARE_REQUIREMENT_CHECK = int(vars["SKIP_HARDWARE_REQUIREMENT_CHECK"])
- except KeyError, var:
- raise BootManagerException, \
- "Missing variable in install store: %s" % var
- except ValueError, var:
- raise BootManagerException, \
- "Variable in install store blank, shouldn't be: %s" % var
+ except KeyError as var:
+ raise BootManagerException("Missing variable in install store: {}".format(var))
+ except ValueError as var:
+ raise BootManagerException("Variable in install store blank, shouldn't be: {}".format(var))
# lets see if we have enough memory to run
- log.write( "Checking for available memory.\n" )
+ log.write("Checking for available memory.\n")
- total_mem= systeminfo.get_total_phsyical_mem(vars, log)
+ total_mem = systeminfo.get_total_phsyical_mem(vars, log)
if total_mem is None:
- raise BootManagerException, "Unable to read total physical memory"
+ raise BootManagerException("Unable to read total physical memory")
if total_mem < MINIMUM_MEMORY:
if not SKIP_HARDWARE_REQUIREMENT_CHECK:
- log.write( "Insufficient memory to run node: %s kb\n" % total_mem )
- log.write( "Required memory: %s kb\n" % MINIMUM_MEMORY )
+ log.write("Insufficient memory to run node: {} kb\n".format(total_mem))
+ log.write("Required memory: {} kb\n".format(MINIMUM_MEMORY))
- include_pis= 0
- include_techs= 1
- include_support= 0
+ include_pis = 0
+ include_techs = 1
+ include_support = 0
- sent= 0
+ sent = 0
try:
- sent= BootAPI.call_api_function( vars, "BootNotifyOwners",
- (notify_messages.MSG_INSUFFICIENT_MEMORY,
- include_pis,
- include_techs,
- include_support) )
- except BootManagerException, e:
- log.write( "Call to BootNotifyOwners failed: %s.\n" % e )
+ sent = BootAPI.call_api_function(vars, "BootNotifyOwners",
+ (notify_messages.MSG_INSUFFICIENT_MEMORY,
+ include_pis,
+ include_techs,
+ include_support))
+ except BootManagerException as e:
+ log.write("Call to BootNotifyOwners failed: {}.\n".format(e))
if sent == 0:
- log.write( "Unable to notify site contacts of problem.\n" )
+ log.write("Unable to notify site contacts of problem.\n")
else:
- log.write( "Notified contacts of problem.\n" )
+ log.write("Notified contacts of problem.\n")
return 0
else:
- log.write( "Memory requirements not met, but running anyway: %s kb\n"
- % total_mem )
+ log.write("Memory requirements not met, but running anyway: {} kb\n"
+ .format(total_mem))
else:
- log.write( "Looks like we have enough memory: %s kb\n" % total_mem )
+ log.write("Looks like we have enough memory: {} kb\n".format(total_mem))
# get a list of block devices to attempt to install on
# (may include cdrom devices)
- install_devices= systeminfo.get_block_device_list(vars, log)
+ install_devices = systeminfo.get_block_device_list(vars, log)
# save the list of block devices in the log
- log.write( "Detected block devices:\n" )
- log.write( repr(install_devices) + "\n" )
+ log.write("Detected block devices:\n")
+ log.write(repr(install_devices) + "\n")
if not install_devices or len(install_devices) == 0:
- log.write( "No block devices detected.\n" )
+ log.write("No block devices detected.\n")
- include_pis= 0
- include_techs= 1
- include_support= 0
+ include_pis = 0
+ include_techs = 1
+ include_support = 0
- sent= 0
+ sent = 0
try:
- sent= BootAPI.call_api_function( vars, "BootNotifyOwners",
- (notify_messages.MSG_INSUFFICIENT_DISK,
- include_pis,
- include_techs,
- include_support) )
- except BootManagerException, e:
- log.write( "Call to BootNotifyOwners failed: %s.\n" % e )
+ sent = BootAPI.call_api_function(vars, "BootNotifyOwners",
+ (notify_messages.MSG_INSUFFICIENT_DISK,
+ include_pis,
+ include_techs,
+ include_support))
+ except BootManagerException as e:
+ log.write("Call to BootNotifyOwners failed: {}.\n".format(e))
if sent == 0:
- log.write( "Unable to notify site contacts of problem.\n" )
+ log.write("Unable to notify site contacts of problem.\n")
return 0
# some size threshold (set in installstore)
# also, keep track of the total size for all devices that appear usable
- total_size= 0
+ total_size = 0
for device in install_devices.keys():
- (major,minor,blocks,gb_size,readonly)= install_devices[device]
+ major, minor, blocks, gb_size, readonly = install_devices[device]
# if the device string starts with
# planetlab or dm- (device mapper), ignore it (could be old lvm setup)
continue
if gb_size < MINIMUM_DISK_SIZE:
- log.write( "Device is too small to use: %s \n(appears" \
- " to be %4.2f GB)\n" % (device,gb_size) )
+ log.write("Device is too small to use: {} \n"
+ "(appears to be {:4.2f} Gb)\n".format(device, gb_size))
try:
del install_devices[device]
- except KeyError, e:
+ except KeyError as e:
pass
continue
if readonly:
- log.write( "Device is readonly, not using: %s\n" % device )
+ log.write("Device is readonly, not using: {}\n".format(device))
try:
del install_devices[device]
- except KeyError, e:
+ except KeyError as e:
pass
continue
# add this sector count to the total count of usable
# sectors we've found.
- total_size= total_size + gb_size
+ total_size = total_size + gb_size
if len(install_devices) == 0:
- log.write( "No suitable block devices found for install.\n" )
+ log.write("No suitable block devices found for install.\n")
- include_pis= 0
- include_techs= 1
- include_support= 0
+ include_pis = 0
+ include_techs = 1
+ include_support = 0
- sent= 0
+ sent = 0
try:
- sent= BootAPI.call_api_function( vars, "BootNotifyOwners",
- (notify_messages.MSG_INSUFFICIENT_DISK,
- include_pis,
- include_techs,
- include_support) )
- except BootManagerException, e:
- log.write( "Call to BootNotifyOwners failed: %s.\n" % e )
+ sent = BootAPI.call_api_function(vars, "BootNotifyOwners",
+ (notify_messages.MSG_INSUFFICIENT_DISK,
+ include_pis,
+ include_techs,
+ include_support))
+ except BootManagerException as e:
+ log.write("Call to BootNotifyOwners failed: {}.\n".format(e))
if sent == 0:
- log.write( "Unable to notify site contacts of problem.\n" )
+ log.write("Unable to notify site contacts of problem.\n")
return 0
# show the devices we found that are usable
- log.write( "Usable block devices:\n" )
- log.write( repr(install_devices.keys()) + "\n" )
+ log.write("Usable block devices:\n")
+ log.write(repr(install_devices.keys()) + "\n")
# save the list of devices for the following steps
- vars["INSTALL_BLOCK_DEVICES"]= install_devices.keys()
+ vars["INSTALL_BLOCK_DEVICES"] = install_devices.keys()
# ensure the total disk size is large enough. if
# put the node into debug mode.
if total_size < TOTAL_MINIMUM_DISK_SIZE:
if not SKIP_HARDWARE_REQUIREMENT_CHECK:
- log.write( "The total usable disk size of all disks is " \
- "insufficient to be usable as a PlanetLab node.\n" )
- include_pis= 0
- include_techs= 1
- include_support= 0
+ log.write("The total usable disk size of all disks is " \
+ "insufficient to be usable as a PlanetLab node.\n")
+ include_pis = 0
+ include_techs = 1
+ include_support = 0
- sent= 0
+ sent = 0
try:
- sent= BootAPI.call_api_function( vars, "BootNotifyOwners",
- (notify_messages.MSG_INSUFFICIENT_DISK,
- include_pis,
- include_techs,
- include_support) )
- except BootManagerException, e:
- log.write( "Call to BootNotifyOwners failed: %s.\n" % e )
+ sent = BootAPI.call_api_function(vars, "BootNotifyOwners",
+ (notify_messages.MSG_INSUFFICIENT_DISK,
+ include_pis,
+ include_techs,
+ include_support))
+ except BootManagerException as e:
+ log.write("Call to BootNotifyOwners failed: {}.\n".format(e))
if sent == 0:
- log.write( "Unable to notify site contacts of problem.\n" )
+ log.write("Unable to notify site contacts of problem.\n")
return 0
else:
- log.write( "The total usable disk size of all disks is " \
- "insufficient, but running anyway.\n" )
+ log.write("The total usable disk size of all disks is " \
+ "insufficient, but running anyway.\n")
- log.write( "Total size for all usable block devices: %4.2f GB\n" % total_size )
+ log.write("Total size for all usable block devices: {:4.2f} Gb\n".format(total_size))
return 1
"""
-def Run( vars, log ):
+def Run(vars, log):
"""
Ask the user if we really want to wipe this machine.
a BootManagerException if anything unexpected occurred.
"""
- log.write( "\n\nStep: Confirming install with user.\n" )
+ log.write("\n\nStep: Confirming install with user.\n")
try:
- confirmation= ""
- install= 0
+ confirmation = ""
+ install = 0
print welcome_message
while confirmation not in ("yes","no"):
- confirmation= \
- raw_input("Are you sure you wish to continue (yes/no):")
- install= confirmation=="yes"
- except EOFError, e:
+ confirmation = \
+ raw_input("Are you sure you wish to continue (yes/no): ")
+ install = confirmation=="yes"
+ except EOFError as e:
pass
- except KeyboardInterrupt, e:
+ except KeyboardInterrupt as e:
pass
if install:
- log.write( "\nUser accepted install.\n" )
+ log.write("\nUser accepted install.\n")
else:
- log.write( "\nUser canceled install.\n" )
+ log.write("\nUser canceled install.\n")
return install
import BootAPI
import ModelOptions
-def Run( vars, log ):
+def Run(vars, log):
"""
Contact PLC and get the attributes for this node. Also, parse in
Raise a BootManagerException if anything fails.
"""
- log.write( "\n\nStep: Retrieving details of node from PLC.\n" )
+ log.write("\n\nStep: Retrieving details of node from PLC.\n")
# make sure we have the variables we need
try:
- SKIP_HARDWARE_REQUIREMENT_CHECK= vars["SKIP_HARDWARE_REQUIREMENT_CHECK"]
+ SKIP_HARDWARE_REQUIREMENT_CHECK = vars["SKIP_HARDWARE_REQUIREMENT_CHECK"]
if SKIP_HARDWARE_REQUIREMENT_CHECK == "":
- raise ValueError, "SKIP_HARDWARE_REQUIREMENT_CHECK"
+ raise ValueError("SKIP_HARDWARE_REQUIREMENT_CHECK")
- INTERFACE_SETTINGS= vars["INTERFACE_SETTINGS"]
+ INTERFACE_SETTINGS = vars["INTERFACE_SETTINGS"]
if INTERFACE_SETTINGS == "":
- raise ValueError, "INTERFACE_SETTINGS"
+ raise ValueError("INTERFACE_SETTINGS")
- WAS_NODE_ID_IN_CONF= vars["WAS_NODE_ID_IN_CONF"]
+ WAS_NODE_ID_IN_CONF = vars["WAS_NODE_ID_IN_CONF"]
if WAS_NODE_ID_IN_CONF == "":
- raise ValueError, "WAS_NODE_ID_IN_CONF"
+ raise ValueError("WAS_NODE_ID_IN_CONF")
- WAS_NODE_KEY_IN_CONF= vars["WAS_NODE_KEY_IN_CONF"]
+ WAS_NODE_KEY_IN_CONF = vars["WAS_NODE_KEY_IN_CONF"]
if WAS_NODE_KEY_IN_CONF == "":
- raise ValueError, "WAS_NODE_KEY_IN_CONF"
+ raise ValueError("WAS_NODE_KEY_IN_CONF")
- except KeyError, var:
- raise BootManagerException, "Missing variable in vars: %s\n" % var
- except ValueError, var:
- raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
+ except KeyError as var:
+ raise BootManagerException("Missing variable in vars: {}\n".format(var))
+ except ValueError as var:
+ raise BootManagerException("Variable in vars, shouldn't be: {}\n".format(var))
- node_details= BootAPI.call_api_function( vars, "GetNodes",
+ node_details = BootAPI.call_api_function(vars, "GetNodes",
(vars['NODE_ID'],
['boot_state', 'nodegroup_ids', 'interface_ids', 'model', 'site_id']))[0]
- vars['BOOT_STATE']= node_details['boot_state']
- vars['RUN_LEVEL']= node_details['boot_state']
- vars['NODE_MODEL']= string.strip(node_details['model'])
+ vars['BOOT_STATE'] = node_details['boot_state']
+ vars['RUN_LEVEL'] = node_details['boot_state']
+ vars['NODE_MODEL'] = string.strip(node_details['model'])
vars['SITE_ID'] = node_details['site_id']
- log.write( "Successfully retrieved node record.\n" )
- log.write( "Current boot state: %s\n" % vars['BOOT_STATE'] )
- log.write( "Node make/model: %s\n" % vars['NODE_MODEL'] )
+ log.write("Successfully retrieved node record.\n")
+ log.write("Current boot state: {}\n".format(vars['BOOT_STATE']))
+ log.write("Node make/model: {}\n".format(vars['NODE_MODEL']))
# parse in the model options from the node_model string
- model= vars['NODE_MODEL']
- options= ModelOptions.Get(model)
- vars['NODE_MODEL_OPTIONS']=options
+ model = vars['NODE_MODEL']
+ options = ModelOptions.Get(model)
+ vars['NODE_MODEL_OPTIONS'] = options
# Check if we should skip hardware requirement check
if options & ModelOptions.MINHW:
- vars['SKIP_HARDWARE_REQUIREMENT_CHECK']=1
- log.write( "node model indicates override to hardware requirements.\n" )
+ vars['SKIP_HARDWARE_REQUIREMENT_CHECK'] = 1
+ log.write("node model indicates override to hardware requirements.\n")
# this contains all the node networks, for now, we are only concerned
# in the primary network
- interfaces= BootAPI.call_api_function( vars, "GetInterfaces", (node_details['interface_ids'],))
- got_primary= 0
+ interfaces = BootAPI.call_api_function(vars, "GetInterfaces", (node_details['interface_ids'],))
+ got_primary = 0
for network in interfaces:
if network['is_primary'] == 1:
- log.write( "Primary network as returned from PLC: %s\n" % str(network) )
- got_primary= 1
+ log.write("Primary network as returned from PLC: {}\n".format(network))
+ got_primary = 1
break
if not got_primary:
- raise BootManagerException, "Node did not have a primary network."
+ raise BootManagerException("Node did not have a primary network.")
- vars['INTERFACES']= interfaces
+ vars['INTERFACES'] = interfaces
# call getNodeFlavour and store in VARS['node_flavour']
try:
- node_flavour = BootAPI.call_api_function(vars, "GetNodeFlavour", (vars['NODE_ID'], ) )
+ node_flavour = BootAPI.call_api_function(vars, "GetNodeFlavour", (vars['NODE_ID'],))
except:
- log.write("GetNodeFlavour failed, not fatal if the node flavor is available in ``configuration''\n")
+ log.write("GetNodeFlavour failed, not fatal if the node flavour is available in ``configuration''\n")
pass
flavour_keys = [
# MyPLC 5.0 workaround
# make sure to define 'extensions' even if not yet set
- if ('extensions' not in vars or vars['extensions']==''):
- vars['extensions']=[]
+ if 'extensions' not in vars or vars['extensions']=='':
+ vars['extensions'] = []
for k in flavour_keys:
- # Support MyPLC <5.2
- if (not vars.has_key(k)):
+ # Support MyPLC<5.2
+ if k not in vars:
try:
vars[k] = node_flavour[k]
except:
exc_type, exc_value, exc_traceback = sys.exc_info()
- lines=traceback.format_exception(exc_type,exc_value,exc_traceback)
- for line in lines: log.write(line)
- raise BootManagerException ("Could not call GetNodeFlavour - need PLCAPI-5.2")
+ lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
+ for line in lines:
+ log.write(line)
+ raise BootManagerException("Could not call GetNodeFlavour - need PLCAPI-5.2")
- log.write ("NodeFlavour as returned from PLC: %s\n"%node_flavour)
+ log.write ("NodeFlavour as returned from PLC: {}\n".format(node_flavour))
return 1
# locations of boot os version files
-BOOT_VERSION_2X_FILE='/usr/bootme/ID'
-BOOT_VERSION_3X_FILE='/pl_version'
+BOOT_VERSION_2X_FILE = '/usr/bootme/ID'
+BOOT_VERSION_3X_FILE = '/pl_version'
# minimium version of the boot os we need to run, as a (major,minor) tuple
-MINIMUM_BOOT_VERSION= (3,0)
+MINIMUM_BOOT_VERSION = (3, 0)
# minimum version of python required to run the boot manager
-MINIMUM_PYTHON_VERSION= (2,2,0)
+MINIMUM_PYTHON_VERSION = (2, 6, 0)
-def Run( vars, log ):
+def Run(vars, log):
"""
Setup the boot manager so it can run, do any extra necessary
hardware setup (to fix old cd problems)
BOOT_CD_VERSION A two number tuple of the boot cd version
"""
- log.write( "\n\nStep: Initializing the BootManager.\n" )
+ log.write("\n\nStep: Initializing the BootManager.\n")
# Default model option. Required in case we go into debug mode
# before we successfully called GetAndUpdateNodeDetails().
- vars["NODE_MODEL_OPTIONS"] = vars.get("NODE_MODEL_OPTIONS",0)
+ vars["NODE_MODEL_OPTIONS"] = vars.get("NODE_MODEL_OPTIONS", 0)
# define the basic partition paths
- PARTITIONS= {}
- PARTITIONS["root"]= "/dev/planetlab/root"
- PARTITIONS["swap"]= "/dev/planetlab/swap"
- PARTITIONS["vservers"]= "/dev/planetlab/vservers"
+ PARTITIONS = {}
+ PARTITIONS["root"] = "/dev/planetlab/root"
+ PARTITIONS["swap"] = "/dev/planetlab/swap"
+ PARTITIONS["vservers"] = "/dev/planetlab/vservers"
# Linux 2.6 mounts LVM with device mapper
- PARTITIONS["mapper-root"]= "/dev/mapper/planetlab-root"
- PARTITIONS["mapper-swap"]= "/dev/mapper/planetlab-swap"
- PARTITIONS["mapper-vservers"]= "/dev/mapper/planetlab-vservers"
- vars["PARTITIONS"]= PARTITIONS
+ PARTITIONS["mapper-root"] = "/dev/mapper/planetlab-root"
+ PARTITIONS["mapper-swap"] = "/dev/mapper/planetlab-swap"
+ PARTITIONS["mapper-vservers"] = "/dev/mapper/planetlab-vservers"
+ vars["PARTITIONS"] = PARTITIONS
- log.write( "Opening connection to API server\n" )
+ log.write("Opening connection to API server\n")
try:
- api_inst= xmlrpclib.Server( vars['BOOT_API_SERVER'], verbose=0 )
- except KeyError, e:
- raise BootManagerException, \
- "configuration file does not specify API server URL"
+ api_inst = xmlrpclib.Server(vars['BOOT_API_SERVER'], verbose=0)
+ except KeyError as e:
+ raise BootManagerException("configuration file does not specify API server URL")
- vars['API_SERVER_INST']= api_inst
+ vars['API_SERVER_INST'] = api_inst
- if not __check_boot_version( vars, log ):
- raise BootManagerException, \
- "Boot CD version insufficient to run the Boot Manager"
+ if not __check_boot_version(vars, log):
+ raise BootManagerException("Boot CD version insufficient to run the Boot Manager")
else:
- log.write( "Running on boot cd version: %s\n" %
- str(vars['BOOT_CD_VERSION']) )
+ log.write("Running on boot cd version: {}\n".format(vars['BOOT_CD_VERSION']))
- BOOT_CD_VERSION= vars['BOOT_CD_VERSION']
+ BOOT_CD_VERSION = vars['BOOT_CD_VERSION']
# In case we are booted with a kernel that does not have the
# device mapper code compiled into the kernel.
if not os.path.exists("/dev/mapper"):
- log.write( "Loading support for LVM\n" )
- utils.sysexec_noerr( "modprobe dm_mod", log )
+ log.write("Loading support for LVM\n")
+ utils.sysexec_noerr("modprobe dm_mod", log)
# for anything that needs to know we are running under the boot cd and
# not the runtime os
- os.environ['PL_BOOTCD']= "1"
+ os.environ['PL_BOOTCD'] = "1"
return 1
-def __check_boot_version( vars, log ):
+def __check_boot_version(vars, log):
"""
identify which version of the boot os we are running on, and whether
or not we can run at all on the given version. later, this will be
try:
# check for a 3.x version first
- version_file= file(BOOT_VERSION_3X_FILE,'r')
- full_version= string.strip(version_file.read())
+ version_file = file(BOOT_VERSION_3X_FILE, 'r')
+ full_version = string.strip(version_file.read())
version_file.close()
- version_parts= string.split(full_version)
- version= version_parts[-1]
+ version_parts = string.split(full_version)
+ version = version_parts[-1]
- version_numbers= string.split(version,".")
+ version_numbers = string.split(version, ".")
if len(version_numbers) == 2:
- BOOT_OS_MAJOR_VERSION= int(version_numbers[0])
- BOOT_OS_MINOR_VERSION= int(version_numbers[1])
+ BOOT_OS_MAJOR_VERSION = int(version_numbers[0])
+ BOOT_OS_MINOR_VERSION = int(version_numbers[1])
else:
# for 3.x cds, if there are more than two parts
# separated by a ., its one of the beta cds.
# hardcode as a 3.0 cd
- BOOT_OS_MAJOR_VERSION= 3
- BOOT_OS_MINOR_VERSION= 0
+ BOOT_OS_MAJOR_VERSION = 3
+ BOOT_OS_MINOR_VERSION = 0
- vars['BOOT_CD_VERSION']= (BOOT_OS_MAJOR_VERSION,BOOT_OS_MINOR_VERSION)
+ vars['BOOT_CD_VERSION'] = (BOOT_OS_MAJOR_VERSION, BOOT_OS_MINOR_VERSION)
- if (BOOT_OS_MAJOR_VERSION,BOOT_OS_MINOR_VERSION) >= \
+ if (BOOT_OS_MAJOR_VERSION, BOOT_OS_MINOR_VERSION) >= \
MINIMUM_BOOT_VERSION:
return 1
- except IOError, e:
+ except IOError as e:
pass
- except IndexError, e:
+ except IndexError as e:
pass
- except TypeError, e:
+ except TypeError as e:
pass
try:
# check for a 2.x version first
- version_file= file(BOOT_VERSION_2X_FILE,'r')
- full_version= string.strip(version_file.read())
+ version_file = file(BOOT_VERSION_2X_FILE, 'r')
+ full_version = string.strip(version_file.read())
version_file.close()
- version_parts= string.split(full_version)
- version= version_parts[-1]
+ version_parts = string.split(full_version)
+ version = version_parts[-1]
if version[0] == 'v':
- version= version[1:]
+ version = version[1:]
- version_numbers= string.split(version,".")
+ version_numbers = string.split(version, ".")
if len(version_numbers) == 2:
- BOOT_OS_MAJOR_VERSION= int(version_numbers[0])
- BOOT_OS_MINOR_VERSION= int(version_numbers[1])
+ BOOT_OS_MAJOR_VERSION = int(version_numbers[0])
+ BOOT_OS_MINOR_VERSION = int(version_numbers[1])
else:
- BOOT_OS_MAJOR_VERSION= int(version_numbers[0])
- BOOT_OS_MINOR_VERSION= int(version_numbers[2])
+ BOOT_OS_MAJOR_VERSION = int(version_numbers[0])
+ BOOT_OS_MINOR_VERSION = int(version_numbers[2])
- vars['BOOT_CD_VERSION']= (BOOT_OS_MAJOR_VERSION,BOOT_OS_MINOR_VERSION)
+ vars['BOOT_CD_VERSION'] = (BOOT_OS_MAJOR_VERSION, BOOT_OS_MINOR_VERSION)
- if (BOOT_OS_MAJOR_VERSION,BOOT_OS_MINOR_VERSION) >= \
+ if (BOOT_OS_MAJOR_VERSION, BOOT_OS_MINOR_VERSION) >= \
MINIMUM_BOOT_VERSION:
return 1
- except IOError, e:
+ except IOError as e:
pass
- except IndexError, e:
+ except IndexError as e:
pass
- except TypeError, e:
+ except TypeError as e:
pass
def _create_cciss_dev_entries():
- def mkccissnod(dev,node):
- dev = dev + " b 104 %d" % (node)
- cmd = "mknod /dev/cciss/%s" %dev
+ def mkccissnod(dev, node):
+ dev = dev + " b 104 {}".format(node)
+ cmd = "mknod /dev/cciss/{}".format(dev)
utils.sysexec_noerr(cmd)
node = node + 1
return node
node = 0
- for i in range(0,16):
- dev = "c0d%d" % i
- node = mkccissnod(dev,node)
- for j in range(1,16):
- subdev = dev + "p%d" % j
- node = mkccissnod(subdev,node)
+ for i in range(0, 16):
+ dev = "c0d{}".format(i)
+ node = mkccissnod(dev, node)
+ for j in range(1, 16):
+ subdev = "{}p{}".format(dev, j)
+ node = mkccissnod(subdev, node)
val = PARTITIONS["root"]
val = PARTITIONS["swap"]
val = PARTITIONS["vservers"]
- except KeyError, part:
+ except KeyError as part:
log.write("Missing partition in PARTITIONS: {}\n".format(part))
return 0
import BootAPI
import ModelOptions
-def Run( vars, log ):
+def Run(vars, log):
"""
Setup the block devices for install, partition them w/ LVM
SWAP_SIZE the size of the swap partition
"""
- log.write( "\n\nStep: Install: partitioning disks.\n" )
+ log.write("\n\nStep: Install: partitioning disks.\n")
# make sure we have the variables we need
try:
- TEMP_PATH= vars["TEMP_PATH"]
+ TEMP_PATH = vars["TEMP_PATH"]
if TEMP_PATH == "":
- raise ValueError, "TEMP_PATH"
+ raise ValueError("TEMP_PATH")
- INSTALL_BLOCK_DEVICES= vars["INSTALL_BLOCK_DEVICES"]
- if( len(INSTALL_BLOCK_DEVICES) == 0 ):
- raise ValueError, "INSTALL_BLOCK_DEVICES is empty"
+ INSTALL_BLOCK_DEVICES = vars["INSTALL_BLOCK_DEVICES"]
+ if(len(INSTALL_BLOCK_DEVICES) == 0):
+ raise ValueError("INSTALL_BLOCK_DEVICES is empty")
# use vs_ROOT_SIZE or lxc_ROOT_SIZE as appropriate
- varname=vars['virt']+"_ROOT_SIZE"
- ROOT_SIZE= vars[varname]
+ varname = vars['virt'] + "_ROOT_SIZE"
+ ROOT_SIZE = vars[varname]
if ROOT_SIZE == "" or ROOT_SIZE == 0:
- raise ValueError, "ROOT_SIZE invalid"
+ raise ValueError("ROOT_SIZE invalid")
- SWAP_SIZE= vars["SWAP_SIZE"]
+ SWAP_SIZE = vars["SWAP_SIZE"]
if SWAP_SIZE == "" or SWAP_SIZE == 0:
- raise ValueError, "SWAP_SIZE invalid"
+ raise ValueError("SWAP_SIZE invalid")
- NODE_MODEL_OPTIONS= vars["NODE_MODEL_OPTIONS"]
+ NODE_MODEL_OPTIONS = vars["NODE_MODEL_OPTIONS"]
- PARTITIONS= vars["PARTITIONS"]
+ PARTITIONS = vars["PARTITIONS"]
if PARTITIONS == None:
- raise ValueError, "PARTITIONS"
+ raise ValueError("PARTITIONS")
if NODE_MODEL_OPTIONS & ModelOptions.RAWDISK:
- VSERVERS_SIZE= "-1"
+ VSERVERS_SIZE = "-1"
if "VSERVERS_SIZE" in vars:
- VSERVERS_SIZE= vars["VSERVERS_SIZE"]
+ VSERVERS_SIZE = vars["VSERVERS_SIZE"]
if VSERVERS_SIZE == "" or VSERVERS_SIZE == 0:
- raise ValueError, "VSERVERS_SIZE"
+ raise ValueError("VSERVERS_SIZE")
- except KeyError, var:
- raise BootManagerException, "Missing variable in vars: %s\n" % var
- except ValueError, var:
- raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
+ except KeyError as var:
+ raise BootManagerException("Missing variable in vars: {}\n".format(var))
+ except ValueError as var:
+ raise BootManagerException("Variable in vars, shouldn't be: {}\n".format(var))
- bs_request= BootServerRequest.BootServerRequest(vars)
+ bs_request = BootServerRequest.BootServerRequest(vars)
# disable swap if its on
- utils.sysexec_noerr( "swapoff %s" % PARTITIONS["swap"], log )
+ utils.sysexec_noerr("swapoff {}".format(PARTITIONS["swap"]), log)
# shutdown and remove any lvm groups/volumes
- utils.sysexec_noerr( "vgscan", log )
- utils.sysexec_noerr( "vgchange -ay", log )
- utils.sysexec_noerr( "lvremove -f %s" % PARTITIONS["root"], log )
- utils.sysexec_noerr( "lvremove -f %s" % PARTITIONS["swap"], log )
- utils.sysexec_noerr( "lvremove -f %s" % PARTITIONS["vservers"], log )
- utils.sysexec_noerr( "vgchange -an", log )
- utils.sysexec_noerr( "vgremove -f planetlab", log )
-
- log.write( "Running vgscan for devices\n" )
- utils.sysexec_noerr( "vgscan", log )
+ utils.sysexec_noerr("vgscan", log)
+ utils.sysexec_noerr("vgchange -ay", log)
+ utils.sysexec_noerr("lvremove -f {}".format(PARTITIONS["root"]), log)
+ utils.sysexec_noerr("lvremove -f {}".format(PARTITIONS["swap"]), log)
+ utils.sysexec_noerr("lvremove -f {}".format(PARTITIONS["vservers"]), log)
+ utils.sysexec_noerr("vgchange -an", log)
+ utils.sysexec_noerr("vgremove -f planetlab", log)
+
+ log.write("Running vgscan for devices\n")
+ utils.sysexec_noerr("vgscan", log)
- used_devices= []
+ used_devices = []
INSTALL_BLOCK_DEVICES.sort()
- for device in INSTALL_BLOCK_DEVICES:
- if single_partition_device( device, vars, log ):
+ for device in INSTALL_BLOCK_DEVICES:
+ if single_partition_device(device, vars, log):
if (len(used_devices) > 0 and
(vars['NODE_MODEL_OPTIONS'] & ModelOptions.RAWDISK)):
- log.write( "Running in raw disk mode, not using %s.\n" % device )
+ log.write("Running in raw disk mode, not using {}.\n".format(device))
else:
- used_devices.append( device )
- log.write( "Successfully initialized %s\n" % device )
+ used_devices.append(device)
+ log.write("Successfully initialized {}\n".format(device))
else:
- log.write( "Unable to partition %s, not using it.\n" % device )
+ log.write("Unable to partition {], not using it.\n".format(device))
continue
# list of devices to be used with vgcreate
- vg_device_list= ""
+ vg_device_list = ""
# get partitions
partitions = []
for device in used_devices:
- part_path= get_partition_path_from_device( device, vars, log )
+ part_path = get_partition_path_from_device(device, vars, log)
partitions.append(part_path)
# create raid partition
raid_partition = create_raid_partition(partitions, vars, log)
if raid_partition != None:
partitions = [raid_partition]
- log.write("PARTITIONS %s\n" % str(partitions))
+ log.write("PARTITIONS {}\n".format(str(partitions)))
# initialize the physical volumes
for part_path in partitions:
- if not create_lvm_physical_volume( part_path, vars, log ):
- raise BootManagerException, "Could not create lvm physical volume " \
- "on partition %s" % part_path
+ if not create_lvm_physical_volume(part_path, vars, log):
+ raise BootManagerException("Could not create lvm physical volume "
+ "on partition {}".format(part_path))
vg_device_list = vg_device_list + " " + part_path
# create an lvm volume group
- utils.sysexec( "vgcreate -s32M planetlab %s" % vg_device_list, log)
+ utils.sysexec("vgcreate -s32M planetlab {}".format(vg_device_list), log)
# create swap logical volume
- utils.sysexec( "lvcreate -L%s -nswap planetlab" % SWAP_SIZE, log )
+ utils.sysexec("lvcreate -L{} -nswap planetlab".format(SWAP_SIZE), log)
# check if we want a separate partition for VMs
one_partition = vars['ONE_PARTITION']=='1'
if (one_partition):
- remaining_extents= get_remaining_extents_on_vg( vars, log )
- utils.sysexec( "lvcreate -l%s -nroot planetlab" % remaining_extents, log )
+ remaining_extents = get_remaining_extents_on_vg(vars, log)
+ utils.sysexec("lvcreate -l{} -nroot planetlab".format(remaining_extents), log)
else:
- utils.sysexec( "lvcreate -L%s -nroot planetlab" % ROOT_SIZE, log )
+ utils.sysexec("lvcreate -L{} -nroot planetlab".format(ROOT_SIZE), log)
if vars['NODE_MODEL_OPTIONS'] & ModelOptions.RAWDISK and VSERVERS_SIZE != "-1":
- utils.sysexec( "lvcreate -L%s -nvservers planetlab" % VSERVERS_SIZE, log )
- remaining_extents= get_remaining_extents_on_vg( vars, log )
- utils.sysexec( "lvcreate -l%s -nrawdisk planetlab" % remaining_extents, log )
+ utils.sysexec("lvcreate -L{} -nvservers planetlab".format(VSERVERS_SIZE), log)
+ remaining_extents = get_remaining_extents_on_vg(vars, log)
+ utils.sysexec("lvcreate -l{} -nrawdisk planetlab".format(remaining_extents), log)
else:
# create vservers logical volume with all remaining space
# first, we need to get the number of remaining extents we can use
- remaining_extents= get_remaining_extents_on_vg( vars, log )
- utils.sysexec( "lvcreate -l%s -nvservers planetlab" % remaining_extents, log )
+ remaining_extents = get_remaining_extents_on_vg(vars, log)
+ utils.sysexec("lvcreate -l{} -nvservers planetlab".format(remaining_extents), log)
# activate volume group (should already be active)
- #utils.sysexec( TEMP_PATH + "vgchange -ay planetlab", log )
+ #utils.sysexec(TEMP_PATH + "vgchange -ay planetlab", log)
# make swap
- utils.sysexec( "mkswap -f %s" % PARTITIONS["swap"], log )
+ utils.sysexec("mkswap -f {}".format(PARTITIONS["swap"]), log)
# check if badhd option has been set
option = ''
fs = 'root'
rbp = filesystems[fs]
devname = PARTITIONS[fs]
- log.write("formatting %s partition (%s)%s.\n" % (fs,devname,txt))
- utils.sysexec( "mkfs.ext2 -q %s -m %d -j %s" % (option,rbp,devname), log )
+ log.write("formatting {} partition ({}){}.\n".format(fs, devname, txt))
+ utils.sysexec("mkfs.ext2 -q {} -m {} -j {}".format(option, rbp, devname), log)
# disable time/count based filesystems checks
- utils.sysexec_noerr( "tune2fs -c -1 -i 0 %s" % devname, log)
+ utils.sysexec_noerr("tune2fs -c -1 -i 0 {}".format(devname), log)
# VSERVER filesystem with btrfs to support snapshoting and stuff
fs = 'vservers'
rbp = filesystems[fs]
devname = PARTITIONS[fs]
- if vars['virt']=='vs':
- log.write("formatting %s partition (%s)%s.\n" % (fs,devname,txt))
- utils.sysexec( "mkfs.ext2 -q %s -m %d -j %s" % (option,rbp,devname), log )
+ if vars['virt'] == 'vs':
+ log.write("formatting {} partition ({}){}.\n".format(fs, devname, txt))
+ utils.sysexec("mkfs.ext2 -q {} -m {} -j {}".format(option, rbp, devname)), log)
# disable time/count based filesystems checks
- utils.sysexec_noerr( "tune2fs -c -1 -i 0 %s" % devname, log)
- elif (not one_partition):
- log.write("formatting %s btrfs partition (%s).\n" % (fs,devname))
+ utils.sysexec_noerr("tune2fs -c -1 -i 0 {}".format(devname), log)
+ elif not one_partition:
+ log.write("formatting {} btrfs partition ({}).\n".format(fs, devname))
# early BootCD's seem to come with a version of mkfs.btrfs that does not support -f
# let's check for that before invoking it
- mkfs="mkfs.btrfs"
- if os.system("mkfs.btrfs --help 2>&1 | grep force")==0:
- mkfs+=" -f"
- mkfs+=" %s"%devname
- utils.sysexec( mkfs, log )
+ mkfs = "mkfs.btrfs"
+ if os.system("mkfs.btrfs --help 2>&1 | grep force") == 0:
+ mkfs += " -f"
+ mkfs +=" {}".format(devname)
+ utils.sysexec(mkfs, log)
# as of 2013/02 it looks like there's not yet an option to set fsck frequency with btrfs
# save the list of block devices in the log
- log.write( "Block devices used (in lvm): %s\n" % repr(used_devices))
+ log.write("Block devices used (in lvm): {}\n".format(repr(used_devices)))
# list of block devices used may be updated
- vars["INSTALL_BLOCK_DEVICES"]= used_devices
+ vars["INSTALL_BLOCK_DEVICES"] = used_devices
return 1
import parted
-def single_partition_device( device, vars, log ):
+def single_partition_device(device, vars, log):
"""
initialize a disk by removing the old partition tables,
and creating a new single partition that fills the disk.
except:
raise
-def single_partition_device_1_x ( device, vars, log):
+def single_partition_device_1_x (device, vars, log):
- lvm_flag= parted.partition_flag_get_by_name('lvm')
+ lvm_flag = parted.partition_flag_get_by_name('lvm')
try:
log.write("Using pyparted 1.x\n")
# wipe the old partition table
- utils.sysexec( "dd if=/dev/zero of=%s bs=512 count=1" % device, log )
+ utils.sysexec("dd if=/dev/zero of={} bs=512 count=1".format(device), log)
# get the device
- dev= parted.PedDevice.get(device)
+ dev = parted.PedDevice.get(device)
# create a new partition table
- disk= dev.disk_new_fresh(parted.disk_type_get("msdos"))
+ disk = dev.disk_new_fresh(parted.disk_type_get("msdos"))
# create one big partition on each block device
- constraint= dev.constraint_any()
+ constraint = dev.constraint_any()
- new_part= disk.partition_new(
+ new_part = disk.partition_new(
parted.PARTITION_PRIMARY,
parted.file_system_type_get("ext2"),
- 0, 1 )
+ 0, 1)
# make it an lvm partition
new_part.set_flag(lvm_flag,1)
disk.commit()
del disk
- except BootManagerException, e:
- log.write( "BootManagerException while running: %s\n" % str(e) )
+ except BootManagerException as e:
+ log.write("BootManagerException while running: {}\n".format(str(e)))
return 0
- except parted.error, e:
- log.write( "parted exception while running: %s\n" % str(e) )
+ except parted.error as e:
+ log.write("parted exception while running: {}\n".format(str(e)))
return 0
return 1
-def single_partition_device_2_x ( device, vars, log):
+def single_partition_device_2_x (device, vars, log):
try:
log.write("Using pyparted 2.x\n")
# create a new partition table
def partition_table (device, part_type, fs_type):
# wipe the old partition table
- utils.sysexec( "dd if=/dev/zero of=%s bs=512 count=1" % device, log )
+ utils.sysexec("dd if=/dev/zero of={} bs=512 count=1".format(device), log)
# get the device
- dev= parted.Device(device)
- disk = parted.freshDisk(dev,part_type)
+ dev = parted.Device(device)
+ disk = parted.freshDisk(dev, part_type)
# create one big partition on each block device
- constraint= parted.constraint.Constraint (device=dev)
+ constraint = parted.constraint.Constraint (device=dev)
geometry = parted.geometry.Geometry (device=dev, start=0, end=1)
- fs = parted.filesystem.FileSystem (type=fs_type,geometry=geometry)
- new_part= parted.partition.Partition (disk, type=parted.PARTITION_NORMAL,
+ fs = parted.filesystem.FileSystem (type=fs_type, geometry=geometry)
+ new_part = parted.partition.Partition (disk, type=parted.PARTITION_NORMAL,
fs=fs, geometry=geometry)
# make it an lvm partition
new_part.setFlag(parted.PARTITION_LVM)
# actually add the partition to the disk
disk.addPartition(new_part, constraint)
- disk.maximizePartition(new_part,constraint)
+ disk.maximizePartition(new_part, constraint)
disk.commit()
- log.write ("Current disk for %s - partition type %s\n%s\n"%(device,part_type,disk))
- log.write ("Current dev for %s\n%s\n"%(device,dev))
+ log.write ("Current disk for {} - partition type {}\n{}\n".format(device, part_type, disk))
+ log.write ("Current dev for {}\n{}\n".format(device, dev))
del disk
try:
except:
partition_table (device, 'gpt', 'ext2')
- except Exception, e:
- log.write( "Exception inside single_partition_device_2_x : %s\n" % str(e) )
+ except Exception as e:
+ log.write("Exception inside single_partition_device_2_x : {}\n".format(str(e)))
import traceback
traceback.print_exc(file=log)
return 0
-def create_lvm_physical_volume( part_path, vars, log ):
+def create_lvm_physical_volume(part_path, vars, log):
"""
make the specificed partition a lvm physical volume.
try:
# again, wipe any old data, this time on the partition
- utils.sysexec( "dd if=/dev/zero of=%s bs=512 count=1" % part_path, log )
+ utils.sysexec("dd if=/dev/zero of={} bs=512 count=1".format(part_path), log)
### patch Thierry Parmentelat, required on some hardware
import time
time.sleep(1)
- utils.sysexec( "pvcreate -ffy %s" % part_path, log )
- except BootManagerException, e:
- log.write( "create_lvm_physical_volume failed.\n" )
+ utils.sysexec("pvcreate -ffy {}".format(part_path), log)
+ except BootManagerException as e:
+ log.write("create_lvm_physical_volume failed.\n")
return 0
return 1
"""
raid_part = None
raid_enabled = False
- node_tags = BootAPI.call_api_function( vars, "GetNodeTags",
- ({'node_id': vars['NODE_ID']},))
+ node_tags = BootAPI.call_api_function(vars, "GetNodeTags",
+ ({'node_id': vars['NODE_ID']},))
for node_tag in node_tags:
if node_tag['tagname'] == 'raid_enabled' and \
node_tag['value'] == '1':
return raid_part
try:
- log.write( "Software raid enabled.\n" )
+ log.write("Software raid enabled.\n")
# wipe everything
utils.sysexec_noerr("mdadm --stop /dev/md0", log)
time.sleep(1)
for part_path in partitions:
- utils.sysexec_noerr("mdadm --zero-superblock %s " % part_path, log)
+ utils.sysexec_noerr("mdadm --zero-superblock {} ".format(part_path), log)
# assume each partiton is on a separate disk
num_parts = len(partitions)
if num_parts < 2:
- log.write( "Not enough disks for raid. Found: %s\n" % partitions )
- raise BootManagerException("Not enough disks for raid. Found: %s\n" % partitions)
+ log.write("Not enough disks for raid. Found: {}\n".format(partitions))
+ raise BootManagerException("Not enough disks for raid. Found: {}\n".format(partitions))
if num_parts == 2:
lvl = 1
else:
- lvl = 5
+ lvl = 5
# make the array
part_list = " ".join(partitions)
raid_part = "/dev/md0"
- cmd = "mdadm --create %(raid_part)s --chunk=128 --level=raid%(lvl)s " % locals() + \
- "--raid-devices=%(num_parts)s %(part_list)s" % locals()
- utils.sysexec(cmd, log)
+ cmd = "mdadm --create {raid_part} --chunk=128 --level=raid{lvl} "\
+ "--raid-devices={num_parts} {part_list}".format(**locals())
+ utils.sysexec(cmd, log)
- except BootManagerException, e:
+ except BootManagerException as e:
log.write("create_raid_partition failed.\n")
raid_part = None
return raid_part
-def get_partition_path_from_device( device, vars, log ):
+def get_partition_path_from_device(device, vars, log):
"""
given a device, return the path of the first partition on the device
"""
# those who wrote the cciss driver just had to make it difficult
- cciss_test= "/dev/cciss"
+ cciss_test = "/dev/cciss"
if device[:len(cciss_test)] == cciss_test:
- part_path= device + "p1"
+ part_path = device + "p1"
else:
- part_path= device + "1"
+ part_path = device + "1"
return part_path
-def get_remaining_extents_on_vg( vars, log ):
+def get_remaining_extents_on_vg(vars, log):
"""
return the free amount of extents on the planetlab volume group
"""
c_stdout, c_stdin = popen2.popen2("vgdisplay -c planetlab")
- result= string.strip(c_stdout.readline())
+ result = string.strip(c_stdout.readline())
c_stdout.close()
c_stdin.close()
- remaining_extents= string.split(result,":")[15]
+ remaining_extents = string.split(result, ":")[15]
return remaining_extents
import ModelOptions
-def Run( vars, log ):
+def Run(vars, log):
"""
See if a node installation is valid. More checks should certainly be
done in the future, but for now, make sure that the sym links kernel-boot
ROOT_MOUNTED the node root file system is mounted
"""
- log.write( "\n\nStep: Validating node installation.\n" )
+ log.write("\n\nStep: Validating node installation.\n")
# make sure we have the variables we need
try:
- SYSIMG_PATH= vars["SYSIMG_PATH"]
+ SYSIMG_PATH = vars["SYSIMG_PATH"]
if SYSIMG_PATH == "":
- raise ValueError, "SYSIMG_PATH"
+ raise ValueError("SYSIMG_PATH")
- NODE_ID= vars["NODE_ID"]
+ NODE_ID = vars["NODE_ID"]
if NODE_ID == "":
- raise ValueError, "NODE_ID"
+ raise ValueError("NODE_ID")
- PLCONF_DIR= vars["PLCONF_DIR"]
+ PLCONF_DIR = vars["PLCONF_DIR"]
if PLCONF_DIR == "":
- raise ValueError, "PLCONF_DIR"
+ raise ValueError("PLCONF_DIR")
- NODE_MODEL_OPTIONS= vars["NODE_MODEL_OPTIONS"]
+ NODE_MODEL_OPTIONS = vars["NODE_MODEL_OPTIONS"]
- PARTITIONS= vars["PARTITIONS"]
+ PARTITIONS = vars["PARTITIONS"]
if PARTITIONS == None:
- raise ValueError, "PARTITIONS"
+ raise ValueError("PARTITIONS")
- except KeyError, var:
- raise BootManagerException, "Missing variable in vars: %s\n" % var
- except ValueError, var:
- raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
+ except KeyError as var:
+ raise BootManagerException("Missing variable in vars: {}\n".format(var))
+ except ValueError as var:
+ raise BootManagerException("Variable in vars, shouldn't be: {}\n".format(var))
- ROOT_MOUNTED= 0
+ ROOT_MOUNTED = 0
if vars.has_key('ROOT_MOUNTED'):
- ROOT_MOUNTED= vars['ROOT_MOUNTED']
+ ROOT_MOUNTED = vars['ROOT_MOUNTED']
# mount the root system image if we haven't already.
# capture BootManagerExceptions during the vgscan/change and mount
systeminfo.get_block_device_list(vars, log)
try:
- utils.sysexec( "vgscan", log )
- utils.sysexec( "vgchange -ay planetlab", log )
- except BootManagerException, e:
- log.write( "BootManagerException during vgscan/vgchange: %s\n" %
- str(e) )
+ utils.sysexec("vgscan", log)
+ utils.sysexec("vgchange -ay planetlab", log)
+ except BootManagerException as e:
+ log.write("BootManagerException during vgscan/vgchange: {}\n"\
+ .format(str(e)))
return 0
- utils.makedirs( SYSIMG_PATH )
+ utils.makedirs(SYSIMG_PATH)
# xxx - TODO - need to fsck the btrfs partition
if vars['virt'] == 'vs':
for filesystem in filesystems_tocheck:
try:
# first run fsck to prevent fs corruption from hanging mount...
- log.write( "fsck %s file system\n" % filesystem )
- utils.sysexec("e2fsck -v -p %s" % (PARTITIONS[filesystem]), log, fsck=True)
- except BootManagerException, e:
- log.write( "BootManagerException during fsck of %s (%s) filesystem : %s\n" %
- (filesystem, PARTITIONS[filesystem], str(e)) )
+ log.write("fsck {} file system\n".format(filesystem))
+ utils.sysexec("e2fsck -v -p {}".format(PARTITIONS[filesystem]), log, fsck=True)
+ except BootManagerException as e:
+ log.write("BootManagerException during fsck of {} ({}) filesystem : {}\n"\
+ .format(filesystem, PARTITIONS[filesystem], str(e)))
try:
- log.write( "Trying to recover filesystem errors on %s\n" % filesystem )
- utils.sysexec("e2fsck -v -y %s" % (PARTITIONS[filesystem]),log, fsck=True)
- except BootManagerException, e:
- log.write( "BootManagerException during trying to recover filesystem errors on %s (%s) filesystem : %s\n" %
- (filesystem, PARTITIONS[filesystem], str(e)) )
+ log.write("Trying to recover filesystem errors on {}\n".format(filesystem))
+ utils.sysexec("e2fsck -v -y {}".format(PARTITIONS[filesystem]), log, fsck=True)
+ except BootManagerException as e:
+ log.write("BootManagerException while trying to recover"
+ "filesystem errors on {} ({}) filesystem : {}\n"
+ .format(filesystem, PARTITIONS[filesystem], str(e)))
return -1
else:
# disable time/count based filesystems checks
- utils.sysexec_noerr( "tune2fs -c -1 -i 0 %s" % PARTITIONS[filesystem], log)
+ utils.sysexec_noerr("tune2fs -c -1 -i 0 {}".format(PARTITIONS[filesystem]), log)
try:
# then attempt to mount them
- log.write( "mounting root file system\n" )
- utils.sysexec("mount -t ext3 %s %s" % (PARTITIONS["root"],SYSIMG_PATH),log)
- except BootManagerException, e:
- log.write( "BootManagerException during mount of /root: %s\n" % str(e) )
+ log.write("mounting root file system\n")
+ utils.sysexec("mount -t ext3 {} {}".format(PARTITIONS["root"], SYSIMG_PATH),log)
+ except BootManagerException as e:
+ log.write("BootManagerException during mount of /root: {}\n".format(str(e)))
return -2
try:
- PROC_PATH = "%s/proc" % SYSIMG_PATH
+ PROC_PATH = "{}/proc".format(SYSIMG_PATH)
utils.makedirs(PROC_PATH)
- log.write( "mounting /proc\n" )
- utils.sysexec( "mount -t proc none %s" % PROC_PATH, log )
- except BootManagerException, e:
- log.write( "BootManagerException during mount of /proc: %s\n" % str(e) )
+ log.write("mounting /proc\n")
+ utils.sysexec("mount -t proc none {}".format(PROC_PATH), log)
+ except BootManagerException as e:
+ log.write("BootManagerException during mount of /proc: {}\n".format(str(e)))
return -2
if (not one_partition):
try:
- VSERVERS_PATH = "%s/vservers" % SYSIMG_PATH
+ VSERVERS_PATH = "{}/vservers".format(SYSIMG_PATH)
utils.makedirs(VSERVERS_PATH)
- log.write( "mounting vservers partition in root file system\n" )
- if vars['virt']=='vs':
- utils.sysexec("mount -t ext3 %s %s" % (PARTITIONS["vservers"], VSERVERS_PATH), log)
+ log.write("mounting vservers partition in root file system\n")
+ if vars['virt'] == 'vs':
+ utils.sysexec("mount -t ext3 {} {}".format(PARTITIONS["vservers"], VSERVERS_PATH), log)
else:
- utils.sysexec("mount -t btrfs %s %s" % (PARTITIONS["vservers"], VSERVERS_PATH), log)
- except BootManagerException, e:
- log.write( "BootManagerException during mount of /vservers: %s\n" % str(e) )
+ utils.sysexec("mount -t btrfs {} {}".format(PARTITIONS["vservers"], VSERVERS_PATH), log)
+ except BootManagerException as e:
+ log.write("BootManagerException while mounting /vservers: {}\n".format(str(e)))
return -2
- ROOT_MOUNTED= 1
- vars['ROOT_MOUNTED']= 1
+ ROOT_MOUNTED = 1
+ vars['ROOT_MOUNTED'] = 1
# check if the base kernel is installed
# these 2 links are created by our kernel's post-install scriplet
log.write("Checking for a custom kernel\n")
try:
if vars['virt'] == 'vs':
- os.stat("%s/boot/kernel-boot" % SYSIMG_PATH)
+ os.stat("{}/boot/kernel-boot".format(SYSIMG_PATH))
else:
try:
- kversion = os.popen("chroot %s rpm -qa kernel | tail -1 | cut -c 8-" % SYSIMG_PATH).read().rstrip()
- os.stat("%s/boot/vmlinuz-%s" % (SYSIMG_PATH,kversion))
+ kversion = os.popen("chroot {} rpm -qa kernel | tail -1 | cut -c 8-"\
+ .format(SYSIMG_PATH)).read().rstrip()
+ os.stat("{}/boot/vmlinuz-{}".format(SYSIMG_PATH, kversion))
major_version = int(kversion[0]) # Check if the string looks like a kernel version
except:
- kversion = os.popen("ls -lrt %s/lib/modules | tail -1 | awk '{print $9;}'"%SYSIMG_PATH).read().rstrip()
- except OSError, e:
- log.write( "Couldn't locate base kernel (you might be using the stock kernel).\n")
+ kversion = os.popen("ls -lrt {}/lib/modules | tail -1 | awk '{print $9;}'"\
+ .format(SYSIMG_PATH)).read().rstrip()
+ except OSError as e:
+ log.write("Couldn't locate base kernel (you might be using the stock kernel).\n")
return -3
# check if the model specified kernel is installed
if NODE_MODEL_OPTIONS & ModelOptions.SMP:
option = 'smp'
try:
- os.stat("%s/boot/kernel-boot%s" % (SYSIMG_PATH,option))
- except OSError, e:
+ os.stat("{}/boot/kernel-boot{}".format(SYSIMG_PATH, option))
+ except OSError as e:
# smp kernel is not there; remove option from modeloptions
# such that the rest of the code base thinks we are just
# using the base kernel.
NODE_MODEL_OPTIONS = NODE_MODEL_OPTIONS & ~ModelOptions.SMP
vars["NODE_MODEL_OPTIONS"] = NODE_MODEL_OPTIONS
- log.write( "WARNING: Couldn't locate smp kernel.\n")
+ log.write("WARNING: Couldn't locate smp kernel.\n")
# write out the node id to /etc/planetlab/node_id. if this fails, return
# 0, indicating the node isn't a valid install.
try:
- node_id_file_path= "%s/%s/node_id" % (SYSIMG_PATH,PLCONF_DIR)
- node_id_file= file( node_id_file_path, "w" )
- node_id_file.write( str(NODE_ID) )
+ node_id_file_path = "{}/{}/node_id".format(SYSIMG_PATH, PLCONF_DIR)
+ node_id_file = file(node_id_file_path, "w")
+ node_id_file.write(str(NODE_ID))
node_id_file.close()
- node_id_file= None
- log.write( "Updated /etc/planetlab/node_id\n" )
- except IOError, e:
- log.write( "Unable to write out /etc/planetlab/node_id\n" )
+ node_id_file = None
+ log.write("Updated /etc/planetlab/node_id\n")
+ except IOError as e:
+ log.write("Unable to write out /etc/planetlab/node_id\n")
return 0
- log.write( "Node installation appears to be ok\n" )
+ log.write("Node installation appears to be ok\n")
return 1