use of com.vmware.vim25.LongPolicy 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.LongPolicy in project CloudStack-archive by CloudStack-extras.
the class HypervisorHostHelper method isSpecMatch.
// This method would be used for VMware Distributed Virtual Switch.
private static boolean isSpecMatch(DVPortgroupConfigInfo spec, Integer vid, DVSTrafficShapingPolicy shapingPolicy) {
DVSTrafficShapingPolicy currentTrafficShapingPolicy;
currentTrafficShapingPolicy = spec.getDefaultPortConfig().getInShapingPolicy();
assert (currentTrafficShapingPolicy != null);
LongPolicy averageBandwidth = currentTrafficShapingPolicy.getAverageBandwidth();
LongPolicy burstSize = currentTrafficShapingPolicy.getBurstSize();
LongPolicy peakBandwidth = currentTrafficShapingPolicy.getPeakBandwidth();
BoolPolicy isEnabled = currentTrafficShapingPolicy.getEnabled();
if (!isEnabled.getValue())
return false;
if (averageBandwidth != null && !averageBandwidth.equals(shapingPolicy.getAverageBandwidth())) {
if (s_logger.isInfoEnabled()) {
s_logger.info("Average bandwidth setting in shaping policy doesn't match with existing setting.");
}
return false;
} else if (burstSize != null && !burstSize.equals(shapingPolicy.getBurstSize())) {
if (s_logger.isInfoEnabled()) {
s_logger.info("Burst size setting in shaping policy doesn't match with existing setting.");
}
return false;
} else if (peakBandwidth != null && !peakBandwidth.equals(shapingPolicy.getPeakBandwidth())) {
if (s_logger.isInfoEnabled()) {
s_logger.info("Peak bandwidth setting in shaping policy doesn't match with existing setting.");
}
return false;
}
return true;
}
use of com.vmware.vim25.LongPolicy in project cloudstack by apache.
the class HypervisorHostHelper method getDVSShapingPolicy.
public static DVSTrafficShapingPolicy getDVSShapingPolicy(Integer networkRateMbps) {
DVSTrafficShapingPolicy shapingPolicy = new DVSTrafficShapingPolicy();
BoolPolicy isEnabled = new BoolPolicy();
if (networkRateMbps == null || networkRateMbps.intValue() <= 0) {
isEnabled.setValue(false);
shapingPolicy.setEnabled(isEnabled);
return shapingPolicy;
}
LongPolicy averageBandwidth = new LongPolicy();
LongPolicy peakBandwidth = new LongPolicy();
LongPolicy burstSize = new LongPolicy();
isEnabled.setValue(true);
averageBandwidth.setValue(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(5 * averageBandwidth.getValue() / 8);
shapingPolicy.setEnabled(isEnabled);
shapingPolicy.setAverageBandwidth(averageBandwidth);
shapingPolicy.setPeakBandwidth(peakBandwidth);
shapingPolicy.setBurstSize(burstSize);
return shapingPolicy;
}
use of com.vmware.vim25.LongPolicy in project cloudstack by apache.
the class HypervisorHostHelperTest method testIsSpecMatchConfigSpecWithMoreDvPortsAndAutoExpandEnabled.
@Test
public void testIsSpecMatchConfigSpecWithMoreDvPortsAndAutoExpandEnabled() throws Exception {
int currentNumPorts = 512;
int currentvlanId = 100;
boolean currentAutoExpand = true;
DVSTrafficShapingPolicy currentTrafficShapingPolicy = new DVSTrafficShapingPolicy();
BoolPolicy currentIsEnabled = new BoolPolicy();
currentIsEnabled.setValue(true);
LongPolicy currentAvgBw = new LongPolicy();
currentAvgBw.setValue(200L);
LongPolicy currentBurstSize = new LongPolicy();
currentBurstSize.setValue(400L);
LongPolicy currentPeakBw = new LongPolicy();
currentPeakBw.setValue(2000L);
VMwareDVSPortSetting currentVmwareDvsPortSetting = new VMwareDVSPortSetting();
VmwareDistributedVirtualSwitchVlanIdSpec currentVlanIdSpec = new VmwareDistributedVirtualSwitchVlanIdSpec();
currentVlanIdSpec.setVlanId(currentvlanId);
currentVmwareDvsPortSetting.setVlan(currentVlanIdSpec);
currentTrafficShapingPolicy.setAverageBandwidth(currentAvgBw);
currentTrafficShapingPolicy.setBurstSize(currentBurstSize);
currentTrafficShapingPolicy.setPeakBandwidth(currentPeakBw);
currentTrafficShapingPolicy.setEnabled(currentIsEnabled);
currentVmwareDvsPortSetting.setInShapingPolicy(currentTrafficShapingPolicy);
when(currentDvPortgroupInfo.getNumPorts()).thenReturn(currentNumPorts);
when(currentDvPortgroupInfo.isAutoExpand()).thenReturn(currentAutoExpand);
when(currentDvPortgroupInfo.getDefaultPortConfig()).thenReturn(currentVmwareDvsPortSetting);
int newNumPorts = 256;
int newvlanId = 100;
boolean newAutoExpand = true;
DVSTrafficShapingPolicy newTrafficShapingPolicy = new DVSTrafficShapingPolicy();
BoolPolicy newIsEnabled = new BoolPolicy();
newIsEnabled.setValue(true);
LongPolicy newAvgBw = new LongPolicy();
newAvgBw.setValue(200L);
LongPolicy newBurstSize = new LongPolicy();
newBurstSize.setValue(400L);
LongPolicy newPeakBw = new LongPolicy();
newPeakBw.setValue(2000L);
VMwareDVSPortSetting newVmwareDvsPortSetting = new VMwareDVSPortSetting();
VmwareDistributedVirtualSwitchVlanIdSpec newVlanIdSpec = new VmwareDistributedVirtualSwitchVlanIdSpec();
newVlanIdSpec.setVlanId(newvlanId);
newVmwareDvsPortSetting.setVlan(newVlanIdSpec);
newTrafficShapingPolicy.setAverageBandwidth(newAvgBw);
newTrafficShapingPolicy.setBurstSize(newBurstSize);
newTrafficShapingPolicy.setPeakBandwidth(newPeakBw);
newTrafficShapingPolicy.setEnabled(newIsEnabled);
newVmwareDvsPortSetting.setInShapingPolicy(newTrafficShapingPolicy);
when(dvPortgroupConfigSpec.getNumPorts()).thenReturn(newNumPorts);
when(dvPortgroupConfigSpec.isAutoExpand()).thenReturn(newAutoExpand);
when(dvPortgroupConfigSpec.getDefaultPortConfig()).thenReturn(newVmwareDvsPortSetting);
boolean specCompareResult = HypervisorHostHelper.isSpecMatch(currentDvPortgroupInfo, dvPortgroupConfigSpec);
assertTrue(specCompareResult);
}
use of com.vmware.vim25.LongPolicy in project cloudstack by apache.
the class HypervisorHostHelperTest method testIsSpecMatchConfigSpecWithCurrentShapingPolicyDisabled.
@Test
public void testIsSpecMatchConfigSpecWithCurrentShapingPolicyDisabled() throws Exception {
int currentNumPorts = 512;
int currentvlanId = 100;
boolean currentAutoExpand = true;
DVSTrafficShapingPolicy currentTrafficShapingPolicy = new DVSTrafficShapingPolicy();
BoolPolicy currentIsEnabled = new BoolPolicy();
currentIsEnabled.setValue(false);
VMwareDVSPortSetting currentVmwareDvsPortSetting = new VMwareDVSPortSetting();
VmwareDistributedVirtualSwitchVlanIdSpec currentVlanIdSpec = new VmwareDistributedVirtualSwitchVlanIdSpec();
currentVlanIdSpec.setVlanId(currentvlanId);
currentVmwareDvsPortSetting.setVlan(currentVlanIdSpec);
currentTrafficShapingPolicy.setEnabled(currentIsEnabled);
currentVmwareDvsPortSetting.setInShapingPolicy(currentTrafficShapingPolicy);
when(currentDvPortgroupInfo.getNumPorts()).thenReturn(currentNumPorts);
when(currentDvPortgroupInfo.isAutoExpand()).thenReturn(currentAutoExpand);
when(currentDvPortgroupInfo.getDefaultPortConfig()).thenReturn(currentVmwareDvsPortSetting);
int newNumPorts = 256;
int newvlanId = 100;
boolean newAutoExpand = true;
DVSTrafficShapingPolicy newTrafficShapingPolicy = new DVSTrafficShapingPolicy();
BoolPolicy newIsEnabled = new BoolPolicy();
newIsEnabled.setValue(true);
LongPolicy newAvgBw = new LongPolicy();
newAvgBw.setValue(200L);
LongPolicy newBurstSize = new LongPolicy();
newBurstSize.setValue(400L);
LongPolicy newPeakBw = new LongPolicy();
newPeakBw.setValue(2000L);
VMwareDVSPortSetting newVmwareDvsPortSetting = new VMwareDVSPortSetting();
VmwareDistributedVirtualSwitchVlanIdSpec newVlanIdSpec = new VmwareDistributedVirtualSwitchVlanIdSpec();
newVlanIdSpec.setVlanId(newvlanId);
newVmwareDvsPortSetting.setVlan(newVlanIdSpec);
newTrafficShapingPolicy.setAverageBandwidth(newAvgBw);
newTrafficShapingPolicy.setBurstSize(newBurstSize);
newTrafficShapingPolicy.setPeakBandwidth(newPeakBw);
newTrafficShapingPolicy.setEnabled(newIsEnabled);
newVmwareDvsPortSetting.setInShapingPolicy(newTrafficShapingPolicy);
when(dvPortgroupConfigSpec.getNumPorts()).thenReturn(newNumPorts);
when(dvPortgroupConfigSpec.isAutoExpand()).thenReturn(newAutoExpand);
when(dvPortgroupConfigSpec.getDefaultPortConfig()).thenReturn(newVmwareDvsPortSetting);
boolean specCompareResult = HypervisorHostHelper.isSpecMatch(currentDvPortgroupInfo, dvPortgroupConfigSpec);
assertFalse(specCompareResult);
}
Aggregations