+
+# the upgrade hook
+def CleanupSysimgBeforeUpgrade(sysimg, target_nodefamily, log):
+
+ areas_to_cleanup = [
+ '/usr/lib',
+ '/var',
+ '/etc',
+ '/boot',
+ ]
+
+ 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('-')
+ with open("{}/etc/planetlab/virt".format(sysimg)) as infile:
+ installed_virt = infile.read().strip()
+ except Exception as e:
+ 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':
+ raise BootManagerException("Can only upgrade nodes running lxc containers (vservers not supported)")
+
+ # 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))