CS-9919 Support for Nexus Swiches (Cisco Vswitches)

Description:

	Moved dvSwitch specific functionality over datacenter.

Conflicts:

	vmware-base/src/com/cloud/hypervisor/vmware/mo/DatacenterMO.java
	vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java
This commit is contained in:
Sateesh Chodapuneedi 2012-05-10 18:35:44 +05:30 committed by Vijayendra Bhamidipati
parent 04898a0bf9
commit aa1f26cb00
3 changed files with 328 additions and 323 deletions

View File

@ -10,6 +10,7 @@
// limitations under the License.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.hypervisor.vmware.mo;
import java.util.ArrayList;
@ -19,6 +20,7 @@ import com.cloud.hypervisor.vmware.util.VmwareContext;
import com.cloud.utils.Pair;
import com.vmware.apputils.vim25.ServiceUtil;
import com.vmware.vim25.CustomFieldStringValue;
import com.vmware.vim25.DVPortgroupConfigInfo;
import com.vmware.vim25.DynamicProperty;
import com.vmware.vim25.ManagedObjectReference;
import com.vmware.vim25.ObjectContent;
@ -300,4 +302,96 @@ public class DatacenterMO extends BaseMO {
String dcName = ocs[0].getPropSet(0).getVal().toString();
return new Pair<DatacenterMO, String>(new DatacenterMO(context, ocs[0].getObj()), dcName);
}
public ManagedObjectReference getDvPortGroupMor(String dvPortGroupName) throws Exception {
PropertySpec pSpec = new PropertySpec();
pSpec.setType("DistributedVirtualPortgroup");
pSpec.setPathSet(new String[] {"name"});
TraversalSpec datacenter2DvPortGroupTraversal = new TraversalSpec();
datacenter2DvPortGroupTraversal.setType("Datacenter");
datacenter2DvPortGroupTraversal.setPath("network");
datacenter2DvPortGroupTraversal.setName("datacenter2DvPortgroupTraversal");
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(_mor);
oSpec.setSkip(Boolean.TRUE);
oSpec.setSelectSet(new SelectionSpec[] { datacenter2DvPortGroupTraversal });
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) {
for(DynamicProperty prop : props) {
if(prop.getVal().equals(dvPortGroupName))
return oc.getObj();
}
}
}
}
return null;
}
public boolean hasDvPortGroup(String dvPortGroupName) throws Exception {
ManagedObjectReference morNetwork = getDvPortGroupMor(dvPortGroupName);
if(morNetwork != null)
return true;
return false;
}
public DVPortgroupConfigInfo getDvPortGroupSpec(String dvPortGroupName) throws Exception {
DVPortgroupConfigInfo configSpec = null;
String nameProperty = null;
PropertySpec pSpec = new PropertySpec();
pSpec.setType("DistributedVirtualPortgroup");
pSpec.setPathSet(new String[] {"name", "config"});
TraversalSpec datacenter2DvPortGroupTraversal = new TraversalSpec();
datacenter2DvPortGroupTraversal.setType("Datacenter");
datacenter2DvPortGroupTraversal.setPath("network");
datacenter2DvPortGroupTraversal.setName("datacenter2DvPortgroupTraversal");
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(_mor);
oSpec.setSkip(Boolean.TRUE);
oSpec.setSelectSet(new SelectionSpec[] { datacenter2DvPortGroupTraversal });
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) {
assert(props.length == 2);
for(DynamicProperty prop : props) {
if(prop.getName().equals("config")) {
configSpec = (DVPortgroupConfigInfo) prop.getVal();
}
else {
nameProperty = prop.getVal().toString();
}
}
if(nameProperty.equalsIgnoreCase(dvPortGroupName)) {
return configSpec;
}
}
}
}
return null;
}
}

View File

@ -27,9 +27,7 @@ import com.vmware.apputils.vim25.ServiceUtil;
import com.vmware.vim25.AboutInfo;
import com.vmware.vim25.ClusterDasConfigInfo;
import com.vmware.vim25.ComputeResourceSummary;
import com.vmware.vim25.DVPortgroupConfigSpec;
import com.vmware.vim25.DatastoreSummary;
import com.vmware.vim25.DistributedVirtualSwitchInfo;
import com.vmware.vim25.DynamicProperty;
import com.vmware.vim25.HostConfigManager;
import com.vmware.vim25.HostConnectInfo;
@ -895,95 +893,4 @@ public class HostMO extends BaseMO implements VmwareHypervisorHost {
HostRuntimeInfo runtimeInfo = (HostRuntimeInfo)_context.getServiceUtil().getDynamicProperty(_mor, "runtime");
return runtimeInfo.getConnectionState() == HostSystemConnectionState.connected;
}
public DVPortgroupConfigSpec getDvPortGroupSpec(String dvPortGroupName) throws Exception {
DVPortgroupConfigSpec configSpec = null;
String nameProperty = null;
PropertySpec pSpec = new PropertySpec();
pSpec.setType("DistributedVirtualPortgroup");
pSpec.setPathSet(new String[] {"summary.name", "config"});
TraversalSpec host2DvPortGroupTraversal = new TraversalSpec();
host2DvPortGroupTraversal.setType("HostSystem");
host2DvPortGroupTraversal.setPath("network");
host2DvPortGroupTraversal.setName("host2DvPortgroupTraversal");
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(_mor);
oSpec.setSkip(Boolean.TRUE);
oSpec.setSelectSet(new SelectionSpec[] { host2DvPortGroupTraversal });
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) {
assert(props.length == 2);
for(DynamicProperty prop : props) {
if(prop.getName().equals("config")) {
configSpec = (DVPortgroupConfigSpec) prop.getVal();
}
else {
nameProperty = prop.getVal().toString();
}
if(nameProperty.equalsIgnoreCase(dvPortGroupName)) {
return configSpec;
}
}
}
}
}
return null;
}
public ManagedObjectReference getDvPortGroupMor(String dvPortGroupName) throws Exception {
PropertySpec pSpec = new PropertySpec();
pSpec.setType("DistributedVirtualPortgroup");
pSpec.setPathSet(new String[] {"summary.name"});
TraversalSpec host2DvPortGroupTraversal = new TraversalSpec();
host2DvPortGroupTraversal.setType("HostSystem");
host2DvPortGroupTraversal.setPath("network");
host2DvPortGroupTraversal.setName("host2DvPortgroupTraversal");
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(_mor);
oSpec.setSkip(Boolean.TRUE);
oSpec.setSelectSet(new SelectionSpec[] { host2DvPortGroupTraversal });
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) {
for(DynamicProperty prop : props) {
if(prop.getVal().equals(dvPortGroupName))
return oc.getObj();
}
}
}
}
return null;
}
public boolean hasDvPortGroup(String dvPortGroupName) throws Exception {
ManagedObjectReference morNetwork = getDvPortGroupMor(dvPortGroupName);
if(morNetwork != null)
return true;
return false;
}
}

