Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Comment on lines +1820 to +1825

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (vmMo == null) {
if (hyperHost instanceof HostMO) {
ClusterMO clusterMo = new ClusterMO(hyperHost.getContext(), ((HostMO) hyperHost).getParentMor());
vmMo = clusterMo.findVmOnHyperHost(vmName);
}
}
if (vmMo == null && 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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could instantiate a more specific exception.

}
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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could instantiate a more specific exception.

}
} catch (Exception e) {
s_logger.error("Unexpected exception when reconfigure domain router after start: ", e);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add the name of the VM to the log and pass the exception as parameter.

}
}

private DiskTO[] validateDisks(DiskTO[] disks) {
List<DiskTO> validatedDisks = new ArrayList<DiskTO>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<CheckSshCommand, Answer, CitrixResourceBase> {
Expand Down Expand Up @@ -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<VM> 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<String, String> 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);
}
}
6 changes: 5 additions & 1 deletion scripts/vm/hypervisor/kvm/patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
43 changes: 33 additions & 10 deletions systemvm/debian/opt/cloud/bin/setup/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -74,8 +75,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
Expand All @@ -92,12 +99,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
Expand All @@ -113,14 +118,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)
Expand All @@ -142,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
Expand Down Expand Up @@ -214,4 +237,4 @@ log_it "Starting guest services for $HYPERVISOR"

config_guest
source /opt/cloud/bin/setup/common.sh
setup_interface_sshd
setup_interface_sshd
9 changes: 9 additions & 0 deletions tools/marvin/marvin/lib/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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(
Expand Down