mirror of https://github.com/apache/cloudstack.git
Add storage network support at VMware resource
This commit is contained in:
parent
b1f2dfa52d
commit
6b8ff93330
|
|
@ -791,7 +791,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
|
||||
private void plugPublicNic(VirtualMachineMO vmMo, final String vlanId, final String vifMacAddress) throws Exception {
|
||||
// TODO : probably need to set traffic shaping
|
||||
Pair<ManagedObjectReference, String> networkInfo = HypervisorHostHelper.preparePublicNetwork(this._publicNetworkVSwitchName,
|
||||
Pair<ManagedObjectReference, String> networkInfo = HypervisorHostHelper.prepareNetwork(this._publicNetworkVSwitchName, "cloud.public",
|
||||
vmMo.getRunningHost(), vlanId, null, null, this._ops_timeout, true);
|
||||
|
||||
int nicIndex = allocPublicNicIndex(vmMo);
|
||||
|
|
@ -1613,20 +1613,50 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
return Vlan.UNTAGGED;
|
||||
}
|
||||
|
||||
private Pair<ManagedObjectReference, String> prepareNetworkFromNicInfo(HostMO hostMo, NicTO nicTo) throws Exception {
|
||||
if (nicTo.getType() == Networks.TrafficType.Guest) {
|
||||
return prepareGuestNetwork(hostMo, getVlanInfo(nicTo), nicTo.getNetworkRateMbps(), nicTo.getNetworkRateMulticastMbps());
|
||||
} else if (nicTo.getType() == Networks.TrafficType.Control || nicTo.getType() == Networks.TrafficType.Management) {
|
||||
return preparePrivateNetwork(hostMo);
|
||||
} else if (nicTo.getType() == Networks.TrafficType.Public) {
|
||||
return preparePublicNetwork(hostMo, getVlanInfo(nicTo), nicTo.getNetworkRateMbps(), nicTo.getNetworkRateMulticastMbps());
|
||||
} else if (nicTo.getType() == Networks.TrafficType.Storage) {
|
||||
throw new Exception("Unsupported traffic type: " + nicTo.getType().toString());
|
||||
} else if (nicTo.getType() == Networks.TrafficType.Vpn) {
|
||||
throw new Exception("Unsupported traffic type: " + nicTo.getType().toString());
|
||||
} else {
|
||||
throw new Exception("Unsupported traffic type: " + nicTo.getType().toString());
|
||||
}
|
||||
private Pair<ManagedObjectReference, String> prepareNetworkFromNicInfo(HostMO hostMo, NicTO nicTo) throws Exception {
|
||||
|
||||
String switchName = getTargetSwitch(nicTo);
|
||||
String namePrefix = getNetworkNamePrefix(nicTo);
|
||||
|
||||
s_logger.info("Prepare network on vSwitch: " + switchName + " with name prefix: " + namePrefix);
|
||||
return HypervisorHostHelper.prepareNetwork(switchName, namePrefix, hostMo, getVlanInfo(nicTo),
|
||||
nicTo.getNetworkRateMbps(), nicTo.getNetworkRateMulticastMbps(), _ops_timeout,
|
||||
!namePrefix.startsWith("cloud.private"));
|
||||
}
|
||||
|
||||
private String getTargetSwitch(NicTO nicTo) throws Exception {
|
||||
if(nicTo.getName() != null && !nicTo.getName().isEmpty())
|
||||
return nicTo.getName();
|
||||
|
||||
if (nicTo.getType() == Networks.TrafficType.Guest) {
|
||||
return this._guestNetworkVSwitchName;
|
||||
} else if (nicTo.getType() == Networks.TrafficType.Control || nicTo.getType() == Networks.TrafficType.Management) {
|
||||
return this._privateNetworkVSwitchName;
|
||||
} else if (nicTo.getType() == Networks.TrafficType.Public) {
|
||||
return this._publicNetworkVSwitchName;
|
||||
} else if (nicTo.getType() == Networks.TrafficType.Storage) {
|
||||
return this._privateNetworkVSwitchName;
|
||||
} else if (nicTo.getType() == Networks.TrafficType.Vpn) {
|
||||
throw new Exception("Unsupported traffic type: " + nicTo.getType().toString());
|
||||
} else {
|
||||
throw new Exception("Unsupported traffic type: " + nicTo.getType().toString());
|
||||
}
|
||||
}
|
||||
|
||||
private String getNetworkNamePrefix(NicTO nicTo) throws Exception {
|
||||
if (nicTo.getType() == Networks.TrafficType.Guest) {
|
||||
return "cloud.guest";
|
||||
} else if (nicTo.getType() == Networks.TrafficType.Control || nicTo.getType() == Networks.TrafficType.Management) {
|
||||
return "cloud.private";
|
||||
} else if (nicTo.getType() == Networks.TrafficType.Public) {
|
||||
return "cloud.public";
|
||||
} else if (nicTo.getType() == Networks.TrafficType.Storage) {
|
||||
return "cloud.storage";
|
||||
} else if (nicTo.getType() == Networks.TrafficType.Vpn) {
|
||||
throw new Exception("Unsupported traffic type: " + nicTo.getType().toString());
|
||||
} else {
|
||||
throw new Exception("Unsupported traffic type: " + nicTo.getType().toString());
|
||||
}
|
||||
}
|
||||
|
||||
protected synchronized Answer execute(final RemoteAccessVpnCfgCommand cmd) {
|
||||
|
|
@ -1724,7 +1754,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
prepareNetworkForVmTargetHost(new HostMO(hyperHost.getContext(), morTargetPhysicalHost), vmMo);
|
||||
if (!vmMo.relocate(morTargetPhysicalHost)) {
|
||||
String msg = "VM " + vmName + " is on other host and we failed to relocate it here";
|
||||
s_logger.error(msg);
|
||||
|
|
@ -2140,7 +2169,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
throw new Exception("Unable to find a target capable physical host");
|
||||
}
|
||||
|
||||
prepareNetworkForVmTargetHost(new HostMO(hyperHost.getContext(), morTargetPhysicalHost), vmMo);
|
||||
if (!vmMo.migrate(destHyperHost.getHyperHostOwnerResourcePool(), morTargetPhysicalHost)) {
|
||||
throw new Exception("Migration failed");
|
||||
}
|
||||
|
|
@ -3465,74 +3493,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
return VirtualMachineGuestOsIdentifier.otherGuest;
|
||||
}
|
||||
|
||||
private synchronized Pair<ManagedObjectReference, String> prepareGuestNetwork(HostMO hostMo, String vlanId, Integer networkRateMbps, Integer networkRateMulticastMbps)
|
||||
throws Exception {
|
||||
|
||||
return HypervisorHostHelper.prepareGuestNetwork(_guestNetworkVSwitchName, hostMo, vlanId, networkRateMbps, networkRateMulticastMbps,
|
||||
_ops_timeout, true);
|
||||
}
|
||||
|
||||
private synchronized Pair<ManagedObjectReference, String> preparePrivateNetwork(HostMO hostMo) throws Exception {
|
||||
String managementPortGroupName = hostMo.getPortGroupNameByNicType(HostVirtualNicType.management);
|
||||
assert(managementPortGroupName != null);
|
||||
HostPortGroupSpec spec = hostMo.getPortGroupSpec(managementPortGroupName);
|
||||
Integer vlanId = null;
|
||||
if(spec.getVlanId() != 0) {
|
||||
vlanId = spec.getVlanId();
|
||||
}
|
||||
|
||||
return HypervisorHostHelper.preparePrivateNetwork(_privateNetworkVSwitchName, hostMo, vlanId, _ops_timeout);
|
||||
}
|
||||
|
||||
private synchronized Pair<ManagedObjectReference, String> preparePublicNetwork(HostMO hostMo, String vlanId, Integer networkRateMbps, Integer networkRateMulticastMbps) throws Exception {
|
||||
|
||||
return HypervisorHostHelper.preparePublicNetwork(_publicNetworkVSwitchName, hostMo, vlanId, networkRateMbps, networkRateMulticastMbps, _ops_timeout, true);
|
||||
}
|
||||
|
||||
private void prepareNetworkForVmTargetHost(HostMO hostMo, VirtualMachineMO vmMo) throws Exception {
|
||||
assert (vmMo != null);
|
||||
assert (hostMo != null);
|
||||
|
||||
String[] networks = vmMo.getNetworks();
|
||||
for (String networkName : networks) {
|
||||
HostPortGroupSpec portGroupSpec = hostMo.getHostPortGroupSpec(networkName);
|
||||
HostNetworkTrafficShapingPolicy shapingPolicy = null;
|
||||
if (portGroupSpec != null) {
|
||||
shapingPolicy = portGroupSpec.getPolicy().getShapingPolicy();
|
||||
}
|
||||
|
||||
if (networkName.startsWith("cloud.private")) {
|
||||
preparePrivateNetwork(hostMo);
|
||||
} else if (networkName.startsWith("cloud.public")) {
|
||||
String[] tokens = networkName.split("\\.");
|
||||
if (tokens.length == 3) {
|
||||
Integer networkRateMbps = null;
|
||||
if (shapingPolicy != null && shapingPolicy.getEnabled() != null && shapingPolicy.getEnabled().booleanValue()) {
|
||||
networkRateMbps = (int) (shapingPolicy.getPeakBandwidth().longValue() / (1024 * 1024));
|
||||
}
|
||||
|
||||
preparePublicNetwork(hostMo, tokens[2], networkRateMbps, null);
|
||||
} else {
|
||||
s_logger.info("Skip suspecious cloud network " + networkName);
|
||||
}
|
||||
} else if (networkName.startsWith("cloud.guest")) {
|
||||
String[] tokens = networkName.split("\\.");
|
||||
if (tokens.length >= 3) {
|
||||
Integer networkRateMbps = null;
|
||||
if (shapingPolicy != null && shapingPolicy.getEnabled() != null && shapingPolicy.getEnabled().booleanValue()) {
|
||||
networkRateMbps = (int) (shapingPolicy.getPeakBandwidth().longValue() / (1024 * 1024));
|
||||
}
|
||||
|
||||
prepareGuestNetwork(hostMo, tokens[2], networkRateMbps, null);
|
||||
} else {
|
||||
s_logger.info("Skip suspecious cloud network " + networkName);
|
||||
}
|
||||
} else {
|
||||
s_logger.info("Skip non-cloud network " + networkName + " when preparing target host");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private HashMap<String, State> getVmStates() throws Exception {
|
||||
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
|
||||
ObjectContent[] ocs = hyperHost.getVmPropertiesOnHyperHost(new String[] { "name", "runtime.powerState", "config.template" });
|
||||
|
|
|
|||
|
|
@ -320,15 +320,15 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
|||
}
|
||||
|
||||
// prepare at least one network on the vswitch to enable OVF importing
|
||||
String managementPortGroupName = hostMo.getPortGroupNameByNicType(HostVirtualNicType.management);
|
||||
String managementPortGroupName = getManagementPortGroupByHost(hostMo);
|
||||
assert(managementPortGroupName != null);
|
||||
HostPortGroupSpec spec = hostMo.getPortGroupSpec(managementPortGroupName);
|
||||
Integer vlanId = null;
|
||||
String vlanId = null;
|
||||
if(spec.getVlanId() != 0) {
|
||||
vlanId = spec.getVlanId();
|
||||
vlanId = String.valueOf(spec.getVlanId());
|
||||
}
|
||||
|
||||
HypervisorHostHelper.preparePrivateNetwork(_privateNetworkVSwitchName, hostMo, vlanId, 180000);
|
||||
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000, false);
|
||||
returnedHostList.add(hosts[0]);
|
||||
return returnedHostList;
|
||||
} else if(mor.getType().equals("ClusterComputeResource")) {
|
||||
|
|
@ -352,16 +352,16 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
|||
}
|
||||
}
|
||||
|
||||
String managementPortGroupName = hostMo.getPortGroupNameByNicType(HostVirtualNicType.management);
|
||||
String managementPortGroupName = getManagementPortGroupByHost(hostMo);
|
||||
assert(managementPortGroupName != null);
|
||||
HostPortGroupSpec spec = hostMo.getPortGroupSpec(managementPortGroupName);
|
||||
Integer vlanId = null;
|
||||
String vlanId = null;
|
||||
if(spec.getVlanId() != 0) {
|
||||
vlanId = spec.getVlanId();
|
||||
vlanId = String.valueOf(spec.getVlanId());
|
||||
}
|
||||
|
||||
// prepare at least one network on the vswitch to enable OVF importing
|
||||
HypervisorHostHelper.preparePrivateNetwork(_privateNetworkVSwitchName, hostMo, vlanId, 180000);
|
||||
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000, false);
|
||||
returnedHostList.add(morHost);
|
||||
}
|
||||
return returnedHostList;
|
||||
|
|
@ -376,16 +376,16 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
|||
}
|
||||
}
|
||||
|
||||
String managementPortGroupName = hostMo.getPortGroupNameByNicType(HostVirtualNicType.management);
|
||||
String managementPortGroupName = getManagementPortGroupByHost(hostMo);
|
||||
assert(managementPortGroupName != null);
|
||||
HostPortGroupSpec spec = hostMo.getPortGroupSpec(managementPortGroupName);
|
||||
Integer vlanId = null;
|
||||
String vlanId = null;
|
||||
if(spec.getVlanId() != 0) {
|
||||
vlanId = spec.getVlanId();
|
||||
vlanId = String.valueOf(spec.getVlanId());
|
||||
}
|
||||
|
||||
// prepare at least one network on the vswitch to enable OVF importing
|
||||
HypervisorHostHelper.preparePrivateNetwork(_privateNetworkVSwitchName, hostMo, vlanId, 180000);
|
||||
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000, false);
|
||||
returnedHostList.add(mor);
|
||||
return returnedHostList;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ public class PhysicalNetworkTrafficTypeDaoImpl extends GenericDaoBase<PhysicalNe
|
|||
vmWareAllFieldsSearch = createSearchBuilder(String.class);
|
||||
vmWareAllFieldsSearch.and("physicalNetworkId", vmWareAllFieldsSearch.entity().getPhysicalNetworkId(), Op.EQ);
|
||||
vmWareAllFieldsSearch.and("trafficType", vmWareAllFieldsSearch.entity().getTrafficType(), Op.EQ);
|
||||
vmWareAllFieldsSearch.selectField(vmWareAllFieldsSearch.entity().getKvmNetworkLabel());
|
||||
vmWareAllFieldsSearch.selectField(vmWareAllFieldsSearch.entity().getVmwareNetworkLabel());
|
||||
vmWareAllFieldsSearch.done();
|
||||
|
||||
simulatorAllFieldsSearch = createSearchBuilder(String.class);
|
||||
|
|
|
|||
|
|
@ -71,149 +71,16 @@ public class HypervisorHostHelper {
|
|||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getPublicNetworkNamePrefix(String vlanId) {
|
||||
if (UNTAGGED_VLAN_NAME.equalsIgnoreCase(vlanId)) {
|
||||
return "cloud.public.untagged";
|
||||
} else {
|
||||
return "cloud.public." + vlanId;
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized Pair<ManagedObjectReference, String> preparePublicNetwork(String vSwitchName,
|
||||
HostMO hostMo, String vlanId, Integer networkRateMbps, Integer networkRateMulticastMbps, long timeOutMs, boolean syncPeerHosts) throws Exception {
|
||||
|
||||
HostVirtualSwitch vSwitch = hostMo.getHostVirtualSwitchByName(vSwitchName);
|
||||
if (vSwitch == null) {
|
||||
String msg = "Unable to find vSwitch configured for public network";
|
||||
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("cloud.public", 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 public network on vSwitch " + vSwitchName;
|
||||
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 public network on other host, vlan: " + vlanId + ", host: " + otherHostMo.getHostName());
|
||||
preparePublicNetwork(vSwitchName, otherHostMo, vlanId, networkRateMbps, networkRateMulticastMbps, timeOutMs, false);
|
||||
} catch(Exception e) {
|
||||
s_logger.warn("Unable to prepare public network on other host, vlan: " + vlanId + ", host: " + otherHostMo.getHostName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
} else {
|
||||
s_logger.warn("Unable to lock cluster to prepare public network, vlan: " + vlanId);
|
||||
}
|
||||
} finally {
|
||||
lock.releaseRef();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s_logger.info("Network " + networkName + " is ready on vSwitch " + vSwitchName);
|
||||
return new Pair<ManagedObjectReference, String>(morNetwork, networkName);
|
||||
}
|
||||
|
||||
public static Pair<ManagedObjectReference, String> preparePrivateNetwork(String vSwitchName,
|
||||
HostMO hostMo, Integer vlanId, long timeOutMs) throws Exception {
|
||||
|
||||
HostVirtualSwitch vSwitch = hostMo.getHostVirtualSwitchByName(vSwitchName);
|
||||
if (vSwitch == null) {
|
||||
String msg = "Unable to find vSwitch configured for private network";
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
String networkName;
|
||||
networkName = composeCloudNetworkName("cloud.private", vlanId == null ? null : String.valueOf(vlanId), null, vSwitchName);
|
||||
|
||||
if (!hostMo.hasPortGroup(vSwitch, networkName)) {
|
||||
hostMo.createPortGroup(vSwitch, networkName, vlanId, null);
|
||||
}
|
||||
|
||||
ManagedObjectReference morNetwork = waitForNetworkReady(hostMo, networkName, timeOutMs);
|
||||
if (morNetwork == null) {
|
||||
String msg = "Failed to create private network";
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
s_logger.info("Network " + networkName + " is ready on vSwitch " + vSwitchName);
|
||||
return new Pair<ManagedObjectReference, String>(morNetwork, networkName);
|
||||
public static String getPublicNetworkNamePrefix(String vlanId) {
|
||||
if (UNTAGGED_VLAN_NAME.equalsIgnoreCase(vlanId)) {
|
||||
return "cloud.public.untagged";
|
||||
} else {
|
||||
return "cloud.public." + vlanId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String composeCloudNetworkName(String prefix, String vlanId, Integer networkRateMbps, String vSwitchName) {
|
||||
StringBuffer sb = new StringBuffer(prefix);
|
||||
if(vlanId == null || UNTAGGED_VLAN_NAME.equalsIgnoreCase(vlanId))
|
||||
|
|
@ -230,114 +97,114 @@ public class HypervisorHostHelper {
|
|||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static Pair<ManagedObjectReference, String> prepareGuestNetwork(String vSwitchName,
|
||||
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 the default virtual switch";
|
||||
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("cloud.guest", 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;
|
||||
}
|
||||
}
|
||||
|
||||
public static Pair<ManagedObjectReference, String> prepareNetwork(String vSwitchName, String namePrefix,
|
||||
HostMO hostMo, String vlanId, Integer networkRateMbps, Integer networkRateMulticastMbps,
|
||||
long timeOutMs, boolean syncPeerHosts) throws Exception {
|
||||
|
||||
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 guest network on other host, vlan: " + vlanId + ", host: " + otherHostMo.getHostName());
|
||||
prepareGuestNetwork(vSwitchName, otherHostMo, vlanId, networkRateMbps, networkRateMulticastMbps, timeOutMs, false);
|
||||
} catch(Exception e) {
|
||||
s_logger.warn("Unable to prepare guest 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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
private static boolean isSpecMatch(HostPortGroupSpec spec, Integer vlanId, HostNetworkTrafficShapingPolicy shapingPolicy) {
|
||||
// check VLAN configuration
|
||||
|
|
|
|||
Loading…
Reference in New Issue