use of com.cloud.model.enumeration.TrafficType in project cosmic by MissionCriticalCloud.
the class DomainRouterJoinDaoImpl method setDomainRouterResponse.
@Override
public DomainRouterResponse setDomainRouterResponse(final DomainRouterResponse vrData, final DomainRouterJoinVO vr) {
final long nic_id = vr.getNicId();
if (nic_id > 0) {
final TrafficType ty = vr.getTrafficType();
if (ty != null) {
// nics response object
if (ty == TrafficType.Public) {
vrData.setPublicIp(vr.getIpAddress());
vrData.setPublicMacAddress(vr.getMacAddress());
vrData.setPublicNetmask(vr.getNetmask());
vrData.setGateway(vr.getGateway());
vrData.setPublicNetworkId(vr.getNetworkUuid());
} else if (ty == TrafficType.Control) {
vrData.setLinkLocalIp(vr.getIpAddress());
vrData.setLinkLocalMacAddress(vr.getMacAddress());
vrData.setLinkLocalNetmask(vr.getNetmask());
vrData.setLinkLocalNetworkId(vr.getNetworkUuid());
} else if (ty == TrafficType.Guest) {
vrData.setGuestIpAddress(vr.getIpAddress());
vrData.setGuestMacAddress(vr.getMacAddress());
vrData.setGuestNetmask(vr.getNetmask());
vrData.setGuestNetworkId(vr.getNetworkUuid());
vrData.setGuestNetworkName(vr.getNetworkName());
vrData.setNetworkDomain(vr.getNetworkDomain());
}
}
final NicResponse nicResponse = new NicResponse();
nicResponse.setId(vr.getNicUuid());
nicResponse.setIpaddress(vr.getIpAddress());
nicResponse.setGateway(vr.getGateway());
nicResponse.setNetmask(vr.getNetmask());
nicResponse.setNetworkid(vr.getNetworkUuid());
nicResponse.setNetworkName(vr.getNetworkName());
nicResponse.setMacAddress(vr.getMacAddress());
nicResponse.setIp6Address(vr.getIp6Address());
nicResponse.setIp6Gateway(vr.getIp6Gateway());
nicResponse.setIp6Cidr(vr.getIp6Cidr());
if (vr.getBroadcastUri() != null) {
nicResponse.setBroadcastUri(vr.getBroadcastUri().toString());
}
if (vr.getIsolationUri() != null) {
nicResponse.setIsolationUri(vr.getIsolationUri().toString());
}
if (vr.getTrafficType() != null) {
nicResponse.setTrafficType(vr.getTrafficType().toString());
}
if (vr.getGuestType() != null) {
nicResponse.setType(vr.getGuestType().toString());
}
nicResponse.setIsDefault(vr.isDefaultNic());
nicResponse.setObjectName("nic");
vrData.addNic(nicResponse);
}
return vrData;
}
use of com.cloud.model.enumeration.TrafficType in project cosmic by MissionCriticalCloud.
the class NetworkServiceImpl method addTrafficTypeToPhysicalNetwork.
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_TRAFFIC_TYPE_CREATE, eventDescription = "Creating Physical Network TrafficType", create = true)
public PhysicalNetworkTrafficType addTrafficTypeToPhysicalNetwork(final Long physicalNetworkId, final String trafficTypeStr, final String isolationMethod, String xenLabel, final String kvmLabel, final String vlan) {
// verify input parameters
final PhysicalNetworkVO network = _physicalNetworkDao.findById(physicalNetworkId);
if (network == null) {
throw new InvalidParameterValueException("Physical Network id=" + physicalNetworkId + "doesn't exist in the system");
}
TrafficType trafficType = null;
if (trafficTypeStr != null && !trafficTypeStr.isEmpty()) {
try {
trafficType = TrafficType.valueOf(trafficTypeStr);
} catch (final 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)) {
final List<SecondaryStorageVmVO> ssvms = _stnwMgr.getSSVMWithNoStorageNetwork(network.getDataCenterId());
if (!ssvms.isEmpty()) {
final 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 (final 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, vlan);
pNetworktrafficType = _pNTrafficTypeDao.persist(pNetworktrafficType);
// each broadcast type will individually need to be qualified for support of public traffic
if (TrafficType.Public.equals(trafficType)) {
final 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
final 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 (final Exception ex) {
s_logger.warn("Exception: ", ex);
throw new CloudRuntimeException("Fail to add a traffic type to physical network");
}
}
use of com.cloud.model.enumeration.TrafficType in project cosmic by MissionCriticalCloud.
the class SystemVmManagerBase method getNetworkForAdvancedZone.
protected static NetworkVO getNetworkForAdvancedZone(final Zone zone, final NetworkDao _networkDao) {
if (zone.getNetworkType() != NetworkType.Advanced) {
throw new CloudRuntimeException("Zone " + zone + " is not advanced.");
}
final TrafficType defaultTrafficType = TrafficType.Public;
final List<NetworkVO> defaultNetworks = _networkDao.listByZoneAndTrafficType(zone.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.model.enumeration.TrafficType in project cosmic by MissionCriticalCloud.
the class ConfigurationManagerImpl method createNetworkOffering.
@Override
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_OFFERING_CREATE, eventDescription = "creating network offering")
public NetworkOffering createNetworkOffering(final CreateNetworkOfferingCmd cmd) {
final String name = cmd.getNetworkOfferingName();
final String displayText = cmd.getDisplayText();
final String tags = cmd.getTags();
final String trafficTypeString = cmd.getTraffictype();
final boolean specifyVlan = cmd.getSpecifyVlan();
final boolean conserveMode = cmd.getConserveMode();
final String availabilityStr = cmd.getAvailability();
Integer networkRate = cmd.getNetworkRate();
TrafficType trafficType = null;
Availability availability = null;
GuestType guestType = null;
final boolean specifyIpRanges = cmd.getSpecifyIpRanges();
final boolean isPersistent = cmd.getIsPersistent();
final Map<String, String> detailsStr = cmd.getDetails();
final Boolean egressDefaultPolicy = cmd.getEgressDefaultPolicy();
Integer maxconn = null;
boolean enableKeepAlive = false;
// Verify traffic type
for (final TrafficType tType : TrafficType.values()) {
if (tType.name().equalsIgnoreCase(trafficTypeString)) {
trafficType = tType;
break;
}
}
if (trafficType == null) {
throw new InvalidParameterValueException("Invalid value for traffictype. Supported traffic types: Public, Management, Control, Guest, Vlan or Storage");
}
// Only GUEST traffic type is supported in Acton
if (trafficType != TrafficType.Guest) {
throw new InvalidParameterValueException("Only traffic type " + TrafficType.Guest + " is supported in the current release");
}
// Verify offering type
for (final GuestType offType : GuestType.values()) {
if (offType.name().equalsIgnoreCase(cmd.getGuestIpType())) {
guestType = offType;
break;
}
}
if (guestType == null) {
throw new InvalidParameterValueException("Invalid \"type\" parameter is given; can have Shared and Isolated values");
}
// Verify availability
for (final Availability avlb : Availability.values()) {
if (avlb.name().equalsIgnoreCase(availabilityStr)) {
availability = avlb;
}
}
if (availability == null) {
throw new InvalidParameterValueException("Invalid value for Availability. Supported types: " + Availability.Required + ", " + Availability.Optional);
}
if (networkRate != null && networkRate < 0) {
networkRate = 0;
}
final Long serviceOfferingId = cmd.getServiceOfferingId();
final Long secondaryServiceOfferingId = cmd.getSecondaryServiceOfferingId();
if (serviceOfferingId != null) {
checkServiceOffering(serviceOfferingId);
}
if (secondaryServiceOfferingId != null) {
checkServiceOffering(secondaryServiceOfferingId);
}
// configure service provider map
final Map<Network.Service, Set<Network.Provider>> serviceProviderMap = new HashMap<>();
final Set<Network.Provider> defaultProviders = new HashSet<>();
// populate the services first
for (final String serviceName : cmd.getSupportedServices()) {
// validate if the service is supported
final Service service = Network.Service.getService(serviceName);
if (service == null || service == Service.Gateway) {
throw new InvalidParameterValueException("Invalid service " + serviceName);
}
serviceProviderMap.put(service, defaultProviders);
}
// add gateway provider (if sourceNat provider is enabled)
final Set<Provider> sourceNatServiceProviders = serviceProviderMap.get(Service.SourceNat);
if (sourceNatServiceProviders != null && !sourceNatServiceProviders.isEmpty()) {
serviceProviderMap.put(Service.Gateway, sourceNatServiceProviders);
}
// populate providers
final Map<Provider, Set<Service>> providerCombinationToVerify = new HashMap<>();
final Map<String, List<String>> svcPrv = cmd.getServiceProviders();
Provider firewallProvider = null;
Provider dhcpProvider = null;
Boolean IsVrUserdataProvider = false;
if (svcPrv != null) {
for (final String serviceStr : svcPrv.keySet()) {
final Network.Service service = Network.Service.getService(serviceStr);
if (serviceProviderMap.containsKey(service)) {
final Set<Provider> providers = new HashSet<>();
// the service is LB
if (!serviceStr.equalsIgnoreCase(Service.Lb.getName()) && svcPrv.get(serviceStr) != null && svcPrv.get(serviceStr).size() > 1) {
throw new InvalidParameterValueException("In the current release only one provider can be " + "specified for the service if the service is not LB");
}
for (final String prvNameStr : svcPrv.get(serviceStr)) {
// check if provider is supported
final Network.Provider provider = Network.Provider.getProvider(prvNameStr);
if (provider == null) {
throw new InvalidParameterValueException("Invalid service provider: " + prvNameStr);
}
if ((service == Service.PortForwarding || service == Service.StaticNat) && provider == Provider.VirtualRouter) {
firewallProvider = Provider.VirtualRouter;
}
if (service == Service.Dhcp) {
dhcpProvider = provider;
}
if (service == Service.UserData && provider == Provider.VirtualRouter) {
IsVrUserdataProvider = true;
}
providers.add(provider);
final Set<Service> serviceSet;
if (providerCombinationToVerify.get(provider) == null) {
serviceSet = new HashSet<>();
} else {
serviceSet = providerCombinationToVerify.get(provider);
}
serviceSet.add(service);
providerCombinationToVerify.put(provider, serviceSet);
}
serviceProviderMap.put(service, providers);
} else {
throw new InvalidParameterValueException("Service " + serviceStr + " is not enabled for the network " + "offering, can't add a provider to it");
}
}
}
// dhcp provider and userdata provider should be same because vm will be contacting dhcp server for user data.
if (dhcpProvider == null && IsVrUserdataProvider) {
s_logger.debug("User data provider VR can't be selected without VR as dhcp provider. In this case VM fails to contact the DHCP server for userdata");
throw new InvalidParameterValueException("Without VR as dhcp provider, User data can't selected for VR. Please select VR as DHCP provider ");
}
// validate providers combination here
_networkModel.canProviderSupportServices(providerCombinationToVerify);
// validate the LB service capabilities specified in the network
// offering
final Map<Capability, String> lbServiceCapabilityMap = cmd.getServiceCapabilities(Service.Lb);
if (!serviceProviderMap.containsKey(Service.Lb) && lbServiceCapabilityMap != null && !lbServiceCapabilityMap.isEmpty()) {
throw new InvalidParameterValueException("Capabilities for LB service can be specifed only when LB service is enabled for network offering.");
}
validateLoadBalancerServiceCapabilities(lbServiceCapabilityMap);
if (lbServiceCapabilityMap != null && !lbServiceCapabilityMap.isEmpty()) {
maxconn = cmd.getMaxconnections();
if (maxconn == null) {
maxconn = Integer.parseInt(_configDao.getValue(Config.NetworkLBHaproxyMaxConn.key()));
}
}
if (cmd.getKeepAliveEnabled() != null && cmd.getKeepAliveEnabled()) {
enableKeepAlive = true;
}
// validate the Source NAT service capabilities specified in the network
// offering
final Map<Capability, String> sourceNatServiceCapabilityMap = cmd.getServiceCapabilities(Service.SourceNat);
if (!serviceProviderMap.containsKey(Service.SourceNat) && sourceNatServiceCapabilityMap != null && !sourceNatServiceCapabilityMap.isEmpty()) {
throw new InvalidParameterValueException("Capabilities for source NAT service can be specifed only when source NAT service is enabled for network offering.");
}
validateSourceNatServiceCapablities(sourceNatServiceCapabilityMap);
// validate the Static Nat service capabilities specified in the network
// offering
final Map<Capability, String> staticNatServiceCapabilityMap = cmd.getServiceCapabilities(Service.StaticNat);
if (!serviceProviderMap.containsKey(Service.StaticNat) && sourceNatServiceCapabilityMap != null && !staticNatServiceCapabilityMap.isEmpty()) {
throw new InvalidParameterValueException("Capabilities for static NAT service can be specifed only when static NAT service is enabled for network offering.");
}
validateStaticNatServiceCapablities(staticNatServiceCapabilityMap);
// validate the 'Connectivity' service capabilities specified in the network offering, if 'Connectivity' service
// is in the supported services of network offering
final Map<Capability, String> connectivityServiceCapabilityMap = cmd.getServiceCapabilities(Service.Connectivity);
if (!serviceProviderMap.containsKey(Service.Connectivity) && connectivityServiceCapabilityMap != null && !connectivityServiceCapabilityMap.isEmpty()) {
throw new InvalidParameterValueException("Capabilities for 'Connectivity' service can be specified " + "only when Connectivity service is enabled for network offering.");
}
validateConnectivityServiceCapablities(serviceProviderMap.get(Service.Connectivity), connectivityServiceCapabilityMap);
final Map<Service, Map<Capability, String>> serviceCapabilityMap = new HashMap<>();
serviceCapabilityMap.put(Service.Lb, lbServiceCapabilityMap);
serviceCapabilityMap.put(Service.SourceNat, sourceNatServiceCapabilityMap);
serviceCapabilityMap.put(Service.StaticNat, staticNatServiceCapabilityMap);
serviceCapabilityMap.put(Service.Connectivity, connectivityServiceCapabilityMap);
// combination
if (firewallProvider != null) {
s_logger.debug("Adding Firewall service with provider " + firewallProvider.getName());
final Set<Provider> firewallProviderSet = new HashSet<>();
firewallProviderSet.add(firewallProvider);
serviceProviderMap.put(Service.Firewall, firewallProviderSet);
if (!firewallProvider.getName().equals(Provider.VirtualRouter.getName()) && !egressDefaultPolicy) {
throw new InvalidParameterValueException("Firewall egress with default policy " + egressDefaultPolicy + " is not supported by the provider " + firewallProvider.getName());
}
}
final Map<NetworkOffering.Detail, String> details = new HashMap<>();
if (detailsStr != null) {
for (final String detailStr : detailsStr.keySet()) {
NetworkOffering.Detail offDetail = null;
for (final NetworkOffering.Detail supportedDetail : NetworkOffering.Detail.values()) {
if (detailStr.equalsIgnoreCase(supportedDetail.toString())) {
offDetail = supportedDetail;
break;
}
}
if (offDetail == null) {
throw new InvalidParameterValueException("Unsupported detail " + detailStr);
}
details.put(offDetail, detailsStr.get(detailStr));
}
}
final NetworkOffering offering = createNetworkOffering(name, displayText, trafficType, tags, specifyVlan, availability, networkRate, serviceProviderMap, false, guestType, false, serviceOfferingId, secondaryServiceOfferingId, conserveMode, serviceCapabilityMap, specifyIpRanges, isPersistent, details, egressDefaultPolicy, maxconn, enableKeepAlive);
CallContext.current().setEventDetails(" Id: " + offering.getId() + " Name: " + name);
return offering;
}
Aggregations