CLOUDSTACK-5884 make getTargetSwitch(NicTO nicTo) do all the work to select switch name, type and vlan token. Change preference to use the tags set on the physical network.

Conflicts:
	plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
This commit is contained in:
Hugo Trippaers 2014-01-20 18:03:02 +01:00
parent 569b558b92
commit ac65f8fddf
2 changed files with 58 additions and 49 deletions

View File

@ -170,6 +170,7 @@ import com.cloud.agent.api.to.VolumeTO;
import com.cloud.configuration.Config; import com.cloud.configuration.Config;
import com.cloud.dc.DataCenter.NetworkType; import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.dc.Vlan; import com.cloud.dc.Vlan;
import com.cloud.exception.CloudException;
import com.cloud.exception.InternalErrorException; import com.cloud.exception.InternalErrorException;
import com.cloud.host.Host.Type; import com.cloud.host.Host.Type;
import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.hypervisor.Hypervisor.HypervisorType;
@ -222,6 +223,7 @@ import com.cloud.utils.DateUtil;
import com.cloud.utils.NumbersUtil; import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair; import com.cloud.utils.Pair;
import com.cloud.utils.StringUtils; import com.cloud.utils.StringUtils;
import com.cloud.utils.Ternary;
import com.cloud.utils.db.DB; import com.cloud.utils.db.DB;
import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.exception.ExceptionUtil; import com.cloud.utils.exception.ExceptionUtil;
@ -3635,24 +3637,13 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
return defaultVlan; return defaultVlan;
} }
private Pair<ManagedObjectReference, String> prepareNetworkFromNicInfo(HostMO hostMo, NicTO nicTo, boolean configureVServiceInNexus, VirtualMachine.Type vmType) private Pair<ManagedObjectReference, String> prepareNetworkFromNicInfo(HostMO hostMo, NicTO nicTo, boolean configureVServiceInNexus, VirtualMachine.Type vmType) throws Exception {
throws Exception {
Pair<String, String> switchName;
TrafficType trafficType;
VirtualSwitchType switchType;
switchName = getTargetSwitch(nicTo); Ternary<String, String, String> switchDetails = getTargetSwitch(nicTo);
trafficType = nicTo.getType(); nicTo.getType();
// Get switch type from resource property which is dictated by cluster property VirtualSwitchType switchType = VirtualSwitchType.getType(switchDetails.second());
// If a virtual switch type is specified while adding cluster that will be used. String switchName = switchDetails.first();
// Else If virtual switch type is specified in physical traffic label that will be used String vlanToken = switchDetails.third();
// Else use standard vSwitch
switchType = VirtualSwitchType.StandardVirtualSwitch;
if (trafficType == TrafficType.Guest && _guestTrafficInfo != null) {
switchType = _guestTrafficInfo.getVirtualSwitchType();
} else if (trafficType == TrafficType.Public && _publicTrafficInfo != null) {
switchType = _publicTrafficInfo.getVirtualSwitchType();
}
String namePrefix = getNetworkNamePrefix(nicTo); String namePrefix = getNetworkNamePrefix(nicTo);
Pair<ManagedObjectReference, String> networkInfo = null; Pair<ManagedObjectReference, String> networkInfo = null;
@ -3660,13 +3651,14 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
s_logger.info("Prepare network on " + switchType + " " + switchName + " with name prefix: " + namePrefix); s_logger.info("Prepare network on " + switchType + " " + switchName + " with name prefix: " + namePrefix);
if (VirtualSwitchType.StandardVirtualSwitch == switchType) { if (VirtualSwitchType.StandardVirtualSwitch == switchType) {
synchronized (hostMo.getMor().getValue().intern()) { synchronized(hostMo.getMor().getValue().intern()) {
networkInfo = networkInfo = HypervisorHostHelper.prepareNetwork(switchName, namePrefix, hostMo, getVlanInfo(nicTo, vlanToken), nicTo.getNetworkRateMbps(),
HypervisorHostHelper.prepareNetwork(switchName.first(), namePrefix, hostMo, getVlanInfo(nicTo, switchName.second()), nicTo.getNetworkRateMbps(), nicTo.getNetworkRateMulticastMbps(), _ops_timeout,
nicTo.getNetworkRateMulticastMbps(), _opsTimeout, !namePrefix.startsWith("cloud.private"), nicTo.getBroadcastType(), nicTo.getUuid()); !namePrefix.startsWith("cloud.private"), nicTo.getBroadcastType(), nicTo.getUuid());
} }
} else { }
String vlanId = getVlanInfo(nicTo, switchName.second()); else {
String vlanId = getVlanInfo(nicTo, vlanToken);
String svlanId = null; String svlanId = null;
boolean pvlannetwork = (getPvlanInfo(nicTo) == null) ? false : true; boolean pvlannetwork = (getPvlanInfo(nicTo) == null) ? false : true;
if (vmType != null && vmType.equals(VirtualMachine.Type.DomainRouter) && pvlannetwork) { if (vmType != null && vmType.equals(VirtualMachine.Type.DomainRouter) && pvlannetwork) {
@ -3676,48 +3668,65 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
// plumb this network to the isolated vlan. // plumb this network to the isolated vlan.
svlanId = getPvlanInfo(nicTo); svlanId = getPvlanInfo(nicTo);
} }
networkInfo = networkInfo = HypervisorHostHelper.prepareNetwork(switchName, namePrefix, hostMo, vlanId, svlanId,
HypervisorHostHelper.prepareNetwork(switchName.first(), namePrefix, hostMo, vlanId, svlanId, nicTo.getNetworkRateMbps(), nicTo.getNetworkRateMbps(), nicTo.getNetworkRateMulticastMbps(), _ops_timeout, switchType,
nicTo.getNetworkRateMulticastMbps(), _opsTimeout, switchType, _portsPerDvPortGroup, nicTo.getGateway(), configureVServiceInNexus, _portsPerDvPortGroup, nicTo.getGateway(), configureVServiceInNexus, nicTo.getBroadcastType());
nicTo.getBroadcastType());
} }
return networkInfo; return networkInfo;
} }
// return Pair<switch name, vlan tagging> // return Ternary <switch name, switch tyep, vlan tagging>
private Pair<String, String> getTargetSwitch(NicTO nicTo) throws Exception { private Ternary<String, String, String> getTargetSwitch(NicTO nicTo) throws CloudException {
if (nicTo.getType() == Networks.TrafficType.Guest) { TrafficType[] supportedTrafficTypes =
return new Pair<String, String>(_guestTrafficInfo.getVirtualSwitchName(), Vlan.UNTAGGED); new TrafficType[] {
} else if (nicTo.getType() == Networks.TrafficType.Public) { TrafficType.Guest,
return new Pair<String, String>(_publicTrafficInfo.getVirtualSwitchName(), Vlan.UNTAGGED); TrafficType.Public,
TrafficType.Control,
TrafficType.Management,
TrafficType.Storage
};
TrafficType trafficType = nicTo.getType();
if (!Arrays.asList(supportedTrafficTypes).contains(trafficType)) {
throw new CloudException("Traffic type " + trafficType.toString() + " for nic " + nicTo.toString() + " is not supported.");
} }
if (nicTo.getName() != null && !nicTo.getName().isEmpty()) { String switchName = null;
VirtualSwitchType switchType = VirtualSwitchType.StandardVirtualSwitch;
String vlanToken = Vlan.UNTAGGED;
// Get switch details from the nicTO object
if(nicTo.getName() != null && !nicTo.getName().isEmpty()) {
String[] tokens = nicTo.getName().split(","); String[] tokens = nicTo.getName().split(",");
// Format of network traffic label is <VSWITCH>,<VLANID>,<VSWITCHTYPE> // Format of network traffic label is <VSWITCH>,<VLANID>,<VSWITCHTYPE>
// If all 3 fields are mentioned then number of tokens would be 3. // If all 3 fields are mentioned then number of tokens would be 3.
// If only <VSWITCH>,<VLANID> are mentioned then number of tokens would be 2. // If only <VSWITCH>,<VLANID> are mentioned then number of tokens would be 2.
if (tokens.length == 2 || tokens.length == 3) { switchName = tokens[0];
String vlanToken = tokens[1]; if(tokens.length == 2 || tokens.length == 3) {
vlanToken = tokens[1];
if (vlanToken.isEmpty()) { if (vlanToken.isEmpty()) {
vlanToken = Vlan.UNTAGGED; vlanToken = Vlan.UNTAGGED;
} }
return new Pair<String, String>(tokens[0], vlanToken); if (tokens.length == 3) {
} else { switchType = VirtualSwitchType.getType(tokens[2]);
return new Pair<String, String>(nicTo.getName(), Vlan.UNTAGGED); }
}
} else {
if (trafficType == TrafficType.Guest && _guestTrafficInfo != null) {
switchType = _guestTrafficInfo.getVirtualSwitchType();
switchName = _guestTrafficInfo.getVirtualSwitchName();
} else if (trafficType == TrafficType.Public && _publicTrafficInfo != null) {
switchType = _publicTrafficInfo.getVirtualSwitchType();
switchName = _publicTrafficInfo.getVirtualSwitchName();
} }
} }
if (nicTo.getType() == Networks.TrafficType.Control || nicTo.getType() == Networks.TrafficType.Management) { if (nicTo.getType() == Networks.TrafficType.Control || nicTo.getType() == Networks.TrafficType.Management || nicTo.getType() == Networks.TrafficType.Storage) {
return new Pair<String, String>(_privateNetworkVSwitchName, Vlan.UNTAGGED); switchName = _privateNetworkVSwitchName;
} else if (nicTo.getType() == Networks.TrafficType.Storage) {
return new Pair<String, String>(_privateNetworkVSwitchName, Vlan.UNTAGGED);
} 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());
} }
return new Ternary<String,String,String>(switchName, switchType.toString(), vlanToken);
} }
private String getNetworkNamePrefix(NicTO nicTo) throws Exception { private String getNetworkNamePrefix(NicTO nicTo) throws Exception {

View File

@ -504,11 +504,11 @@ public class HypervisorHostHelper {
} }
morDvSwitch = dataCenterMo.getDvSwitchMor(dvSwitchName); morDvSwitch = dataCenterMo.getDvSwitchMor(dvSwitchName);
if (morDvSwitch == null) { if (morDvSwitch == null) {
String msg = "Unable to find distributed vSwitch " + morDvSwitch; String msg = "Unable to find distributed vSwitch " + dvSwitchName;
s_logger.error(msg); s_logger.error(msg);
throw new Exception(msg); throw new Exception(msg);
} else { } else {
s_logger.info("Found distributed vSwitch " + morDvSwitch); s_logger.debug("Found distributed vSwitch " + dvSwitchName);
} }
if (broadcastDomainType == BroadcastDomainType.Lswitch) { if (broadcastDomainType == BroadcastDomainType.Lswitch) {