mirror of https://github.com/apache/cloudstack.git
CS-9919 Support for Nexus Swiches (Cisco Vswitches)
Description: Moved dvSwitch specific functionality over datacenter.
This commit is contained in:
parent
b7196a566e
commit
2ebdc817a8
|
|
@ -12,21 +12,22 @@
|
|||
// Automatically generated by addcopyright.py at 04/03/2012
|
||||
package com.cloud.hypervisor.vmware.mo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.vmware.apputils.vim25.ServiceUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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.DynamicProperty;
|
||||
import com.vmware.vim25.ManagedObjectReference;
|
||||
import com.vmware.vim25.ObjectContent;
|
||||
import com.vmware.vim25.ObjectSpec;
|
||||
import com.vmware.vim25.PropertyFilterSpec;
|
||||
import com.vmware.vim25.PropertySpec;
|
||||
import com.vmware.vim25.SelectionSpec;
|
||||
import com.vmware.vim25.TraversalSpec;
|
||||
import com.vmware.vim25.DVPortgroupConfigInfo;
|
||||
import com.vmware.vim25.DynamicProperty;
|
||||
import com.vmware.vim25.ManagedObjectReference;
|
||||
import com.vmware.vim25.ObjectContent;
|
||||
import com.vmware.vim25.ObjectSpec;
|
||||
import com.vmware.vim25.PropertyFilterSpec;
|
||||
import com.vmware.vim25.PropertySpec;
|
||||
import com.vmware.vim25.SelectionSpec;
|
||||
import com.vmware.vim25.TraversalSpec;
|
||||
|
||||
public class DatacenterMO extends BaseMO {
|
||||
|
||||
|
|
@ -299,5 +300,97 @@ 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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -894,96 +892,5 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -212,8 +213,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;
|
||||
|
|
@ -253,12 +256,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;
|
||||
|
|
@ -266,9 +270,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);
|
||||
|
|
@ -284,14 +288,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;
|
||||
}
|
||||
|
|
@ -302,7 +306,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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue