From 9c29926e16153876de4f2c6beca67c376e74955f Mon Sep 17 00:00:00 2001 From: Guillaume Date: Mon, 23 Sep 2024 18:51:19 +0200 Subject: [PATCH] Use the management address type from old install During an upgrade if no modes are selected we need to use the management address from the previous installation read from /etc/xensource-inventory. By default it is set to IPv4. If a mode is selected then we are using it. It both modes are selected (IPv4 abd IPv6) then we are using IPv4. Signed-off-by: Guillaume --- backend.py | 10 +++++++--- upgrade.py | 11 ++++++----- util.py | 3 +++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/backend.py b/backend.py index cee2dff4..27bafdde 100644 --- a/backend.py +++ b/backend.py @@ -104,6 +104,7 @@ def getPrepSequence(ans, interactive): seq = [ Task(util.getUUID, As(ans), ['installation-uuid']), Task(util.getUUID, As(ans), ['control-domain-uuid']), + Task(util.mgmtAddrType, As(ans), ['management-address-type']), Task(util.randomLabelStr, As(ans), ['disk-label-suffix']), Task(diskutil.create_raid, A(ans, 'raid'), []), Task(partitionTargetDisk, A(ans, 'primary-disk', 'installation-to-overwrite', 'preserve-first-partition','sr-on-primary'), ['target-boot-mode', 'boot-partnum', 'primary-partnum', 'backup-partnum', 'logs-partnum', 'swap-partnum', 'storage-partnum']), @@ -188,7 +189,7 @@ def getFinalisationSequence(ans): Task(writeFstab, A(ans, 'mounts', 'target-boot-mode', 'primary-disk', 'logs-partnum', 'swap-partnum', 'disk-label-suffix'), []), Task(enableAgent, A(ans, 'mounts', 'network-backend', 'services'), []), Task(configureCC, A(ans, 'mounts'), []), - Task(writeInventory, A(ans, 'installation-uuid', 'control-domain-uuid', 'mounts', 'primary-disk', + Task(writeInventory, A(ans, 'installation-uuid', 'control-domain-uuid', 'management-address-type', 'mounts', 'primary-disk', 'backup-partnum', 'storage-partnum', 'guest-disks', 'net-admin-bridge', 'branding', 'net-admin-configuration', 'host-config', 'install-type'), []), Task(writeXencommons, A(ans, 'control-domain-uuid', 'mounts'), []), @@ -1617,7 +1618,7 @@ def writeXencommons(controlID, mounts): with open(os.path.join(mounts['root'], constants.XENCOMMONS_FILE), "w") as f: f.write(contents) -def writeInventory(installID, controlID, mounts, primary_disk, backup_partnum, storage_partnum, guest_disks, admin_bridge, branding, admin_config, host_config, install_type): +def writeInventory(installID, controlID, mgmtAddrType, mounts, primary_disk, backup_partnum, storage_partnum, guest_disks, admin_bridge, branding, admin_config, host_config, install_type): inv = open(os.path.join(mounts['root'], constants.INVENTORY_FILE), "w") if 'product-brand' in branding: inv.write("PRODUCT_BRAND='%s'\n" % branding['product-brand']) @@ -1658,8 +1659,11 @@ def writeInventory(installID, controlID, mounts, primary_disk, backup_partnum, s inv.write("DOM0_MEM='%d'\n" % host_config['dom0-mem']) inv.write("DOM0_VCPUS='%d'\n" % host_config['dom0-vcpus']) inv.write("MANAGEMENT_INTERFACE='%s'\n" % admin_bridge) + # if no modes are configured then use mgmtAddrType + if not (admin_config.mode or admin_config.modev6): + inv.write("MANAGEMENT_ADDRESS_TYPE='%s'\n" % mgmtAddrType) # Default to IPv4 unless we have only got an IPv6 admin interface - if ((not admin_config.mode) and admin_config.modev6): + elif (not admin_config.mode) and admin_config.modev6: inv.write("MANAGEMENT_ADDRESS_TYPE='IPv6'\n") else: inv.write("MANAGEMENT_ADDRESS_TYPE='IPv4'\n") diff --git a/upgrade.py b/upgrade.py index 4a17a026..a5410b0b 100644 --- a/upgrade.py +++ b/upgrade.py @@ -503,18 +503,19 @@ def replace_config(config_file, destination): finally: primary_fs.unmount() - prepUpgradeArgs = ['installation-uuid', 'control-domain-uuid'] - prepStateChanges = ['installation-uuid', 'control-domain-uuid'] - def prepareUpgrade(self, progress_callback, installID, controlID): + prepUpgradeArgs = ['installation-uuid', 'control-domain-uuid', 'management-address-type'] + prepStateChanges = ['installation-uuid', 'control-domain-uuid', 'management-address-type'] + def prepareUpgrade(self, progress_callback, installID, controlID, mgmtAddrType): """ Try to preserve the installation and control-domain UUIDs from xensource-inventory.""" try: installID = self.source.getInventoryValue("INSTALLATION_UUID") controlID = self.source.getInventoryValue("CONTROL_DOMAIN_UUID") + mgmtAddrType = self.source.getInventoryValue("MANAGEMENT_ADDRESS_TYPE") except KeyError: - raise RuntimeError("Required information (INSTALLATION_UUID, CONTROL_DOMAIN_UUID) was missing from your xensource-inventory file. Aborting installation; please replace these keys and try again.") + raise RuntimeError("Required information (INSTALLATION_UUID, CONTROL_DOMAIN_UUID, MANAGEMENT_ADDRESS_TYPE) was missing from your xensource-inventory file. Aborting installation; please replace these keys and try again.") - return installID, controlID + return installID, controlID, mgmtAddrType def buildRestoreList(self, src_base): self.restore_list += ['etc/xensource/ptoken', 'etc/xensource/pool.conf', diff --git a/util.py b/util.py index c407d20f..5cc0562c 100644 --- a/util.py +++ b/util.py @@ -357,6 +357,9 @@ def udevinfoCmd(): def randomLabelStr(): return "".join([random.choice(string.ascii_lowercase) for x in range(6)]) +def mgmtAddrType(): + return "IPv4" + def getLocalTime(timezone=None): if timezone: os.environ['TZ'] = timezone