use of com.vmware.vim25.mo.Network in project cloudstack by apache.
the class DatacenterMO method getDvSwitchMor.
public ManagedObjectReference getDvSwitchMor(ManagedObjectReference dvPortGroupMor) throws Exception {
String dvPortGroupKey = null;
ManagedObjectReference dvSwitchMor = null;
PropertySpec pSpec = new PropertySpec();
pSpec.setType("DistributedVirtualPortgroup");
pSpec.getPathSet().add("key");
pSpec.getPathSet().add("config.distributedVirtualSwitch");
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.getSelectSet().add(datacenter2DvPortGroupTraversal);
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.getPropSet().add(pSpec);
pfSpec.getObjectSet().add(oSpec);
List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
pfSpecArr.add(pfSpec);
List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
if (ocs != null) {
for (ObjectContent oc : ocs) {
List<DynamicProperty> props = oc.getPropSet();
if (props != null) {
assert (props.size() == 2);
for (DynamicProperty prop : props) {
if (prop.getName().equals("key")) {
dvPortGroupKey = (String) prop.getVal();
} else {
dvSwitchMor = (ManagedObjectReference) prop.getVal();
}
}
if ((dvPortGroupKey != null) && dvPortGroupKey.equals(dvPortGroupMor.getValue())) {
return dvSwitchMor;
}
}
}
}
return null;
}
use of com.vmware.vim25.mo.Network in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method getNetworks.
public String[] getNetworks() throws Exception {
PropertySpec pSpec = new PropertySpec();
pSpec.setType("Network");
pSpec.setPathSet(new String[] { "name" });
TraversalSpec vm2NetworkTraversal = new TraversalSpec();
vm2NetworkTraversal.setType("VirtualMachine");
vm2NetworkTraversal.setPath("network");
vm2NetworkTraversal.setName("vm2NetworkTraversal");
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(_mor);
oSpec.setSkip(Boolean.TRUE);
oSpec.setSelectSet(new SelectionSpec[] { vm2NetworkTraversal });
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 });
List<String> networks = new ArrayList<String>();
if (ocs != null && ocs.length > 0) {
for (ObjectContent oc : ocs) {
networks.add(oc.getPropSet(0).getVal().toString());
}
}
return networks.toArray(new String[0]);
}
use of com.vmware.vim25.mo.Network in project CloudStack-archive by CloudStack-extras.
the class HostMO method getPortGroupNameByNicType.
public String getPortGroupNameByNicType(HostVirtualNicType nicType) throws Exception {
assert (nicType != null);
VirtualNicManagerNetConfig[] netConfigs = (VirtualNicManagerNetConfig[]) _context.getServiceUtil().getDynamicProperty(_mor, "config.virtualNicManagerInfo.netConfig");
if (netConfigs != null) {
for (VirtualNicManagerNetConfig netConfig : netConfigs) {
if (netConfig.getNicType().equals(nicType.toString())) {
HostVirtualNic[] nics = netConfig.getCandidateVnic();
if (nics != null) {
for (HostVirtualNic nic : nics) {
return nic.getPortgroup();
}
}
}
}
}
if (nicType == HostVirtualNicType.management) {
// ESX management network is configured in service console
HostNetworkInfo netInfo = getHostNetworkInfo();
assert (netInfo != null);
HostVirtualNic[] nics = netInfo.getConsoleVnic();
if (nics != null) {
for (HostVirtualNic nic : nics) {
return nic.getPortgroup();
}
}
}
return null;
}
use of com.vmware.vim25.mo.Network in project CloudStack-archive by CloudStack-extras.
the class HypervisorHostHelper method prepareNetwork.
/**
* @param ethPortProfileName
* @param namePrefix
* @param hostMo
* @param vlanId
* @param networkRateMbps
* @param networkRateMulticastMbps
* @param timeOutMs
* @return
* @throws Exception
*/
public static Pair<ManagedObjectReference, String> prepareNetwork(String ethPortProfileName, String namePrefix, HostMO hostMo, String vlanId, Integer networkRateMbps, Integer networkRateMulticastMbps, long timeOutMs) throws Exception {
ManagedObjectReference morNetwork = null;
VmwareContext context = hostMo.getContext();
ManagedObjectReference dcMor = hostMo.getHyperHostDatacenter();
DatacenterMO dataCenterMo = new DatacenterMO(context, dcMor);
ManagedObjectReference morEthernetPortProfile = dataCenterMo.getDvPortGroupMor(ethPortProfileName);
if (morEthernetPortProfile == null) {
String msg = "Unable to find Ethernet port profile " + ethPortProfileName;
s_logger.error(msg);
throw new Exception(msg);
} else {
s_logger.info("Found Ethernet port profile " + ethPortProfileName);
}
boolean createGCTag = false;
String networkName;
Integer vid = null;
if (vlanId != null && !UNTAGGED_VLAN_NAME.equalsIgnoreCase(vlanId)) {
createGCTag = true;
vid = Integer.parseInt(vlanId);
}
networkName = composeCloudNetworkName(namePrefix, vlanId, networkRateMbps, ethPortProfileName);
// TODO(sateesh): Enable this for VMware DVS.
// DVSTrafficShapingPolicy shapingPolicy = null;
// if (networkRateMbps != null && networkRateMbps.intValue() > 0) {
// shapingPolicy = new DVSTrafficShapingPolicy();
// BoolPolicy isEnabled = new BoolPolicy();
// LongPolicy averageBandwidth = new LongPolicy();
// LongPolicy peakBandwidth = new LongPolicy();
// LongPolicy burstSize = new LongPolicy();
//
// isEnabled.setValue(true);
// averageBandwidth.setValue((long) networkRateMbps.intValue() * 1024L * 1024L);
// // We chose 50% higher allocation than average bandwidth.
// // TODO(sateesh): Also let user specify the peak coefficient
// peakBandwidth.setValue((long) (averageBandwidth.getValue() * 1.5));
// // TODO(sateesh): Also let user specify the burst coefficient
// burstSize.setValue((long) (5 * averageBandwidth.getValue() / 8));
//
// shapingPolicy.setEnabled(isEnabled);
// shapingPolicy.setAverageBandwidth(averageBandwidth);
// shapingPolicy.setPeakBandwidth(peakBandwidth);
// shapingPolicy.setBurstSize(burstSize);
// }
DVPortgroupConfigInfo spec = dataCenterMo.getDvPortGroupSpec(networkName);
long averageBandwidth = 0L;
if (networkRateMbps != null && networkRateMbps.intValue() > 0) {
averageBandwidth = (long) (networkRateMbps.intValue() * 1024L * 1024L);
}
// We chose 50% higher allocation than average bandwidth.
// TODO(sateesh): Also let user specify the peak coefficient
long peakBandwidth = (long) (averageBandwidth * 1.5);
// TODO(sateesh): Also let user specify the burst coefficient
long burstSize = 5 * averageBandwidth / 8;
boolean bWaitPortGroupReady = false;
if (!dataCenterMo.hasDvPortGroup(networkName)) {
s_logger.info("Port profile " + networkName + " not found.");
createPortProfile(context, ethPortProfileName, networkName, vid, networkRateMbps, peakBandwidth, burstSize);
bWaitPortGroupReady = true;
} else {
s_logger.info("Port profile " + networkName + " found.");
bWaitPortGroupReady = true;
updatePortProfile(context, ethPortProfileName, networkName, vid, networkRateMbps, peakBandwidth, burstSize);
}
// Wait for dvPortGroup on vCenter
if (bWaitPortGroupReady)
morNetwork = waitForDvPortGroupReady(dataCenterMo, networkName, timeOutMs);
else
morNetwork = dataCenterMo.getDvPortGroupMor(networkName);
if (morNetwork == null) {
String msg = "Failed to create guest network " + networkName;
s_logger.error(msg);
throw new Exception(msg);
}
if (createGCTag) {
NetworkMO networkMo = new NetworkMO(hostMo.getContext(), morNetwork);
networkMo.setCustomFieldValue(CustomFieldConstants.CLOUD_GC_DVP, "true");
s_logger.debug("Added custom field : " + CustomFieldConstants.CLOUD_GC_DVP);
}
return new Pair<ManagedObjectReference, String>(morNetwork, networkName);
}
use of com.vmware.vim25.mo.Network in project CloudStack-archive by CloudStack-extras.
the class DatacenterMO method getDvPortBackingInfo.
public VirtualEthernetCardDistributedVirtualPortBackingInfo getDvPortBackingInfo(Pair<ManagedObjectReference, String> networkInfo) throws Exception {
assert (networkInfo != null);
assert (networkInfo.first() != null && networkInfo.first().getType().equalsIgnoreCase("DistributedVirtualPortgroup"));
final VirtualEthernetCardDistributedVirtualPortBackingInfo dvPortBacking = new VirtualEthernetCardDistributedVirtualPortBackingInfo();
final DistributedVirtualSwitchPortConnection dvPortConnection = new DistributedVirtualSwitchPortConnection();
ManagedObjectReference dvsMor = getDvSwitchMor(networkInfo.first());
String dvSwitchUuid = getDvSwitchUuid(dvsMor);
dvPortConnection.setSwitchUuid(dvSwitchUuid);
dvPortConnection.setPortgroupKey(networkInfo.first().get_value());
dvPortBacking.setPort(dvPortConnection);
System.out.println("Plugging NIC device into network " + networkInfo.second() + " backed by dvSwitch: " + dvSwitchUuid);
return dvPortBacking;
}
Aggregations