diff --git a/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java index e47aee31880..e4953c21a4f 100755 --- a/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -4022,14 +4022,19 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa _morHyperHost.setType(hostTokens[0]); _morHyperHost.set_value(hostTokens[1]); - VmwareContext context = getServiceContext(); - try { - VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME); - mgr.setupResourceStartupParams(params); - - CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(context, context.getServiceContent().getCustomFieldsManager()); + VmwareContext context = getServiceContext(); + try { + VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME); + mgr.setupResourceStartupParams(params); + + CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(context, context.getServiceContent().getCustomFieldsManager()); cfmMo.ensureCustomFieldDef("Datastore", CustomFieldConstants.CLOUD_UUID); - cfmMo.ensureCustomFieldDef("Network", CustomFieldConstants.CLOUD_GC); + if (mgr.getNexusVSwitchGlobalParameter()) { + cfmMo.ensureCustomFieldDef("DistributedVirtualPortgroup", CustomFieldConstants.CLOUD_GC_DVP); + } else { + cfmMo.ensureCustomFieldDef("Network", CustomFieldConstants.CLOUD_GC); + } + cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_UUID); cfmMo.ensureCustomFieldDef("VirtualMachine", CustomFieldConstants.CLOUD_NIC_MASK); diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/CustomFieldConstants.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/CustomFieldConstants.java index 016b04c3b96..84f72fd0d70 100644 --- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/CustomFieldConstants.java +++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/CustomFieldConstants.java @@ -15,5 +15,6 @@ package com.cloud.hypervisor.vmware.mo; public interface CustomFieldConstants { public final static String CLOUD_UUID = "cloud.uuid"; public final static String CLOUD_GC = "cloud.gc"; + public final static String CLOUD_GC_DVP = "cloud.gc.dvp"; public final static String CLOUD_NIC_MASK = "cloud.nic.mask"; } diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java index 428c88a276c..f9127e3304a 100755 --- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java +++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java @@ -444,31 +444,6 @@ public class DatacenterMO extends BaseMO { public String getDvSwitchUuid(ManagedObjectReference dvSwitchMor) throws Exception { assert (dvSwitchMor != null); - PropertySpec pSpec = new PropertySpec(); - pSpec.setType("DistributedVirtualSwitch"); - pSpec.setPathSet(new String[] { "uuid" }); - - ObjectSpec oSpec = new ObjectSpec(); - oSpec.setObj(dvSwitchMor); - oSpec.setSkip(Boolean.FALSE); - oSpec.setSelectSet(new SelectionSpec[] {}); - - PropertyFilterSpec pfSpec = new PropertyFilterSpec(); - pfSpec.setPropSet(new PropertySpec[] { pSpec }); - pfSpec.setObjectSet(new ObjectSpec[] { oSpec }); - - ObjectContent[] ocs = _context.getService().retrieveProperties( - _context.getServiceContent().getPropertyCollector(), - new PropertyFilterSpec[] { pfSpec }); - - if (ocs != null) { - for (ObjectContent oc : ocs) { - DynamicProperty[] props = oc.getPropSet(); - if (props != null) { - return (String) props[0].getVal(); - } - } - } - return null; + return (String) _context.getServiceUtil().getDynamicProperty(dvSwitchMor, "uuid"); } } diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java index 52addafe46d..4ee61366ece 100755 --- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java +++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java @@ -176,6 +176,10 @@ public class HypervisorHostHelper { } catch (CloudRuntimeException e) { msg = "Failed to modify ethernet port profile " + ethPortProfileName + " with parameters " + params.toString(); s_logger.error(msg); + if(netconfClient != null) { + netconfClient.disconnect(); + s_logger.debug("Disconnected VSM session."); + } throw new CloudRuntimeException(msg); } } @@ -188,6 +192,7 @@ public class HypervisorHostHelper { s_logger.info("Adding port profile configured over VLAN : " + vlanId.toString()); netconfClient.addPortProfile(networkName, PortProfileType.vethernet, BindingType.portbindingstatic, SwitchPortMode.access, vlanId.intValue()); } + } catch (CloudRuntimeException e) { msg = "Failed to add vEthernet port profile " + networkName + ". Exception: " + e.toString(); s_logger.error(msg); @@ -195,6 +200,11 @@ public class HypervisorHostHelper { s_logger.warn("Ignoring exception : " + e.toString()); // throw new CloudRuntimeException(msg); } + } finally { + if(netconfClient != null) { + netconfClient.disconnect(); + s_logger.debug("Disconnected VSM session."); + } } } @@ -224,11 +234,16 @@ public class HypervisorHostHelper { params.add(new Pair(OperationType.addvlanid, vlanId.toString())); try { - netconfClient.updatePortProfile(ethPortProfileName, SwitchPortMode.access, params); + netconfClient.updatePortProfile(ethPortProfileName, SwitchPortMode.trunk, params); } catch(CloudRuntimeException e) { msg = "Failed to modify ethernet port profile " + ethPortProfileName + " with parameters " + params.toString(); s_logger.error(msg); throw new CloudRuntimeException(msg); + } finally { + if(netconfClient != null) { + netconfClient.disconnect(); + s_logger.debug("Disconnected VSM session."); + } } } @@ -339,7 +354,8 @@ public class HypervisorHostHelper { if(createGCTag) { NetworkMO networkMo = new NetworkMO(hostMo.getContext(), morNetwork); - networkMo.setCustomFieldValue(CustomFieldConstants.CLOUD_GC, "true"); + networkMo.setCustomFieldValue(CustomFieldConstants.CLOUD_GC_DVP, "true"); + s_logger.debug("Added custom field : " + CustomFieldConstants.CLOUD_GC_DVP); } return new Pair(morNetwork, networkName); diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java index 71907b0ced1..dade93dd4cc 100644 --- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java +++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java @@ -650,6 +650,11 @@ public class VirtualMachineMO extends BaseMO { int gcTagKey = getCustomFieldKey("Network", CustomFieldConstants.CLOUD_GC); + if(gcTagKey == 0) { + gcTagKey = getCustomFieldKey("DistributedVirtualPortgroup", CustomFieldConstants.CLOUD_GC_DVP); + s_logger.debug("The custom key for dvPortGroup is : " + gcTagKey); + } + PropertySpec pSpec = new PropertySpec(); pSpec.setType("Network"); pSpec.setPathSet(new String[] {"name", "vm", String.format("value[%d]", gcTagKey)}); @@ -696,6 +701,7 @@ public class VirtualMachineMO extends BaseMO { networks.add(details); } + s_logger.debug("Retrieved " + networks.size() + " networks with key : " + gcTagKey); } return networks;