+ update_vals = {}
+ update_vals['ssh_rsa_key'] = ssh_host_key
+ BootAPI.call_api_function(vars, "BootUpdateNode", (update_vals,))
+
+
+ # get the kernel version
+ option = ''
+ if NODE_MODEL_OPTIONS & ModelOptions.SMP:
+ option = 'smp'
+
+ log.write("Copying kernel and initrd for booting.\n")
+ if vars['virt'] == 'vs':
+ 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 {} 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 {}/lib/modules | tail -1 | awk '{print $9;}'"\
+ .format(SYSIMG_PATH)).read().rstrip()
+
+ utils.sysexec("cp {}/boot/vmlinuz-{} /tmp/kernel".format(SYSIMG_PATH, kversion), log)
+ candidates = []
+ # f16/18: expect initramfs image here
+ candidates.append ("/boot/initramfs-{}.img".format(kversion))
+ # f20: uses a uid of some kind, e.g. /boot/543f88c129de443baaa65800cf3927ce/<kversion>/initrd
+ candidates.append ("/boot/*/{}/initrd".format(kversion))
+ # Ubuntu:
+ 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 {} matches in {}\n".format(len(matches), pattern))
+ if matches:
+ return matches[0]
+ initrd = find_file_in_sysimg(candidates)
+ if initrd:
+ utils.sysexec("cp {} /tmp/initrd".format(initrd), log)
+ else:
+ raise Exception("Unable to locate initrd - bailing out")
+
+ BootAPI.save(vars)
+
+ log.write("Unmounting disks.\n")
+
+ 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
+
+ # Change runlevel to 'boot' prior to kexec.
+ StopRunlevelAgent.Run(vars, log)
+
+ log.write("Unloading modules and chain booting to new kernel.\n")