use of com.vmware.vim25.HostPortGroupSpec in project CloudStack-archive by CloudStack-extras.
the class HostMO method createPortGroup.
public void createPortGroup(HostVirtualSwitch vSwitch, String portGroupName, Integer vlanId, HostNetworkTrafficShapingPolicy shapingPolicy) throws Exception {
assert (portGroupName != null);
HostNetworkSystemMO hostNetMo = getHostNetworkSystemMO();
assert (hostNetMo != null);
HostPortGroupSpec spec = new HostPortGroupSpec();
spec.setName(portGroupName);
if (vlanId != null)
spec.setVlanId(vlanId.intValue());
HostNetworkPolicy policy = new HostNetworkPolicy();
policy.setShapingPolicy(shapingPolicy);
spec.setPolicy(policy);
spec.setVswitchName(vSwitch.getName());
hostNetMo.addPortGroup(spec);
}
use of com.vmware.vim25.HostPortGroupSpec in project CloudStack-archive by CloudStack-extras.
the class HostMO method getHostPortGroupSpec.
public HostPortGroupSpec getHostPortGroupSpec(String portGroupName) throws Exception {
HostNetworkInfo hostNetInfo = getHostNetworkInfo();
HostPortGroup[] portGroups = hostNetInfo.getPortgroup();
if (portGroups != null) {
for (HostPortGroup portGroup : portGroups) {
HostPortGroupSpec spec = portGroup.getSpec();
if (spec.getName().equals(portGroupName))
return spec;
}
}
return null;
}
use of com.vmware.vim25.HostPortGroupSpec in project CloudStack-archive by CloudStack-extras.
the class HypervisorHostHelper method prepareNetwork.
public static Pair<ManagedObjectReference, String> prepareNetwork(String vSwitchName, String namePrefix, HostMO hostMo, String vlanId, Integer networkRateMbps, Integer networkRateMulticastMbps, long timeOutMs, boolean syncPeerHosts) throws Exception {
HostVirtualSwitch vSwitch;
vSwitch = hostMo.getHostVirtualSwitchByName(vSwitchName);
if (vSwitch == null) {
String msg = "Unable to find vSwitch" + vSwitchName;
s_logger.error(msg);
throw new Exception(msg);
}
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, vSwitchName);
HostNetworkTrafficShapingPolicy shapingPolicy = null;
if (networkRateMbps != null && networkRateMbps.intValue() > 0) {
shapingPolicy = new HostNetworkTrafficShapingPolicy();
shapingPolicy.setEnabled(true);
shapingPolicy.setAverageBandwidth((long) networkRateMbps.intValue() * 1024L * 1024L);
//
// TODO : people may have different opinion on how to set the following
//
// give 50% premium to peek
shapingPolicy.setPeakBandwidth((long) (shapingPolicy.getAverageBandwidth() * 1.5));
// allow 5 seconds of burst transfer
shapingPolicy.setBurstSize(5 * shapingPolicy.getAverageBandwidth() / 8);
}
boolean bWaitPortGroupReady = false;
if (!hostMo.hasPortGroup(vSwitch, networkName)) {
hostMo.createPortGroup(vSwitch, networkName, vid, shapingPolicy);
bWaitPortGroupReady = true;
} else {
HostPortGroupSpec spec = hostMo.getPortGroupSpec(networkName);
if (!isSpecMatch(spec, vid, shapingPolicy)) {
hostMo.updatePortGroup(vSwitch, networkName, vid, shapingPolicy);
bWaitPortGroupReady = true;
}
}
ManagedObjectReference morNetwork;
if (bWaitPortGroupReady)
morNetwork = waitForNetworkReady(hostMo, networkName, timeOutMs);
else
morNetwork = hostMo.getNetworkMor(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, "true");
}
if (syncPeerHosts) {
ManagedObjectReference morParent = hostMo.getParentMor();
if (morParent != null && morParent.getType().equals("ClusterComputeResource")) {
// to be conservative, lock cluster
GlobalLock lock = GlobalLock.getInternLock("ClusterLock." + morParent.get_value());
try {
if (lock.lock(DEFAULT_LOCK_TIMEOUT_SECONDS)) {
try {
ManagedObjectReference[] hosts = (ManagedObjectReference[]) hostMo.getContext().getServiceUtil().getDynamicProperty(morParent, "host");
if (hosts != null) {
for (ManagedObjectReference otherHost : hosts) {
if (!otherHost.get_value().equals(hostMo.getMor().get_value())) {
HostMO otherHostMo = new HostMO(hostMo.getContext(), otherHost);
try {
if (s_logger.isDebugEnabled())
s_logger.debug("Prepare network on other host, vlan: " + vlanId + ", host: " + otherHostMo.getHostName());
prepareNetwork(vSwitchName, namePrefix, otherHostMo, vlanId, networkRateMbps, networkRateMulticastMbps, timeOutMs, false);
} catch (Exception e) {
s_logger.warn("Unable to prepare network on other host, vlan: " + vlanId + ", host: " + otherHostMo.getHostName());
}
}
}
}
} finally {
lock.unlock();
}
} else {
s_logger.warn("Unable to lock cluster to prepare guest network, vlan: " + vlanId);
}
} finally {
lock.releaseRef();
}
}
}
s_logger.info("Network " + networkName + " is ready on vSwitch " + vSwitchName);
return new Pair<ManagedObjectReference, String>(morNetwork, networkName);
}
use of com.vmware.vim25.HostPortGroupSpec in project cloudstack by apache.
the class HostMO method updatePortGroup.
public void updatePortGroup(HostVirtualSwitch vSwitch, String portGroupName, Integer vlanId, HostNetworkSecurityPolicy secPolicy, HostNetworkTrafficShapingPolicy shapingPolicy) throws Exception {
assert (portGroupName != null);
HostNetworkSystemMO hostNetMo = getHostNetworkSystemMO();
assert (hostNetMo != null);
HostPortGroupSpec spec = new HostPortGroupSpec();
spec.setName(portGroupName);
if (vlanId != null)
spec.setVlanId(vlanId.intValue());
HostNetworkPolicy policy = new HostNetworkPolicy();
if (secPolicy != null)
policy.setSecurity(secPolicy);
policy.setShapingPolicy(shapingPolicy);
spec.setPolicy(policy);
spec.setVswitchName(vSwitch.getName());
hostNetMo.updatePortGroup(portGroupName, spec);
}
use of com.vmware.vim25.HostPortGroupSpec in project cloudstack by apache.
the class HostMO method getHostPortGroupSpec.
public HostPortGroupSpec getHostPortGroupSpec(String portGroupName) throws Exception {
HostNetworkInfo hostNetInfo = getHostNetworkInfo();
List<HostPortGroup> portGroups = hostNetInfo.getPortgroup();
if (portGroups != null) {
for (HostPortGroup portGroup : portGroups) {
HostPortGroupSpec spec = portGroup.getSpec();
if (spec.getName().equals(portGroupName))
return spec;
}
}
return null;
}
Aggregations