weizhouapache commented on a change in pull request #5985:
URL: https://github.com/apache/cloudstack/pull/5985#discussion_r807635754
##########
File path:
plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java
##########
@@ -1622,6 +1589,83 @@ private ExecutionResult
prepareNetworkElementCommand(IpAssocCommand cmd) {
return new ExecutionResult(true, null);
}
+ private ExecutionResult cleanupNetworkElementCommand(IpAssocCommand cmd) {
+ VmwareContext context = getServiceContext();
+ try {
+ VmwareHypervisorHost hyperHost = getHyperHost(context);
+ IpAddressTO[] ips = cmd.getIpAddresses();
+ String routerName =
cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
+
+ VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(routerName);
+ // command may sometimes be redirected to a wrong host, we relax
+ // the check and will try to find it within datacenter
+ if (vmMo == null) {
+ if (hyperHost instanceof HostMO) {
+ final DatacenterMO dcMo = new DatacenterMO(context,
hyperHost.getHyperHostDatacenter());
+ vmMo = dcMo.findVm(routerName);
+ }
+ }
+
+ if (vmMo == null) {
+ String msg = String.format("Router %s no longer exists to
execute IPAssoc command ", routerName);
+ s_logger.error(msg);
+ throw new Exception(msg);
+ }
+ final String lastIp =
cmd.getAccessDetail(NetworkElementCommand.NETWORK_PUB_LAST_IP);
+ if (ips.length == 1 && !ips[0].isAdd()) {
+ Pair<VirtualDevice, Integer> nicInfo = getVirtualDevice(vmMo,
ips[0]);
+
+ if (nicInfo.first() == null &&
lastIp.equalsIgnoreCase("true")) {
+ if (nicInfo.second() == 2) {
+ return new ExecutionResult(false, "Unable to remove
eth2 in network VR because it is the public NIC of source NAT");
Review comment:
@Pearl1594
for eth2, we can return a sucess result.
##########
File path:
plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java
##########
@@ -1622,6 +1589,83 @@ private ExecutionResult
prepareNetworkElementCommand(IpAssocCommand cmd) {
return new ExecutionResult(true, null);
}
+ private ExecutionResult cleanupNetworkElementCommand(IpAssocCommand cmd) {
+ VmwareContext context = getServiceContext();
+ try {
+ VmwareHypervisorHost hyperHost = getHyperHost(context);
+ IpAddressTO[] ips = cmd.getIpAddresses();
+ String routerName =
cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
+
+ VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(routerName);
+ // command may sometimes be redirected to a wrong host, we relax
+ // the check and will try to find it within datacenter
+ if (vmMo == null) {
+ if (hyperHost instanceof HostMO) {
+ final DatacenterMO dcMo = new DatacenterMO(context,
hyperHost.getHyperHostDatacenter());
+ vmMo = dcMo.findVm(routerName);
+ }
+ }
+
+ if (vmMo == null) {
+ String msg = String.format("Router %s no longer exists to
execute IPAssoc command ", routerName);
+ s_logger.error(msg);
+ throw new Exception(msg);
+ }
+ final String lastIp =
cmd.getAccessDetail(NetworkElementCommand.NETWORK_PUB_LAST_IP);
+ if (ips.length == 1 && !ips[0].isAdd()) {
Review comment:
@Pearl1594
sometimes there are multiple public Ip addresses in the IpAssocCommand
maybe it is better to loop all ip addresses, like kvm/xenserver plugins do.
##########
File path:
plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java
##########
@@ -1622,6 +1589,83 @@ private ExecutionResult
prepareNetworkElementCommand(IpAssocCommand cmd) {
return new ExecutionResult(true, null);
}
+ private ExecutionResult cleanupNetworkElementCommand(IpAssocCommand cmd) {
+ VmwareContext context = getServiceContext();
+ try {
+ VmwareHypervisorHost hyperHost = getHyperHost(context);
+ IpAddressTO[] ips = cmd.getIpAddresses();
+ String routerName =
cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
+
+ VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(routerName);
+ // command may sometimes be redirected to a wrong host, we relax
+ // the check and will try to find it within datacenter
+ if (vmMo == null) {
+ if (hyperHost instanceof HostMO) {
+ final DatacenterMO dcMo = new DatacenterMO(context,
hyperHost.getHyperHostDatacenter());
+ vmMo = dcMo.findVm(routerName);
+ }
+ }
+
+ if (vmMo == null) {
+ String msg = String.format("Router %s no longer exists to
execute IPAssoc command ", routerName);
+ s_logger.error(msg);
+ throw new Exception(msg);
+ }
+ final String lastIp =
cmd.getAccessDetail(NetworkElementCommand.NETWORK_PUB_LAST_IP);
+ if (ips.length == 1 && !ips[0].isAdd()) {
+ Pair<VirtualDevice, Integer> nicInfo = getVirtualDevice(vmMo,
ips[0]);
+
+ if (nicInfo.first() == null &&
lastIp.equalsIgnoreCase("true")) {
+ if (nicInfo.second() == 2) {
+ return new ExecutionResult(false, "Unable to remove
eth2 in network VR because it is the public NIC of source NAT");
+ }
+ return new ExecutionResult(false, "Couldn't find NIC");
+ }
+ configureNicDevice(vmMo, nicInfo.first(),
VirtualDeviceConfigSpecOperation.REMOVE, "unplugNicCommand");
+ }
+ } catch (Throwable e) {
+ s_logger.error("Unexpected exception: " + e.toString() + " will
shortcut rest of IPAssoc commands", e);
+ return new ExecutionResult(false, e.toString());
+ }
+ return new ExecutionResult(true, null);
+ }
+
+ private Pair<VirtualDevice, Integer> getVirtualDevice(VirtualMachineMO
vmMo, IpAddressTO ip) throws Exception {
+ NicTO nicTO = ip.getNicTO();
+ URI broadcastUri =
BroadcastDomainType.fromString(ip.getBroadcastUri());
+ if (BroadcastDomainType.getSchemeValue(broadcastUri) !=
BroadcastDomainType.Vlan) {
+ throw new InternalErrorException(String.format("Unable to assign a
public IP to a VIF on network %s", ip.getBroadcastUri()));
+ }
+ String vlanId = BroadcastDomainType.getValue(broadcastUri);
+
+ String publicNetworkName =
HypervisorHostHelper.getPublicNetworkNamePrefix(vlanId);
+ Pair<Integer, VirtualDevice> publicNicInfo =
vmMo.getNicDeviceIndex(publicNetworkName);
+
+ if (publicNicInfo.first() == 2) {
Review comment:
this is not needed ,because it is already handled in line 1619/1620
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]