use of com.cloud.network.Networks.TrafficType in project cloudstack by apache.
the class SecondaryStorageManagerImpl method getDefaultNetworkForBasicZone.
/**
* Get default network for secondary storage VM for starting up in a basic zone. Basic zones select
* the Guest network whether or not the zone is SG-enabled.
* @param dc - The zone.
* @return The default network according to the zone's network selection rules.
* @throws CloudRuntimeException - If the zone is not a valid choice or a network couldn't be found.
*/
protected NetworkVO getDefaultNetworkForBasicZone(DataCenter dc) {
if (dc.getNetworkType() != NetworkType.Basic) {
throw new CloudRuntimeException("Zone " + dc + "is not basic.");
}
TrafficType defaultTrafficType = TrafficType.Guest;
List<NetworkVO> defaultNetworks = _networkDao.listByZoneAndTrafficType(dc.getId(), defaultTrafficType);
// api should never allow this situation to happen
if (defaultNetworks.size() != 1) {
throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type " + defaultTrafficType + " when expect to find 1");
}
return defaultNetworks.get(0);
}
use of com.cloud.network.Networks.TrafficType in project cloudstack by apache.
the class LibvirtVifDriverTest method testOverrideSomeTrafficTypes.
@Test
public void testOverrideSomeTrafficTypes() throws ConfigurationException {
Map<String, Object> params = new HashMap<String, Object>();
params.put(LibVirtVifDriver + "." + "Public", FakeVifDriverClassName);
params.put(LibVirtVifDriver + "." + "Guest", LibvirtComputingResource.DEFAULT_OVS_VIF_DRIVER_CLASS_NAME);
res._bridgeType = BridgeType.NATIVE;
configure(params);
// Initially, set all traffic types to use default
for (TrafficType trafficType : TrafficType.values()) {
assertions.put(trafficType, bridgeVifDriver);
}
assertions.put(TrafficType.Public, fakeVifDriver);
assertions.put(TrafficType.Guest, ovsVifDriver);
checkAssertions();
}
use of com.cloud.network.Networks.TrafficType in project cloudstack by apache.
the class LibvirtVifDriverTest method testEmptyTrafficType.
@Test
public void testEmptyTrafficType() throws ConfigurationException {
Map<String, Object> params = new HashMap<String, Object>();
params.put(LibVirtVifDriver + ".", FakeVifDriverClassName);
res._bridgeType = BridgeType.NATIVE;
configure(params);
// Set all traffic types to use default, because bad traffic type should be ignored
for (TrafficType trafficType : TrafficType.values()) {
assertions.put(trafficType, bridgeVifDriver);
}
checkAssertions();
}
use of com.cloud.network.Networks.TrafficType in project cloudstack by apache.
the class LibvirtComputingResource method configureVifDrivers.
protected void configureVifDrivers(final Map<String, Object> params) throws ConfigurationException {
final String LIBVIRT_VIF_DRIVER = "libvirt.vif.driver";
_trafficTypeVifDrivers = new HashMap<TrafficType, VifDriver>();
// Load the default vif driver
String defaultVifDriverName = (String) params.get(LIBVIRT_VIF_DRIVER);
if (defaultVifDriverName == null) {
if (_bridgeType == BridgeType.OPENVSWITCH) {
s_logger.info("No libvirt.vif.driver specified. Defaults to OvsVifDriver.");
defaultVifDriverName = DEFAULT_OVS_VIF_DRIVER_CLASS_NAME;
} else {
s_logger.info("No libvirt.vif.driver specified. Defaults to BridgeVifDriver.");
defaultVifDriverName = DEFAULT_BRIDGE_VIF_DRIVER_CLASS_NAME;
}
}
_defaultVifDriver = getVifDriverClass(defaultVifDriverName, params);
// Load any per-traffic-type vif drivers
for (final Map.Entry<String, Object> entry : params.entrySet()) {
final String k = entry.getKey();
final String vifDriverPrefix = LIBVIRT_VIF_DRIVER + ".";
if (k.startsWith(vifDriverPrefix)) {
// Get trafficType
final String trafficTypeSuffix = k.substring(vifDriverPrefix.length());
// Does this suffix match a real traffic type?
final TrafficType trafficType = TrafficType.getTrafficType(trafficTypeSuffix);
if (!trafficType.equals(TrafficType.None)) {
// Get vif driver class name
final String vifDriverClassName = (String) entry.getValue();
// if value is null, ignore
if (vifDriverClassName != null) {
// add traffic type to vif driver mapping to Map
_trafficTypeVifDrivers.put(trafficType, getVifDriverClass(vifDriverClassName, params));
}
}
}
}
}
use of com.cloud.network.Networks.TrafficType in project cloudstack by apache.
the class NetworkServiceImpl method addTrafficTypeToPhysicalNetwork.
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_TRAFFIC_TYPE_CREATE, eventDescription = "Creating Physical Network TrafficType", create = true)
public PhysicalNetworkTrafficType addTrafficTypeToPhysicalNetwork(Long physicalNetworkId, String trafficTypeStr, String isolationMethod, String xenLabel, String kvmLabel, String vmwareLabel, String simulatorLabel, String vlan, String hypervLabel, String ovm3Label) {
// verify input parameters
PhysicalNetworkVO network = _physicalNetworkDao.findById(physicalNetworkId);
if (network == null) {
throw new InvalidParameterValueException("Physical Network id=" + physicalNetworkId + "doesn't exist in the system");
}
Networks.TrafficType trafficType = null;
if (trafficTypeStr != null && !trafficTypeStr.isEmpty()) {
try {
trafficType = Networks.TrafficType.valueOf(trafficTypeStr);
} catch (IllegalArgumentException ex) {
throw new InvalidParameterValueException("Unable to resolve trafficType '" + trafficTypeStr + "' to a supported value");
}
}
if (_pNTrafficTypeDao.isTrafficTypeSupported(physicalNetworkId, trafficType)) {
throw new CloudRuntimeException("This physical network already supports the traffic type: " + trafficType);
}
if (TrafficType.isSystemNetwork(trafficType) || TrafficType.Public.equals(trafficType) || TrafficType.Storage.equals(trafficType)) {
if (!_physicalNetworkDao.listByZoneAndTrafficType(network.getDataCenterId(), trafficType).isEmpty()) {
throw new CloudRuntimeException("Fail to add the traffic type to physical network because Zone already has a physical network with this traffic type: " + trafficType);
}
}
if (TrafficType.Storage.equals(trafficType)) {
List<SecondaryStorageVmVO> ssvms = _stnwMgr.getSSVMWithNoStorageNetwork(network.getDataCenterId());
if (!ssvms.isEmpty()) {
StringBuilder sb = new StringBuilder("Cannot add " + trafficType + " traffic type as there are below secondary storage vm still running. Please stop them all and add Storage traffic type again, then destory them all to allow CloudStack recreate them with storage network(If you have added storage network ip range)");
sb.append("SSVMs:");
for (SecondaryStorageVmVO ssvm : ssvms) {
sb.append(ssvm.getInstanceName()).append(":").append(ssvm.getState());
}
throw new CloudRuntimeException(sb.toString());
}
}
try {
// Create the new traffic type in the database
if (xenLabel == null) {
xenLabel = getDefaultXenNetworkLabel(trafficType);
}
PhysicalNetworkTrafficTypeVO pNetworktrafficType = new PhysicalNetworkTrafficTypeVO(physicalNetworkId, trafficType, xenLabel, kvmLabel, vmwareLabel, simulatorLabel, vlan, hypervLabel, ovm3Label);
pNetworktrafficType = _pNTrafficTypeDao.persist(pNetworktrafficType);
// each broadcast type will individually need to be qualified for support of public traffic
if (TrafficType.Public.equals(trafficType)) {
List<String> isolationMethods = network.getIsolationMethods();
if ((isolationMethods.size() == 1 && isolationMethods.get(0).toLowerCase().equals("vxlan")) || (isolationMethod != null && isolationMethods.contains(isolationMethod) && isolationMethod.toLowerCase().equals("vxlan"))) {
// find row in networks table that is defined as 'Public', created when zone was deployed
NetworkVO publicNetwork = _networksDao.listByZoneAndTrafficType(network.getDataCenterId(), TrafficType.Public).get(0);
if (publicNetwork != null) {
s_logger.debug("setting public network " + publicNetwork + " to broadcast type vxlan");
publicNetwork.setBroadcastDomainType(BroadcastDomainType.Vxlan);
_networksDao.persist(publicNetwork);
}
}
}
return pNetworktrafficType;
} catch (Exception ex) {
s_logger.warn("Exception: ", ex);
throw new CloudRuntimeException("Fail to add a traffic type to physical network");
}
}
Aggregations