use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.
the class NetworkOrchestrator method prepareNic.
@Override
public NicProfile prepareNic(final VirtualMachineProfile vmProfile, final DeployDestination dest, final ReservationContext context, final long nicId, final Network network) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
final Integer networkRate = _networkModel.getNetworkRate(network.getId(), vmProfile.getId());
final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
final NicVO nic = _nicDao.findById(nicId);
final NicProfile profile;
if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) {
nic.setState(Nic.State.Reserving);
nic.setReservationId(context.getReservationId());
_nicDao.update(nic.getId(), nic);
URI broadcastUri = nic.getBroadcastUri();
if (broadcastUri == null) {
broadcastUri = network.getBroadcastUri();
}
final URI isolationUri = nic.getIsolationUri();
profile = new NicProfile(nic, network, broadcastUri, isolationUri, networkRate, _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network));
guru.reserve(profile, network, vmProfile, dest, context);
nic.setIPv4Address(profile.getIPv4Address());
nic.setAddressFormat(profile.getFormat());
nic.setIPv6Address(profile.getIPv6Address());
nic.setMacAddress(profile.getMacAddress());
nic.setIsolationUri(profile.getIsolationUri());
nic.setBroadcastUri(profile.getBroadCastUri());
nic.setReserver(guru.getName());
nic.setState(Nic.State.Reserved);
nic.setIPv4Netmask(profile.getIPv4Netmask());
nic.setIPv4Gateway(profile.getIPv4Gateway());
if (profile.getReservationStrategy() != null) {
nic.setReservationStrategy(profile.getReservationStrategy());
}
updateNic(nic, network.getId(), 1);
} else {
profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network));
guru.updateNicProfile(profile, network);
nic.setState(Nic.State.Reserved);
updateNic(nic, network.getId(), 1);
}
final List<Provider> providersToImplement = getNetworkProviders(network.getId());
for (final NetworkElement element : networkElements) {
if (providersToImplement.contains(element.getProvider())) {
if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) {
throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: " + network.getPhysicalNetworkId());
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Asking " + element.getName() + " to prepare for " + nic);
}
if (!prepareElement(element, network, profile, vmProfile, dest, context)) {
throw new InsufficientAddressCapacityException("unable to configure the dhcp service, due to insufficiant address capacity", Network.class, network.getId());
}
}
}
guru.updateNicProfile(profile, network);
return profile;
}
use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.
the class ConfigurationManagerImpl method validateConnectivityServiceCapablities.
void validateConnectivityServiceCapablities(final Set<Provider> providers, final Map<Capability, String> connectivityServiceCapabilityMap) {
if (connectivityServiceCapabilityMap != null && !connectivityServiceCapabilityMap.isEmpty()) {
for (final Map.Entry<Capability, String> entry : connectivityServiceCapabilityMap.entrySet()) {
final Capability capability = entry.getKey();
if (capability == Capability.StretchedL2Subnet) {
final String value = entry.getValue().toLowerCase();
if (!(value.contains("true") ^ value.contains("false"))) {
throw new InvalidParameterValueException("Invalid value (" + value + ") for " + capability + " should be true/false");
}
} else {
throw new InvalidParameterValueException("Capability " + capability.getName() + " can not be " + " specified with connectivity service.");
}
}
// validate connectivity service provider actually supports specified capabilities
if (providers != null && !providers.isEmpty()) {
for (final Provider provider : providers) {
final NetworkElement element = _networkModel.getElementImplementingProvider(provider.getName());
final Map<Service, Map<Capability, String>> capabilities = element.getCapabilities();
if (capabilities != null && !capabilities.isEmpty()) {
final Map<Capability, String> connectivityCapabilities = capabilities.get(Service.Connectivity);
if (connectivityCapabilities == null || connectivityCapabilities != null && !connectivityCapabilities.keySet().contains(Capability.StretchedL2Subnet)) {
throw new InvalidParameterValueException("Provider: " + provider.getName() + " does not support " + Capability.StretchedL2Subnet.getName());
}
}
}
}
}
}
use of com.cloud.legacymodel.network.Network.Provider 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;
}
use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.
the class ConfigurationManagerImpl method validateNtwkOffDetails.
protected void validateNtwkOffDetails(final Map<Detail, String> details, final Map<Service, Set<Provider>> serviceProviderMap) {
for (final Detail detail : details.keySet()) {
Provider lbProvider = null;
if (detail == NetworkOffering.Detail.PublicLbProvider) {
// 1) Vaidate the detail values - have to match the lb provider
// name
final String providerStr = details.get(detail);
if (Network.Provider.getProvider(providerStr) == null) {
throw new InvalidParameterValueException("Invalid value " + providerStr + " for the detail " + detail);
}
if (serviceProviderMap.get(Service.Lb) != null) {
for (final Provider provider : serviceProviderMap.get(Service.Lb)) {
if (provider.getName().equalsIgnoreCase(providerStr)) {
lbProvider = provider;
break;
}
}
}
if (lbProvider == null) {
throw new InvalidParameterValueException("Invalid value " + details.get(detail) + " for the detail " + detail + ". The provider is not supported by the network offering");
}
// 2) validate if the provider supports the scheme
final Set<Provider> lbProviders = new HashSet<>();
lbProviders.add(lbProvider);
if (detail == NetworkOffering.Detail.PublicLbProvider) {
_networkModel.checkCapabilityForProvider(lbProviders, Service.Lb, Capability.LbSchemes, Scheme.Public.toString());
}
}
}
}
use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.
the class CreateNetworkOfferingTest method createIsolatedNtwkOffWithSpecifyIpRangesAndNoSourceNat.
@Test
public void createIsolatedNtwkOffWithSpecifyIpRangesAndNoSourceNat() {
final Map<Service, Set<Provider>> serviceProviderMap = new HashMap<>();
final Set<Network.Provider> vrProvider = new HashSet<>();
final NetworkOfferingVO off = configMgr.createNetworkOffering("isolated", "isolated", TrafficType.Guest, null, false, Availability.Optional, 200, serviceProviderMap, false, GuestType.Isolated, false, null, null, false, null, true, false, null, false, null, true);
assertNotNull("Isolated network offering with specifyIpRanges=true and with no sourceNatService, failed to create", off);
}
Aggregations