3 from Exceptions import *
6 from systeminfo import systeminfo
12 Load the kernel off of a node and boot to it.
13 This step assumes the disks are mounted on SYSIMG_PATH.
15 Expect the following variables:
16 BOOT_CD_VERSION A tuple of the current bootcd version
17 SYSIMG_PATH the path where the system image will be mounted
18 (always starts with TEMP_PATH)
19 ROOT_MOUNTED the node root file system is mounted
21 Sets the following variables:
22 ROOT_MOUNTED the node root file system is mounted
25 log.write( "\n\nStep: Chain booting node.\n" )
27 # make sure we have the variables we need
29 BOOT_CD_VERSION= vars["BOOT_CD_VERSION"]
30 if BOOT_CD_VERSION == "":
31 raise ValueError, "BOOT_CD_VERSION"
33 SYSIMG_PATH= vars["SYSIMG_PATH"]
35 raise ValueError, "SYSIMG_PATH"
38 raise BootManagerException, "Missing variable in vars: %s\n" % var
39 except ValueError, var:
40 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
43 if 'ROOT_MOUNTED' in vars.keys():
44 ROOT_MOUNTED= vars['ROOT_MOUNTED']
47 log.write( "Mounting node partitions\n" )
49 # old cds need extra utilities to run lvm
50 if BOOT_CD_VERSION[0] == 2:
51 compatibility.setup_lvm_2x_cd( vars, log )
53 # simply creating an instance of this class and listing the system
54 # block devices will make them show up so vgscan can find the planetlab
56 systeminfo().get_block_device_list()
58 utils.sysexec( "vgscan", log )
59 utils.sysexec( "vgchange -ay planetlab", log )
61 utils.makedirs( SYSIMG_PATH )
63 utils.sysexec( "mount /dev/planetlab/root %s" % SYSIMG_PATH, log )
64 utils.sysexec( "mount /dev/planetlab/vservers %s/vservers" %
68 vars['ROOT_MOUNTED']= 1
71 node_update_cmd= "/usr/local/planetlab/bin/NodeUpdate.py start noreboot"
73 log.write( "Running node update.\n" )
74 utils.sysexec( "chroot %s %s" % (SYSIMG_PATH,node_update_cmd), log )
76 log.write( "Updating ssh public host key with PLC.\n" )
79 ssh_host_key_file= file("%s/etc/ssh/ssh_host_rsa_key.pub"%SYSIMG_PATH,"r")
80 ssh_host_key= ssh_host_key_file.read().strip()
81 ssh_host_key_file.close()
82 ssh_host_key_file= None
87 update_vals['ssh_host_key']= ssh_host_key
88 BootAPI.call_api_function( vars, "BootUpdateNode", (update_vals,) )
91 log.write( "Copying kernel and initrd for booting.\n" )
92 utils.sysexec( "cp %s/boot/kernel-boot /tmp/kernel" % SYSIMG_PATH, log )
93 utils.sysexec( "cp %s/boot/initrd-boot /tmp/initrd" % SYSIMG_PATH, log )
95 log.write( "Unmounting disks.\n" )
96 utils.sysexec_noerr( "chroot %s umount /rcfs" % SYSIMG_PATH, log )
97 utils.sysexec_noerr( "umount -r /dev/planetlab/vservers", log )
98 utils.sysexec_noerr( "umount -r /dev/planetlab/root", log )
99 utils.sysexec_noerr( "vgchange -an", log )
102 vars['ROOT_MOUNTED']= 0
104 if BOOT_CD_VERSION[0] == 2:
105 log.write( "Unloading modules and chaining booting to new kernel.\n" )
107 log.write( "Chaining booting to new kernel.\n" )
109 # further use of log after Upload will only output to screen
112 # on 2.x cds (2.4 kernel) for sure, we need to shutdown everything to
113 # get kexec to work correctly
115 utils.sysexec_noerr( "ifconfig eth0 down", log )
117 if BOOT_CD_VERSION[0] == 2:
118 utils.sysexec_noerr( "killall dhcpcd", log )
119 elif BOOT_CD_VERSION[0] == 3:
120 utils.sysexec_noerr( "killall dhclient", log )
122 utils.sysexec_noerr( "umount -a -r -t ext2,ext3", log )
123 utils.sysexec_noerr( "modprobe -r lvm-mod", log )
126 modules= file("/tmp/loadedmodules","r")
129 module= string.strip(line)
131 utils.sysexec_noerr( "modprobe -r %s" % module, log )
133 log.write( "Couldn't load /tmp/loadedmodules to unload, continuing.\n" )
135 utils.sysexec( "kexec --force --initrd=/tmp/initrd " \
136 "--append=ramdisk_size=8192 /tmp/kernel" )