Skip to content

Commit 593f1b6

Browse files
committed
Do not remove/unplug nic on removal of static nat on last IP (Public NIC)
1 parent 39a7499 commit 593f1b6

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

  • plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,7 +1597,7 @@ private ExecutionResult cleanupNetworkElementCommand(IpAssocCommand cmd) {
15971597
String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
15981598

15991599
VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(routerName);
1600-
// command may sometimes be redirect to a wrong host, we relax
1600+
// command may sometimes be redirected to a wrong host, we relax
16011601
// the check and will try to find it within datacenter
16021602
if (vmMo == null) {
16031603
if (hyperHost instanceof HostMO) {
@@ -1611,14 +1611,17 @@ private ExecutionResult cleanupNetworkElementCommand(IpAssocCommand cmd) {
16111611
s_logger.error(msg);
16121612
throw new Exception(msg);
16131613
}
1614-
1614+
final String lastIp = cmd.getAccessDetail(NetworkElementCommand.NETWORK_PUB_LAST_IP);
16151615
if (ips.length == 1 && !ips[0].isAdd()) {
1616-
VirtualDevice nic = getVirtualDevice(vmMo, ips[0]);
1616+
Pair<VirtualDevice, Integer> nicInfo = getVirtualDevice(vmMo, ips[0]);
16171617

1618-
if (nic == null) {
1618+
if (nicInfo.first() == null && lastIp.equalsIgnoreCase("true")) {
1619+
if (nicInfo.second() == 2) {
1620+
return new ExecutionResult(false, "Unable to remove eth2 in network VR because it is the public NIC of source NAT");
1621+
}
16191622
return new ExecutionResult(false, "Couldn't find NIC");
16201623
}
1621-
configureNicDevice(vmMo, nic, VirtualDeviceConfigSpecOperation.REMOVE, "unplugNicCommand");
1624+
configureNicDevice(vmMo, nicInfo.first(), VirtualDeviceConfigSpecOperation.REMOVE, "unplugNicCommand");
16221625
}
16231626
} catch (Throwable e) {
16241627
s_logger.error("Unexpected exception: " + e.toString() + " will shortcut rest of IPAssoc commands", e);
@@ -1627,7 +1630,7 @@ private ExecutionResult cleanupNetworkElementCommand(IpAssocCommand cmd) {
16271630
return new ExecutionResult(true, null);
16281631
}
16291632

1630-
private VirtualDevice getVirtualDevice(VirtualMachineMO vmMo, IpAddressTO ip) throws Exception {
1633+
private Pair<VirtualDevice, Integer> getVirtualDevice(VirtualMachineMO vmMo, IpAddressTO ip) throws Exception {
16311634
NicTO nicTO = ip.getNicTO();
16321635
URI broadcastUri = BroadcastDomainType.fromString(ip.getBroadcastUri());
16331636
if (BroadcastDomainType.getSchemeValue(broadcastUri) != BroadcastDomainType.Vlan) {
@@ -1638,11 +1641,16 @@ private VirtualDevice getVirtualDevice(VirtualMachineMO vmMo, IpAddressTO ip) th
16381641
String publicNetworkName = HypervisorHostHelper.getPublicNetworkNamePrefix(vlanId);
16391642
Pair<Integer, VirtualDevice> publicNicInfo = vmMo.getNicDeviceIndex(publicNetworkName);
16401643

1644+
if (publicNicInfo.first() == 2) {
1645+
s_logger.debug("Do not remove eth2 in network VR because it is the public NIC of source NAT.");
1646+
return new Pair<>(null, publicNicInfo.first());
1647+
}
1648+
16411649
if (s_logger.isDebugEnabled()) {
16421650
s_logger.debug(String.format("Find public NIC index, public network name: %s , index: %s", publicNetworkName, publicNicInfo.first()));
16431651
}
16441652

1645-
return findVirtualNicDevice(vmMo, nicTO.getMac());
1653+
return new Pair<>(findVirtualNicDevice(vmMo, nicTO.getMac()), publicNicInfo.first());
16461654
}
16471655

16481656
private void configureNicDevice(VirtualMachineMO vmMo, VirtualDevice nic, VirtualDeviceConfigSpecOperation operation, String commandName) throws Exception {

0 commit comments

Comments
 (0)