View File

@ -38,6 +38,7 @@ import com.vmware.vim25.BoolPolicy;
import com.vmware.vim25.DVPortgroupConfigSpec;
import com.vmware.vim25.DVSTrafficShapingPolicy;
//import com.vmware.vim25.DistributedVirtualSwitchKeyedOpaqueBlob;
import com.vmware.vim25.DVPortgroupConfigInfo;
import com.vmware.vim25.DynamicProperty;
import com.vmware.vim25.HostNetworkTrafficShapingPolicy;
import com.vmware.vim25.HostPortGroupSpec;
@ -220,8 +221,10 @@ public class HypervisorHostHelper {
long timeOutMs) throws Exception, CloudRuntimeException {
ManagedObjectReference morNetwork = null;
VmwareContext context = hostMo.getContext();
ManagedObjectReference dcMor = hostMo.getHyperHostDatacenter();
DatacenterMO dataCenterMo = new DatacenterMO(context, dcMor);
ManagedObjectReference morEthernetPortProfile = hostMo.getDvPortGroupMor(ethPortProfileName);
ManagedObjectReference morEthernetPortProfile = dataCenterMo.getDvPortGroupMor(ethPortProfileName);
if (morEthernetPortProfile == null) {
String msg = "Unable to find Ethernet port profile " + ethPortProfileName;
@ -261,12 +264,13 @@ public class HypervisorHostHelper {
shapingPolicy.setPeakBandwidth(peakBandwidth);
shapingPolicy.setBurstSize(burstSize);
}
boolean bWaitPortGroupReady = false;
if (!hostMo.hasDvPortGroup(networkName)) {
if (!dataCenterMo.hasDvPortGroup(networkName)) {
createPortProfile(context, ethPortProfileName, networkName, vid, networkRateMbps);
bWaitPortGroupReady = true;
} else {
DVPortgroupConfigSpec spec = hostMo.getDvPortGroupSpec(networkName);
DVPortgroupConfigInfo spec = dataCenterMo.getDvPortGroupSpec(networkName);
if(!isSpecMatch(spec, vid, shapingPolicy)) {
updatePortProfile(context, ethPortProfileName, vid, networkRateMbps);
bWaitPortGroupReady = true;
@ -274,9 +278,9 @@ public class HypervisorHostHelper {
}
//Wait for dvPortGroup on vCenter
if(bWaitPortGroupReady)
morNetwork = waitForDvPortGroupReady(hostMo, networkName, timeOutMs);
morNetwork = waitForDvPortGroupReady(dataCenterMo, networkName, timeOutMs);
else
morNetwork = hostMo.getDvPortGroupMor(networkName);
morNetwork = dataCenterMo.getDvPortGroupMor(networkName);
if (morNetwork == null) {
String msg = "Failed to create guest network " + networkName;
s_logger.error(msg);
@ -292,14 +296,14 @@ public class HypervisorHostHelper {
}
private static ManagedObjectReference waitForDvPortGroupReady(
HostMO hostMo, String dvPortGroupName, long timeOutMs) throws Exception {
DatacenterMO dataCenterMo, String dvPortGroupName, long timeOutMs) throws Exception {
ManagedObjectReference morDvPortGroup = null;
// if DvPortGroup is just created, we may fail to retrieve it, we
// need to retry
long startTick = System.currentTimeMillis();
while (System.currentTimeMillis() - startTick <= timeOutMs) {
morDvPortGroup = hostMo.getDvPortGroupMor(dvPortGroupName);
morDvPortGroup = dataCenterMo.getDvPortGroupMor(dvPortGroupName);
if (morDvPortGroup != null) {
break;
}
@ -310,7 +314,7 @@ public class HypervisorHostHelper {
return morDvPortGroup;
}
private static boolean isSpecMatch(DVPortgroupConfigSpec spec, Integer vid,
private static boolean isSpecMatch(DVPortgroupConfigInfo spec, Integer vid,
DVSTrafficShapingPolicy shapingPolicy) {
DVSTrafficShapingPolicy currentTrafficShapingPolicy;
currentTrafficShapingPolicy = spec.getDefaultPortConfig().getInShapingPolicy();