+
+# the upgrade hook
+def CleanupSysimgBeforeUpgrade(sysimg, target_nodefamily, log):
+
+ areas_to_cleanup = [
+ '/boot',
+ '/usr',
+ '/var',
+ '/etc',
+ '/run',
+ '/vsys',
+ ]
+
+ target_pldistro, target_fcdistro, target_arch = target_nodefamily.split('-')
+
+ # minimal check : not all configurations are possible...
+
+ installed_pldistro, installed_fcdistro, installed_arch = None, None, None
+ installed_virt = None
+ prefix = "Using nodefamily "
+ try:
+ with open("{}/bm-install.txt".format(sysimg)) as infile:
+ for line in infile:
+ if line.startswith(prefix):
+ installed_nodefamily = line.replace(prefix,"").strip()
+ installed_pldistro, installed_fcdistro, installed_arch = installed_nodefamily.split('-')
+ # do not break here, bm-install is additive, we want the last one..
+ with open("{}/etc/planetlab/virt".format(sysimg)) as infile:
+ installed_virt = infile.read().strip()
+ except Exception as e:
+ traceback.print_exc()
+ raise BootManagerException("Could not retrieve data about previous installation - cannot upgrade")
+
+ # moving from vservers to lxc also means another filesystem
+ # so plain reinstall is the only option
+ if installed_virt != 'lxc':
+ message = """Can only upgrade nodes already running lxc containers
+a node running vservers has its /vservers/ partition formatted as ext3
+and we need btrfs to move to containers
+your only option here is reinstall"""
+ raise BootManagerException(message)
+
+ # changing arch is not reasonable either
+ if target_arch != installed_arch:
+ raise BootManagerException("Cannot upgrade from arch={} to arch={}"
+ .format(installed_arch, target_arch))
+
+ if target_pldistro != installed_pldistro:
+ log.write("\nWARNING: upgrading across pldistros {} to {} - might not work well..\n"
+ .format(installed_pldistro, target_pldistro))
+
+ # otherwise at this point we do not do any more advanced checking
+ log.write("\n\nPseudo step CleanupSysimgBeforeUpgrade : cleaning up hard drive\n")
+
+ for area in areas_to_cleanup:
+ utils.sysexec("rm -rf {}/{}".format(sysimg, area))