Skip to content

Commit af696e6

Browse files
committed
CLOUDSTACK-728 Remove the nvp portgroup when the virtual machine is
expunged.
1 parent 53f6b2a commit af696e6

1 file changed

Lines changed: 30 additions & 5 deletions

File tree

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

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4865,14 +4865,39 @@ protected Answer execute(UnregisterVMCommand cmd){
48654865
* @return
48664866
*/
48674867
protected Answer execute(UnregisterNicCommand cmd) {
4868-
if (s_logger.isInfoEnabled()) {
4869-
s_logger.info("Executing resource UnregisterNicCommand: " + _gson.toJson(cmd));
4868+
s_logger.info("Executing resource UnregisterNicCommand: " + _gson.toJson(cmd));
4869+
4870+
if (_guestTrafficInfo == null) {
4871+
return new Answer(cmd, false, "No Guest Traffic Info found, unable to determine where to clean up");
48704872
}
48714873

4872-
VmwareContext context = getServiceContext();
4873-
getHyperHost(context);
48744874
try {
4875-
return new Answer(cmd, true, "Not implemented yet");
4875+
if (_guestTrafficInfo.getVirtualSwitchType() != VirtualSwitchType.StandardVirtualSwitch) {
4876+
// For now we only need to cleanup the nvp specific portgroups
4877+
// on the standard switches
4878+
return new Answer(cmd, true, "Nothing to do");
4879+
}
4880+
4881+
s_logger.debug("Cleaning up portgroup " + cmd.getNicUuid() + " on switch "
4882+
+ _guestTrafficInfo.getVirtualSwitchName());
4883+
VmwareContext context = getServiceContext();
4884+
VmwareHypervisorHost host = getHyperHost(context);
4885+
ManagedObjectReference clusterMO = host.getHyperHostCluster();
4886+
4887+
// Get a list of all the hosts in this cluster
4888+
@SuppressWarnings("unchecked")
4889+
List<ManagedObjectReference> hosts = (List<ManagedObjectReference>) context.getVimClient()
4890+
.getDynamicProperty(clusterMO, "host");
4891+
if (hosts == null) {
4892+
return new Answer(cmd, false, "No hosts in cluster, which is pretty weird");
4893+
}
4894+
4895+
for (ManagedObjectReference hostMOR : hosts) {
4896+
HostMO hostMo = new HostMO(context, hostMOR);
4897+
hostMo.deletePortGroup(cmd.getNicUuid().toString());
4898+
s_logger.debug("Removed portgroup " + cmd.getNicUuid() + " from host " + hostMo.getHostName());
4899+
}
4900+
return new Answer(cmd, true, "Unregistered resources for NIC " + cmd.getNicUuid());
48764901
} catch (Exception e) {
48774902
if (e instanceof RemoteException) {
48784903
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");

0 commit comments

Comments
 (0)