From b24525a98c04cfa960cbce647e3ae8abb312ffee Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Fri, 4 Feb 2022 19:52:55 +0100 Subject: [PATCH 01/11] VR: remove old json config when start vmware/xenserver VRs --- systemvm/debian/opt/cloud/bin/setup/bootstrap.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh b/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh index 2335d649a950..ccb2f3a4a036 100755 --- a/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh +++ b/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh @@ -80,6 +80,9 @@ config_guest() { systemctl enable xe-daemon systemctl start xe-daemon + log_it "Removing old configuration files in /etc/cloudstack/" + rm -rf /etc/cloudstack/*.json + if [ ! -f /usr/bin/xenstore-read ]; then log_it "ERROR: xentools not installed, cannot found xenstore-read" && exit 5 fi @@ -122,6 +125,9 @@ config_guest() { systemctl enable open-vm-tools systemctl start open-vm-tools + log_it "Removing old configuration files in /etc/cloudstack/" + rm -rf /etc/cloudstack/*.json + vmtoolsd --cmd 'machine.id.get' > $CMDLINE ;; virtualpc|hyperv) From 09f8afec44887a13cb0c2da25d3597b2a72c2150 Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Thu, 10 Mar 2022 14:38:05 +0100 Subject: [PATCH 02/11] marvin: get free vlan from physical network with Guest traffictype --- tools/marvin/marvin/lib/common.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/marvin/marvin/lib/common.py b/tools/marvin/marvin/lib/common.py index 07fbbca402fd..b133af93eb95 100644 --- a/tools/marvin/marvin/lib/common.py +++ b/tools/marvin/marvin/lib/common.py @@ -1139,6 +1139,14 @@ def get_free_vlan(apiclient, zoneid): list_physical_networks_response) > 0, "No physical networks found in zone %s" % zoneid physical_network = list_physical_networks_response[0] + for physicalNetwork in list_physical_networks_response: + trafficTypes = TrafficType.list( + apiclient, + physicalnetworkid=physicalNetwork.id) + for trafficType in trafficTypes: + if trafficType.traffictype == "Guest": + physical_network = physicalNetwork + break networks = list_networks(apiclient, zoneid=zoneid) usedVlanIds = [] @@ -1161,6 +1169,7 @@ def get_free_vlan(apiclient, zoneid): break else: vlans = xsplit(physical_network.vlan, ['-', ',']) + list.sort(vlans) assert len(vlans) > 0 assert int(vlans[0]) < int( From 0ef9cd76ad8247aa58372fb305961e5628ef2ecf Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Thu, 10 Mar 2022 14:39:06 +0100 Subject: [PATCH 03/11] Revert "VR: remove old json config when start vmware/xenserver VRs" This reverts commit b24525a98c04cfa960cbce647e3ae8abb312ffee. --- systemvm/debian/opt/cloud/bin/setup/bootstrap.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh b/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh index ccb2f3a4a036..2335d649a950 100755 --- a/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh +++ b/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh @@ -80,9 +80,6 @@ config_guest() { systemctl enable xe-daemon systemctl start xe-daemon - log_it "Removing old configuration files in /etc/cloudstack/" - rm -rf /etc/cloudstack/*.json - if [ ! -f /usr/bin/xenstore-read ]; then log_it "ERROR: xentools not installed, cannot found xenstore-read" && exit 5 fi @@ -125,9 +122,6 @@ config_guest() { systemctl enable open-vm-tools systemctl start open-vm-tools - log_it "Removing old configuration files in /etc/cloudstack/" - rm -rf /etc/cloudstack/*.json - vmtoolsd --cmd 'machine.id.get' > $CMDLINE ;; virtualpc|hyperv) From 7340cda499ce859dbc9d0453d93d3a69e0a5af1f Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Thu, 10 Mar 2022 14:40:06 +0100 Subject: [PATCH 04/11] kvm/vmware/xenserver: fix VR reboot from out-of-band --- .../vmware/resource/VmwareResource.java | 34 +++++++++++++++++ .../resource/CitrixResourceBase.java | 2 +- .../xenbase/CitrixCheckSshCommandWrapper.java | 21 ++++++++++ scripts/vm/hypervisor/kvm/patch.sh | 2 +- .../debian/opt/cloud/bin/setup/bootstrap.sh | 38 ++++++++++++++++--- 5 files changed, 90 insertions(+), 7 deletions(-) diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java index 3732804f9a8f..0478656b58d5 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -1702,9 +1702,43 @@ protected CheckSshAnswer execute(CheckSshCommand cmd) { networkUsage(privateIp, "create", null); } + if (VirtualMachineName.isValidRouterName(vmName)) { + reconfigureDomainRouterAfterStart(vmName); + } + return new CheckSshAnswer(cmd); } + private void reconfigureDomainRouterAfterStart(String vmName) { + s_logger.debug("Reconfigure to remove machine.id from domain router after start. vmName: " + vmName); + VmwareContext context = getServiceContext(); + try { + VmwareHypervisorHost hyperHost = getHyperHost(context); + VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName); + if (vmMo == null) { + if (hyperHost instanceof HostMO) { + ClusterMO clusterMo = new ClusterMO(hyperHost.getContext(), ((HostMO) hyperHost).getParentMor()); + vmMo = clusterMo.findVmOnHyperHost(vmName); + } + } + if (vmMo == null) { + String msg = "VM " + vmName + " no longer exists to execute UnPlugNic command"; + s_logger.error(msg); + throw new Exception(msg); + } + VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec(); + OptionValue option = new OptionValue(); + option.setKey("machine.id"); + option.setValue(""); + vmConfigSpec.getExtraConfig().add(option); + if (!vmMo.configureVm(vmConfigSpec)) { + throw new Exception("Failed to reconfigure domain router after start. vmName: " + vmName); + } + } catch (Exception e) { + s_logger.error("Unexpected exception when reconfigure domain router after start: ", e); + } + } + private DiskTO[] validateDisks(DiskTO[] disks) { List validatedDisks = new ArrayList(); diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java index 19625a2f09a1..d321e88a6a21 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java @@ -309,7 +309,7 @@ private static boolean isAlienVm(final VM vm, final Connection conn) throws XenA private static final String XENSTORE_DATA_IP = "vm-data/ip"; private static final String XENSTORE_DATA_GATEWAY = "vm-data/gateway"; private static final String XENSTORE_DATA_NETMASK = "vm-data/netmask"; - private static final String XENSTORE_DATA_CS_INIT = "vm-data/cloudstack/init"; + public static final String XENSTORE_DATA_CS_INIT = "vm-data/cloudstack/init"; public CitrixResourceBase() { } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckSshCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckSshCommandWrapper.java index cf34a8fb30cd..fc0a96571bfc 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckSshCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckSshCommandWrapper.java @@ -19,6 +19,10 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; @@ -28,6 +32,8 @@ import com.cloud.resource.CommandWrapper; import com.cloud.resource.ResourceWrapper; import com.xensource.xenapi.Connection; +import com.xensource.xenapi.VM; + @ResourceWrapper(handles = CheckSshCommand.class) public final class CitrixCheckSshCommandWrapper extends CommandWrapper { @@ -60,6 +66,21 @@ public Answer execute(final CheckSshCommand command, final CitrixResourceBase ci s_logger.debug("Ping command port succeeded for vm " + vmName); } + try { + final Set vms = VM.getByNameLabel(conn, vmName); + if (vms != null) { + for (final VM vm : vms) { + s_logger.debug("Update boot args in xenstore-data for domain router after start. vmName: " + vmName); + Map xenstoreData = new HashMap<>(); + xenstoreData.put(citrixResourceBase.XENSTORE_DATA_CS_INIT, ""); + vm.setXenstoreData(conn, xenstoreData); + break; + } + } + } catch (final Exception e) { + s_logger.warn("Catch Exception: " + e.getClass().toString() + " due to " + e.toString(), e); + } + return new CheckSshAnswer(command); } } \ No newline at end of file diff --git a/scripts/vm/hypervisor/kvm/patch.sh b/scripts/vm/hypervisor/kvm/patch.sh index 84c6b5b14509..246788e868fe 100755 --- a/scripts/vm/hypervisor/kvm/patch.sh +++ b/scripts/vm/hypervisor/kvm/patch.sh @@ -72,4 +72,4 @@ do done # Write cmdline payload -send_file $name "/var/cache/cloud/cmdline" $cmdline +send_file $name "/var/cache/cloud/cmdline_passed" $cmdline diff --git a/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh b/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh index 2335d649a950..f85da13993c6 100755 --- a/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh +++ b/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh @@ -18,6 +18,7 @@ PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" CMDLINE=/var/cache/cloud/cmdline +CMDLINE_PASSED=/var/cache/cloud/cmdline_passed rm -f /var/cache/cloud/enabled_svcs rm -f /var/cache/cloud/disabled_svcs @@ -83,8 +84,17 @@ config_guest() { if [ ! -f /usr/bin/xenstore-read ]; then log_it "ERROR: xentools not installed, cannot found xenstore-read" && exit 5 fi - /usr/bin/xenstore-read vm-data/cloudstack/init > $CMDLINE - sed -i "s/%/ /g" $CMDLINE + /usr/bin/xenstore-read vm-data/cloudstack/init |tr -d "\n$" > $CMDLINE_PASSED + if [ -s $CMDLINE_PASSED ]; then + log_it "Received a new non-empty cmdline file from qemu-guest-agent" + rm -rf $CMDLINE && mv $CMDLINE_PASSED $CMDLINE + # Remove old configuration files in /etc/cloudstack if VR is booted from cloudstack + rm -rf /etc/cloudstack/*.json + log_it "Booting from cloudstack, remove old configuration files in /etc/cloudstack/" + break + else + sed -i "s/%/ /g" $CMDLINE + fi ;; kvm) # Configure kvm hotplug support @@ -102,8 +112,9 @@ config_guest() { # Wait for $CMDLINE file to be written by the qemu-guest-agent for i in {1..60}; do - if [ -s $CMDLINE ]; then + if [ -s $CMDLINE_PASSED ]; then log_it "Received a new non-empty cmdline file from qemu-guest-agent" + rm -rf $CMDLINE && mv $CMDLINE_PASSED $CMDLINE # Remove old configuration files in /etc/cloudstack if VR is booted from cloudstack rm -rf /etc/cloudstack/*.json log_it "Booting from cloudstack, remove old configuration files in /etc/cloudstack/" @@ -122,14 +133,31 @@ config_guest() { systemctl enable open-vm-tools systemctl start open-vm-tools - vmtoolsd --cmd 'machine.id.get' > $CMDLINE + vmtoolsd --cmd 'machine.id.get' > $CMDLINE_PASSED + if [ -s $CMDLINE_PASSED ]; then + log_it "Received a new non-empty cmdline file from vm-tools" + rm -rf $CMDLINE && mv $CMDLINE_PASSED $CMDLINE + # Remove old configuration files in /etc/cloudstack if VR is booted from cloudstack + rm -rf /etc/cloudstack/*.json + log_it "Booting from cloudstack, remove old configuration files in /etc/cloudstack/" + break + fi + ;; virtualpc|hyperv) # Hyper-V is recognized as virtualpc hypervisor type. Boot args are passed using KVP Daemon systemctl enable hyperv-daemons.hv-fcopy-daemon.service hyperv-daemons.hv-kvp-daemon.service hyperv-daemons.hv-vss-daemon.service systemctl start hyperv-daemons.hv-fcopy-daemon.service hyperv-daemons.hv-kvp-daemon.service hyperv-daemons.hv-vss-daemon.service sleep 5 - cp -f /var/opt/hyperv/.kvp_pool_0 $CMDLINE + cp -f /var/opt/hyperv/.kvp_pool_0 $CMDLINE_PASSED + if [ -s $CMDLINE_PASSED ]; then + log_it "Received a new non-empty cmdline file from vm-tools" + rm -rf $CMDLINE && mv $CMDLINE_PASSED $CMDLINE + # Remove old configuration files in /etc/cloudstack if VR is booted from cloudstack + rm -rf /etc/cloudstack/*.json + log_it "Booting from cloudstack, remove old configuration files in /etc/cloudstack/" + break + fi cat /dev/null > /var/opt/hyperv/.kvp_pool_0 ;; virtualbox) From 6345a838a4a0d2aa31fa1c3ed1a1d553a65aeaeb Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Mon, 14 Mar 2022 10:45:25 +0100 Subject: [PATCH 05/11] VR: create method to perform actions when boot from cloudstack --- .../debian/opt/cloud/bin/setup/bootstrap.sh | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh b/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh index f85da13993c6..ffd8fcaf1ef9 100755 --- a/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh +++ b/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh @@ -87,10 +87,7 @@ config_guest() { /usr/bin/xenstore-read vm-data/cloudstack/init |tr -d "\n$" > $CMDLINE_PASSED if [ -s $CMDLINE_PASSED ]; then log_it "Received a new non-empty cmdline file from qemu-guest-agent" - rm -rf $CMDLINE && mv $CMDLINE_PASSED $CMDLINE - # Remove old configuration files in /etc/cloudstack if VR is booted from cloudstack - rm -rf /etc/cloudstack/*.json - log_it "Booting from cloudstack, remove old configuration files in /etc/cloudstack/" + perform_actions_when_boot_from_cloudstack break else sed -i "s/%/ /g" $CMDLINE @@ -114,10 +111,7 @@ config_guest() { for i in {1..60}; do if [ -s $CMDLINE_PASSED ]; then log_it "Received a new non-empty cmdline file from qemu-guest-agent" - rm -rf $CMDLINE && mv $CMDLINE_PASSED $CMDLINE - # Remove old configuration files in /etc/cloudstack if VR is booted from cloudstack - rm -rf /etc/cloudstack/*.json - log_it "Booting from cloudstack, remove old configuration files in /etc/cloudstack/" + perform_actions_when_boot_from_cloudstack break fi sleep 1 @@ -136,10 +130,7 @@ config_guest() { vmtoolsd --cmd 'machine.id.get' > $CMDLINE_PASSED if [ -s $CMDLINE_PASSED ]; then log_it "Received a new non-empty cmdline file from vm-tools" - rm -rf $CMDLINE && mv $CMDLINE_PASSED $CMDLINE - # Remove old configuration files in /etc/cloudstack if VR is booted from cloudstack - rm -rf /etc/cloudstack/*.json - log_it "Booting from cloudstack, remove old configuration files in /etc/cloudstack/" + perform_actions_when_boot_from_cloudstack break fi @@ -152,10 +143,7 @@ config_guest() { cp -f /var/opt/hyperv/.kvp_pool_0 $CMDLINE_PASSED if [ -s $CMDLINE_PASSED ]; then log_it "Received a new non-empty cmdline file from vm-tools" - rm -rf $CMDLINE && mv $CMDLINE_PASSED $CMDLINE - # Remove old configuration files in /etc/cloudstack if VR is booted from cloudstack - rm -rf /etc/cloudstack/*.json - log_it "Booting from cloudstack, remove old configuration files in /etc/cloudstack/" + perform_actions_when_boot_from_cloudstack break fi cat /dev/null > /var/opt/hyperv/.kvp_pool_0 @@ -175,6 +163,13 @@ config_guest() { export TYPE=$(grep -Po 'type=\K[a-zA-Z]*' $CMDLINE) } +perform_actions_when_boot_from_cloudstack() { + rm -rf $CMDLINE && mv $CMDLINE_PASSED $CMDLINE + # Remove old configuration files in /etc/cloudstack if VR is booted from cloudstack + rm -rf /etc/cloudstack/*.json + log_it "Booting from cloudstack, removed old configuration files in /etc/cloudstack/" +} + patch_systemvm() { local patchfile=$1 local backupfolder="/tmp/.conf.backup" From 811d73d51ca18471b1922832e87fbcb539a89e58 Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Thu, 24 Mar 2022 15:06:59 +0100 Subject: [PATCH 06/11] Update #5938: write to /var/cache/cloud/cmdline for cks nodes --- scripts/vm/hypervisor/kvm/patch.sh | 6 +++++- systemvm/debian/opt/cloud/bin/setup/bootstrap.sh | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/vm/hypervisor/kvm/patch.sh b/scripts/vm/hypervisor/kvm/patch.sh index 246788e868fe..895dbf1fbe24 100755 --- a/scripts/vm/hypervisor/kvm/patch.sh +++ b/scripts/vm/hypervisor/kvm/patch.sh @@ -72,4 +72,8 @@ do done # Write cmdline payload -send_file $name "/var/cache/cloud/cmdline_passed" $cmdline +if [[ $bootargs =~ .*type=cksnode.* ]];then + send_file $name "/var/cache/cloud/cmdline" $cmdline +else + send_file $name "/var/cache/cloud/cmdline_passed" $cmdline +fi \ No newline at end of file diff --git a/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh b/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh index ffd8fcaf1ef9..2d3416059d72 100755 --- a/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh +++ b/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh @@ -108,7 +108,7 @@ config_guest() { systemctl start qemu-guest-agent # Wait for $CMDLINE file to be written by the qemu-guest-agent - for i in {1..60}; do + for i in {1..10}; do if [ -s $CMDLINE_PASSED ]; then log_it "Received a new non-empty cmdline file from qemu-guest-agent" perform_actions_when_boot_from_cloudstack From 9835bf349643054982107ecfec16af1605b042aa Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Fri, 22 Apr 2022 09:55:55 +0200 Subject: [PATCH 07/11] Revert "VR: create method to perform actions when boot from cloudstack" This reverts commit 6345a838a4a0d2aa31fa1c3ed1a1d553a65aeaeb. --- .../debian/opt/cloud/bin/setup/bootstrap.sh | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh b/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh index 2d3416059d72..2643ce12c265 100755 --- a/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh +++ b/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh @@ -87,7 +87,10 @@ config_guest() { /usr/bin/xenstore-read vm-data/cloudstack/init |tr -d "\n$" > $CMDLINE_PASSED if [ -s $CMDLINE_PASSED ]; then log_it "Received a new non-empty cmdline file from qemu-guest-agent" - perform_actions_when_boot_from_cloudstack + rm -rf $CMDLINE && mv $CMDLINE_PASSED $CMDLINE + # Remove old configuration files in /etc/cloudstack if VR is booted from cloudstack + rm -rf /etc/cloudstack/*.json + log_it "Booting from cloudstack, remove old configuration files in /etc/cloudstack/" break else sed -i "s/%/ /g" $CMDLINE @@ -111,7 +114,10 @@ config_guest() { for i in {1..10}; do if [ -s $CMDLINE_PASSED ]; then log_it "Received a new non-empty cmdline file from qemu-guest-agent" - perform_actions_when_boot_from_cloudstack + rm -rf $CMDLINE && mv $CMDLINE_PASSED $CMDLINE + # Remove old configuration files in /etc/cloudstack if VR is booted from cloudstack + rm -rf /etc/cloudstack/*.json + log_it "Booting from cloudstack, remove old configuration files in /etc/cloudstack/" break fi sleep 1 @@ -130,7 +136,10 @@ config_guest() { vmtoolsd --cmd 'machine.id.get' > $CMDLINE_PASSED if [ -s $CMDLINE_PASSED ]; then log_it "Received a new non-empty cmdline file from vm-tools" - perform_actions_when_boot_from_cloudstack + rm -rf $CMDLINE && mv $CMDLINE_PASSED $CMDLINE + # Remove old configuration files in /etc/cloudstack if VR is booted from cloudstack + rm -rf /etc/cloudstack/*.json + log_it "Booting from cloudstack, remove old configuration files in /etc/cloudstack/" break fi @@ -143,7 +152,10 @@ config_guest() { cp -f /var/opt/hyperv/.kvp_pool_0 $CMDLINE_PASSED if [ -s $CMDLINE_PASSED ]; then log_it "Received a new non-empty cmdline file from vm-tools" - perform_actions_when_boot_from_cloudstack + rm -rf $CMDLINE && mv $CMDLINE_PASSED $CMDLINE + # Remove old configuration files in /etc/cloudstack if VR is booted from cloudstack + rm -rf /etc/cloudstack/*.json + log_it "Booting from cloudstack, remove old configuration files in /etc/cloudstack/" break fi cat /dev/null > /var/opt/hyperv/.kvp_pool_0 @@ -163,13 +175,6 @@ config_guest() { export TYPE=$(grep -Po 'type=\K[a-zA-Z]*' $CMDLINE) } -perform_actions_when_boot_from_cloudstack() { - rm -rf $CMDLINE && mv $CMDLINE_PASSED $CMDLINE - # Remove old configuration files in /etc/cloudstack if VR is booted from cloudstack - rm -rf /etc/cloudstack/*.json - log_it "Booting from cloudstack, removed old configuration files in /etc/cloudstack/" -} - patch_systemvm() { local patchfile=$1 local backupfolder="/tmp/.conf.backup" From 4b778906d04d3f65ea3207790d45afcf771628a5 Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Fri, 22 Apr 2022 09:56:05 +0200 Subject: [PATCH 08/11] Revert "Update #5938: write to /var/cache/cloud/cmdline for cks nodes" This reverts commit 811d73d51ca18471b1922832e87fbcb539a89e58. --- scripts/vm/hypervisor/kvm/patch.sh | 6 +----- systemvm/debian/opt/cloud/bin/setup/bootstrap.sh | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/scripts/vm/hypervisor/kvm/patch.sh b/scripts/vm/hypervisor/kvm/patch.sh index 895dbf1fbe24..246788e868fe 100755 --- a/scripts/vm/hypervisor/kvm/patch.sh +++ b/scripts/vm/hypervisor/kvm/patch.sh @@ -72,8 +72,4 @@ do done # Write cmdline payload -if [[ $bootargs =~ .*type=cksnode.* ]];then - send_file $name "/var/cache/cloud/cmdline" $cmdline -else - send_file $name "/var/cache/cloud/cmdline_passed" $cmdline -fi \ No newline at end of file +send_file $name "/var/cache/cloud/cmdline_passed" $cmdline diff --git a/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh b/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh index 2643ce12c265..f85da13993c6 100755 --- a/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh +++ b/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh @@ -111,7 +111,7 @@ config_guest() { systemctl start qemu-guest-agent # Wait for $CMDLINE file to be written by the qemu-guest-agent - for i in {1..10}; do + for i in {1..60}; do if [ -s $CMDLINE_PASSED ]; then log_it "Received a new non-empty cmdline file from qemu-guest-agent" rm -rf $CMDLINE && mv $CMDLINE_PASSED $CMDLINE From a97b766708e8283c8f1a8c69ecaec6e9ce3887f3 Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Fri, 22 Apr 2022 09:56:14 +0200 Subject: [PATCH 09/11] Revert "kvm/vmware/xenserver: fix VR reboot from out-of-band" This reverts commit 7340cda499ce859dbc9d0453d93d3a69e0a5af1f. --- .../vmware/resource/VmwareResource.java | 34 ----------------- .../resource/CitrixResourceBase.java | 2 +- .../xenbase/CitrixCheckSshCommandWrapper.java | 21 ---------- scripts/vm/hypervisor/kvm/patch.sh | 2 +- .../debian/opt/cloud/bin/setup/bootstrap.sh | 38 +++---------------- 5 files changed, 7 insertions(+), 90 deletions(-) diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java index 0478656b58d5..3732804f9a8f 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -1702,43 +1702,9 @@ protected CheckSshAnswer execute(CheckSshCommand cmd) { networkUsage(privateIp, "create", null); } - if (VirtualMachineName.isValidRouterName(vmName)) { - reconfigureDomainRouterAfterStart(vmName); - } - return new CheckSshAnswer(cmd); } - private void reconfigureDomainRouterAfterStart(String vmName) { - s_logger.debug("Reconfigure to remove machine.id from domain router after start. vmName: " + vmName); - VmwareContext context = getServiceContext(); - try { - VmwareHypervisorHost hyperHost = getHyperHost(context); - VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName); - if (vmMo == null) { - if (hyperHost instanceof HostMO) { - ClusterMO clusterMo = new ClusterMO(hyperHost.getContext(), ((HostMO) hyperHost).getParentMor()); - vmMo = clusterMo.findVmOnHyperHost(vmName); - } - } - if (vmMo == null) { - String msg = "VM " + vmName + " no longer exists to execute UnPlugNic command"; - s_logger.error(msg); - throw new Exception(msg); - } - VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec(); - OptionValue option = new OptionValue(); - option.setKey("machine.id"); - option.setValue(""); - vmConfigSpec.getExtraConfig().add(option); - if (!vmMo.configureVm(vmConfigSpec)) { - throw new Exception("Failed to reconfigure domain router after start. vmName: " + vmName); - } - } catch (Exception e) { - s_logger.error("Unexpected exception when reconfigure domain router after start: ", e); - } - } - private DiskTO[] validateDisks(DiskTO[] disks) { List validatedDisks = new ArrayList(); diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java index d321e88a6a21..19625a2f09a1 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java @@ -309,7 +309,7 @@ private static boolean isAlienVm(final VM vm, final Connection conn) throws XenA private static final String XENSTORE_DATA_IP = "vm-data/ip"; private static final String XENSTORE_DATA_GATEWAY = "vm-data/gateway"; private static final String XENSTORE_DATA_NETMASK = "vm-data/netmask"; - public static final String XENSTORE_DATA_CS_INIT = "vm-data/cloudstack/init"; + private static final String XENSTORE_DATA_CS_INIT = "vm-data/cloudstack/init"; public CitrixResourceBase() { } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckSshCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckSshCommandWrapper.java index fc0a96571bfc..cf34a8fb30cd 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckSshCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckSshCommandWrapper.java @@ -19,10 +19,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; @@ -32,8 +28,6 @@ import com.cloud.resource.CommandWrapper; import com.cloud.resource.ResourceWrapper; import com.xensource.xenapi.Connection; -import com.xensource.xenapi.VM; - @ResourceWrapper(handles = CheckSshCommand.class) public final class CitrixCheckSshCommandWrapper extends CommandWrapper { @@ -66,21 +60,6 @@ public Answer execute(final CheckSshCommand command, final CitrixResourceBase ci s_logger.debug("Ping command port succeeded for vm " + vmName); } - try { - final Set vms = VM.getByNameLabel(conn, vmName); - if (vms != null) { - for (final VM vm : vms) { - s_logger.debug("Update boot args in xenstore-data for domain router after start. vmName: " + vmName); - Map xenstoreData = new HashMap<>(); - xenstoreData.put(citrixResourceBase.XENSTORE_DATA_CS_INIT, ""); - vm.setXenstoreData(conn, xenstoreData); - break; - } - } - } catch (final Exception e) { - s_logger.warn("Catch Exception: " + e.getClass().toString() + " due to " + e.toString(), e); - } - return new CheckSshAnswer(command); } } \ No newline at end of file diff --git a/scripts/vm/hypervisor/kvm/patch.sh b/scripts/vm/hypervisor/kvm/patch.sh index 246788e868fe..84c6b5b14509 100755 --- a/scripts/vm/hypervisor/kvm/patch.sh +++ b/scripts/vm/hypervisor/kvm/patch.sh @@ -72,4 +72,4 @@ do done # Write cmdline payload -send_file $name "/var/cache/cloud/cmdline_passed" $cmdline +send_file $name "/var/cache/cloud/cmdline" $cmdline diff --git a/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh b/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh index f85da13993c6..2335d649a950 100755 --- a/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh +++ b/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh @@ -18,7 +18,6 @@ PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" CMDLINE=/var/cache/cloud/cmdline -CMDLINE_PASSED=/var/cache/cloud/cmdline_passed rm -f /var/cache/cloud/enabled_svcs rm -f /var/cache/cloud/disabled_svcs @@ -84,17 +83,8 @@ config_guest() { if [ ! -f /usr/bin/xenstore-read ]; then log_it "ERROR: xentools not installed, cannot found xenstore-read" && exit 5 fi - /usr/bin/xenstore-read vm-data/cloudstack/init |tr -d "\n$" > $CMDLINE_PASSED - if [ -s $CMDLINE_PASSED ]; then - log_it "Received a new non-empty cmdline file from qemu-guest-agent" - rm -rf $CMDLINE && mv $CMDLINE_PASSED $CMDLINE - # Remove old configuration files in /etc/cloudstack if VR is booted from cloudstack - rm -rf /etc/cloudstack/*.json - log_it "Booting from cloudstack, remove old configuration files in /etc/cloudstack/" - break - else - sed -i "s/%/ /g" $CMDLINE - fi + /usr/bin/xenstore-read vm-data/cloudstack/init > $CMDLINE + sed -i "s/%/ /g" $CMDLINE ;; kvm) # Configure kvm hotplug support @@ -112,9 +102,8 @@ config_guest() { # Wait for $CMDLINE file to be written by the qemu-guest-agent for i in {1..60}; do - if [ -s $CMDLINE_PASSED ]; then + if [ -s $CMDLINE ]; then log_it "Received a new non-empty cmdline file from qemu-guest-agent" - rm -rf $CMDLINE && mv $CMDLINE_PASSED $CMDLINE # Remove old configuration files in /etc/cloudstack if VR is booted from cloudstack rm -rf /etc/cloudstack/*.json log_it "Booting from cloudstack, remove old configuration files in /etc/cloudstack/" @@ -133,31 +122,14 @@ config_guest() { systemctl enable open-vm-tools systemctl start open-vm-tools - vmtoolsd --cmd 'machine.id.get' > $CMDLINE_PASSED - if [ -s $CMDLINE_PASSED ]; then - log_it "Received a new non-empty cmdline file from vm-tools" - rm -rf $CMDLINE && mv $CMDLINE_PASSED $CMDLINE - # Remove old configuration files in /etc/cloudstack if VR is booted from cloudstack - rm -rf /etc/cloudstack/*.json - log_it "Booting from cloudstack, remove old configuration files in /etc/cloudstack/" - break - fi - + vmtoolsd --cmd 'machine.id.get' > $CMDLINE ;; virtualpc|hyperv) # Hyper-V is recognized as virtualpc hypervisor type. Boot args are passed using KVP Daemon systemctl enable hyperv-daemons.hv-fcopy-daemon.service hyperv-daemons.hv-kvp-daemon.service hyperv-daemons.hv-vss-daemon.service systemctl start hyperv-daemons.hv-fcopy-daemon.service hyperv-daemons.hv-kvp-daemon.service hyperv-daemons.hv-vss-daemon.service sleep 5 - cp -f /var/opt/hyperv/.kvp_pool_0 $CMDLINE_PASSED - if [ -s $CMDLINE_PASSED ]; then - log_it "Received a new non-empty cmdline file from vm-tools" - rm -rf $CMDLINE && mv $CMDLINE_PASSED $CMDLINE - # Remove old configuration files in /etc/cloudstack if VR is booted from cloudstack - rm -rf /etc/cloudstack/*.json - log_it "Booting from cloudstack, remove old configuration files in /etc/cloudstack/" - break - fi + cp -f /var/opt/hyperv/.kvp_pool_0 $CMDLINE cat /dev/null > /var/opt/hyperv/.kvp_pool_0 ;; virtualbox) From 064cb077b67f9a81c8f73d0476cfdd154d8cea7f Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Fri, 22 Apr 2022 09:56:30 +0200 Subject: [PATCH 10/11] VR: remove old json config when start vmware/xenserver VPC VRs (#5938) --- .../vmware/resource/VmwareResource.java | 34 +++++++++++++++++++ .../resource/CitrixResourceBase.java | 2 +- .../xenbase/CitrixCheckSshCommandWrapper.java | 21 ++++++++++++ scripts/vm/hypervisor/kvm/patch.sh | 6 +++- .../debian/opt/cloud/bin/setup/bootstrap.sh | 8 +++++ systemvm/debian/opt/cloud/bin/setup/init.sh | 33 +++++++++++++----- 6 files changed, 93 insertions(+), 11 deletions(-) diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java index 2180152ab067..b613f249af4d 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -1804,9 +1804,43 @@ protected CheckSshAnswer execute(CheckSshCommand cmd) { networkUsage(privateIp, "create", null); } + if (VirtualMachineName.isValidRouterName(vmName)) { + reconfigureDomainRouterAfterStart(vmName); + } + return new CheckSshAnswer(cmd); } + private void reconfigureDomainRouterAfterStart(String vmName) { + s_logger.debug("Reconfigure to remove machine.id from domain router after start. vmName: " + vmName); + VmwareContext context = getServiceContext(); + try { + VmwareHypervisorHost hyperHost = getHyperHost(context); + VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName); + if (vmMo == null) { + if (hyperHost instanceof HostMO) { + ClusterMO clusterMo = new ClusterMO(hyperHost.getContext(), ((HostMO) hyperHost).getParentMor()); + vmMo = clusterMo.findVmOnHyperHost(vmName); + } + } + if (vmMo == null) { + String msg = "VM " + vmName + " no longer exists to execute UnPlugNic command"; + s_logger.error(msg); + throw new Exception(msg); + } + VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec(); + OptionValue option = new OptionValue(); + option.setKey("machine.id"); + option.setValue(""); + vmConfigSpec.getExtraConfig().add(option); + if (!vmMo.configureVm(vmConfigSpec)) { + throw new Exception("Failed to reconfigure domain router after start. vmName: " + vmName); + } + } catch (Exception e) { + s_logger.error("Unexpected exception when reconfigure domain router after start: ", e); + } + } + private DiskTO[] validateDisks(DiskTO[] disks) { List validatedDisks = new ArrayList(); diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java index 6bed711b5f07..bdfd7cf6541b 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java @@ -312,7 +312,7 @@ private static boolean isAlienVm(final VM vm, final Connection conn) throws XenA private static final String XENSTORE_DATA_IP = "vm-data/ip"; private static final String XENSTORE_DATA_GATEWAY = "vm-data/gateway"; private static final String XENSTORE_DATA_NETMASK = "vm-data/netmask"; - private static final String XENSTORE_DATA_CS_INIT = "vm-data/cloudstack/init"; + public static final String XENSTORE_DATA_CS_INIT = "vm-data/cloudstack/init"; public CitrixResourceBase() { } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckSshCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckSshCommandWrapper.java index ec7d844dfbc7..25bf59927a57 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckSshCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckSshCommandWrapper.java @@ -19,6 +19,10 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; @@ -28,6 +32,8 @@ import com.cloud.resource.CommandWrapper; import com.cloud.resource.ResourceWrapper; import com.xensource.xenapi.Connection; +import com.xensource.xenapi.VM; + @ResourceWrapper(handles = CheckSshCommand.class) public final class CitrixCheckSshCommandWrapper extends CommandWrapper { @@ -60,6 +66,21 @@ public Answer execute(final CheckSshCommand command, final CitrixResourceBase ci s_logger.debug("Ping command port succeeded for vm " + vmName); } + try { + final Set vms = VM.getByNameLabel(conn, vmName); + if (vms != null) { + for (final VM vm : vms) { + s_logger.debug("Update boot args in xenstore-data for domain router after start. vmName: " + vmName); + Map xenstoreData = new HashMap<>(); + xenstoreData.put(citrixResourceBase.XENSTORE_DATA_CS_INIT, ""); + vm.setXenstoreData(conn, xenstoreData); + break; + } + } + } catch (final Exception e) { + s_logger.warn("Catch Exception: " + e.getClass().toString() + " due to " + e.toString(), e); + } + return new CheckSshAnswer(command); } } \ No newline at end of file diff --git a/scripts/vm/hypervisor/kvm/patch.sh b/scripts/vm/hypervisor/kvm/patch.sh index 84c6b5b14509..895dbf1fbe24 100755 --- a/scripts/vm/hypervisor/kvm/patch.sh +++ b/scripts/vm/hypervisor/kvm/patch.sh @@ -72,4 +72,8 @@ do done # Write cmdline payload -send_file $name "/var/cache/cloud/cmdline" $cmdline +if [[ $bootargs =~ .*type=cksnode.* ]];then + send_file $name "/var/cache/cloud/cmdline" $cmdline +else + send_file $name "/var/cache/cloud/cmdline_passed" $cmdline +fi \ No newline at end of file diff --git a/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh b/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh index 4720237543fb..35bdef77edcf 100755 --- a/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh +++ b/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh @@ -18,6 +18,7 @@ set -x PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" CMDLINE=/var/cache/cloud/cmdline +CMDLINE_PASSED=/var/cache/cloud/cmdline_passed rm -f /var/cache/cloud/enabled_svcs rm -f /var/cache/cloud/disabled_svcs @@ -29,6 +30,13 @@ log_it() { log_action_msg "$@" } +perform_actions_when_boot_from_cloudstack() { + rm -rf $CMDLINE && mv $CMDLINE_PASSED $CMDLINE + # Remove old configuration files in /etc/cloudstack if VR is booted from cloudstack + rm -rf /etc/cloudstack/*.json + log_it "Booting from cloudstack, removed old configuration files in /etc/cloudstack/" +} + patch_systemvm() { local patchfile=$1 local backupfolder="/tmp/.conf.backup" diff --git a/systemvm/debian/opt/cloud/bin/setup/init.sh b/systemvm/debian/opt/cloud/bin/setup/init.sh index a1ac48e46b56..16b41311dffc 100644 --- a/systemvm/debian/opt/cloud/bin/setup/init.sh +++ b/systemvm/debian/opt/cloud/bin/setup/init.sh @@ -74,8 +74,14 @@ config_guest() { if [ ! -f /usr/bin/xenstore-read ]; then log_it "ERROR: xentools not installed, cannot found xenstore-read" && exit 5 fi - /usr/bin/xenstore-read vm-data/cloudstack/init > $CMDLINE - sed -i "s/%/ /g" $CMDLINE + /usr/bin/xenstore-read vm-data/cloudstack/init |tr -d "\n$" > $CMDLINE_PASSED + if [ -s $CMDLINE_PASSED ]; then + log_it "Received a new non-empty cmdline file from qemu-guest-agent" + perform_actions_when_boot_from_cloudstack + break + else + sed -i "s/%/ /g" $CMDLINE + fi ;; kvm) # Configure kvm hotplug support @@ -92,12 +98,10 @@ config_guest() { systemctl start qemu-guest-agent # Wait for $CMDLINE file to be written by the qemu-guest-agent - for i in {1..60}; do - if [ -s $CMDLINE ]; then + for i in {1..10}; do + if [ -s $CMDLINE_PASSED ]; then log_it "Received a new non-empty cmdline file from qemu-guest-agent" - # Remove old configuration files in /etc/cloudstack if VR is booted from cloudstack - rm -rf /etc/cloudstack/*.json - log_it "Booting from cloudstack, remove old configuration files in /etc/cloudstack/" + perform_actions_when_boot_from_cloudstack break fi sleep 1 @@ -113,14 +117,25 @@ config_guest() { systemctl enable open-vm-tools systemctl start open-vm-tools - vmtoolsd --cmd 'machine.id.get' > $CMDLINE + vmtoolsd --cmd 'machine.id.get' > $CMDLINE_PASSED + if [ -s $CMDLINE_PASSED ]; then + log_it "Received a new non-empty cmdline file from vm-tools" + perform_actions_when_boot_from_cloudstack + break + fi + ;; virtualpc|hyperv) # Hyper-V is recognized as virtualpc hypervisor type. Boot args are passed using KVP Daemon systemctl enable hyperv-daemons.hv-fcopy-daemon.service hyperv-daemons.hv-kvp-daemon.service hyperv-daemons.hv-vss-daemon.service systemctl start hyperv-daemons.hv-fcopy-daemon.service hyperv-daemons.hv-kvp-daemon.service hyperv-daemons.hv-vss-daemon.service sleep 5 - cp -f /var/opt/hyperv/.kvp_pool_0 $CMDLINE + cp -f /var/opt/hyperv/.kvp_pool_0 $CMDLINE_PASSED + if [ -s $CMDLINE_PASSED ]; then + log_it "Received a new non-empty cmdline file from vm-tools" + perform_actions_when_boot_from_cloudstack + break + fi cat /dev/null > /var/opt/hyperv/.kvp_pool_0 ;; virtualbox) From 0b156df2419c746773581f8ea5c686c354714774 Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Fri, 22 Apr 2022 14:27:52 +0200 Subject: [PATCH 11/11] Update #5938: move method perform_actions_when_boot_from_cloudstack to init.sh --- systemvm/debian/opt/cloud/bin/setup/bootstrap.sh | 8 -------- systemvm/debian/opt/cloud/bin/setup/init.sh | 10 +++++++++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh b/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh index 35bdef77edcf..4720237543fb 100755 --- a/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh +++ b/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh @@ -18,7 +18,6 @@ set -x PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" CMDLINE=/var/cache/cloud/cmdline -CMDLINE_PASSED=/var/cache/cloud/cmdline_passed rm -f /var/cache/cloud/enabled_svcs rm -f /var/cache/cloud/disabled_svcs @@ -30,13 +29,6 @@ log_it() { log_action_msg "$@" } -perform_actions_when_boot_from_cloudstack() { - rm -rf $CMDLINE && mv $CMDLINE_PASSED $CMDLINE - # Remove old configuration files in /etc/cloudstack if VR is booted from cloudstack - rm -rf /etc/cloudstack/*.json - log_it "Booting from cloudstack, removed old configuration files in /etc/cloudstack/" -} - patch_systemvm() { local patchfile=$1 local backupfolder="/tmp/.conf.backup" diff --git a/systemvm/debian/opt/cloud/bin/setup/init.sh b/systemvm/debian/opt/cloud/bin/setup/init.sh index 16b41311dffc..32612975ccdb 100644 --- a/systemvm/debian/opt/cloud/bin/setup/init.sh +++ b/systemvm/debian/opt/cloud/bin/setup/init.sh @@ -19,6 +19,7 @@ set -x PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" CMDLINE=/var/cache/cloud/cmdline +CMDLINE_PASSED=/var/cache/cloud/cmdline_passed hypervisor() { if [ -d /proc/xen ]; then @@ -157,6 +158,13 @@ config_guest() { export TYPE=$(grep -Po 'type=\K[a-zA-Z]*' $CMDLINE) } +perform_actions_when_boot_from_cloudstack() { + rm -rf $CMDLINE && mv $CMDLINE_PASSED $CMDLINE + # Remove old configuration files in /etc/cloudstack if VR is booted from cloudstack + rm -rf /etc/cloudstack/*.json + log_it "Booting from cloudstack, removed old configuration files in /etc/cloudstack/" +} + setup_interface_sshd() { if [ "$TYPE" != "cksnode" ]; then @@ -229,4 +237,4 @@ log_it "Starting guest services for $HYPERVISOR" config_guest source /opt/cloud/bin/setup/common.sh -setup_interface_sshd \ No newline at end of file +setup_interface_sshd