Updated Branches: refs/heads/master 53f6b2aee -> af696e6ff
CLOUDSTACK-728 Remove the nvp portgroup when the virtual machine is expunged. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/af696e6f Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/af696e6f Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/af696e6f Branch: refs/heads/master Commit: af696e6ff67fdfc8477455ae2a57a20ab22e93ef Parents: 53f6b2a Author: Hugo Trippaers <[email protected]> Authored: Tue Jul 16 15:41:47 2013 +0200 Committer: Hugo Trippaers <[email protected]> Committed: Tue Jul 16 15:42:29 2013 +0200 ---------------------------------------------------------------------- .../vmware/resource/VmwareResource.java | 35 +++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/af696e6f/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java index 9049f4c..a45a8ce 100755 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -4865,14 +4865,39 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa * @return */ protected Answer execute(UnregisterNicCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource UnregisterNicCommand: " + _gson.toJson(cmd)); + s_logger.info("Executing resource UnregisterNicCommand: " + _gson.toJson(cmd)); + + if (_guestTrafficInfo == null) { + return new Answer(cmd, false, "No Guest Traffic Info found, unable to determine where to clean up"); } - VmwareContext context = getServiceContext(); - getHyperHost(context); try { - return new Answer(cmd, true, "Not implemented yet"); + if (_guestTrafficInfo.getVirtualSwitchType() != VirtualSwitchType.StandardVirtualSwitch) { + // For now we only need to cleanup the nvp specific portgroups + // on the standard switches + return new Answer(cmd, true, "Nothing to do"); + } + + s_logger.debug("Cleaning up portgroup " + cmd.getNicUuid() + " on switch " + + _guestTrafficInfo.getVirtualSwitchName()); + VmwareContext context = getServiceContext(); + VmwareHypervisorHost host = getHyperHost(context); + ManagedObjectReference clusterMO = host.getHyperHostCluster(); + + // Get a list of all the hosts in this cluster + @SuppressWarnings("unchecked") + List<ManagedObjectReference> hosts = (List<ManagedObjectReference>) context.getVimClient() + .getDynamicProperty(clusterMO, "host"); + if (hosts == null) { + return new Answer(cmd, false, "No hosts in cluster, which is pretty weird"); + } + + for (ManagedObjectReference hostMOR : hosts) { + HostMO hostMo = new HostMO(context, hostMOR); + hostMo.deletePortGroup(cmd.getNicUuid().toString()); + s_logger.debug("Removed portgroup " + cmd.getNicUuid() + " from host " + hostMo.getHostName()); + } + return new Answer(cmd, true, "Unregistered resources for NIC " + cmd.getNicUuid()); } catch (Exception e) { if (e instanceof RemoteException) { s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
