Search in sources :

Example 61 with NetworkOfferingVO

use of com.cloud.offerings.NetworkOfferingVO in project cloudstack by apache.

the class NuageVspElement method shutdown.

@Override
public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException {
    if (!canHandle(network, Service.Connectivity)) {
        return false;
    }
    if (cleanup && isDnsSupportedByVR(network)) {
        // The network is restarted, possibly the domain name is changed, update the dhcpOptions as soon as possible
        NetworkOfferingVO networkOfferingVO = _ntwkOfferingDao.findById(network.getNetworkOfferingId());
        VspDhcpDomainOption vspDhcpOptions = _nuageVspEntityBuilder.buildNetworkDhcpOption(network, networkOfferingVO);
        VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(network);
        HostVO nuageVspHost = _nuageVspManager.getNuageVspHost(network.getPhysicalNetworkId());
        ShutDownVspCommand cmd = new ShutDownVspCommand(vspNetwork, vspDhcpOptions);
        Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
        if (answer == null || !answer.getResult()) {
            s_logger.error("ShutDownVspCommand for network " + network.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
            if ((null != answer) && (null != answer.getDetails())) {
                throw new ResourceUnavailableException(answer.getDetails(), Network.class, network.getId());
            }
        }
    }
    return true;
}
Also used : Answer(com.cloud.agent.api.Answer) VspDhcpDomainOption(net.nuage.vsp.acs.client.api.model.VspDhcpDomainOption) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) VspNetwork(net.nuage.vsp.acs.client.api.model.VspNetwork) ShutDownVspCommand(com.cloud.agent.api.element.ShutDownVspCommand) HostVO(com.cloud.host.HostVO)

Example 62 with NetworkOfferingVO

use of com.cloud.offerings.NetworkOfferingVO in project cloudstack by apache.

the class ConfigurationManagerImpl method createNetworkOffering.

@Override
@DB
public NetworkOfferingVO createNetworkOffering(final String name, final String displayText, final TrafficType trafficType, String tags, final boolean specifyVlan, final Availability availability, final Integer networkRate, final Map<Service, Set<Provider>> serviceProviderMap, final boolean isDefault, final Network.GuestType type, final boolean systemOnly, final Long serviceOfferingId, final boolean conserveMode, final Map<Service, Map<Capability, String>> serviceCapabilityMap, final boolean specifyIpRanges, final boolean isPersistent, final Map<NetworkOffering.Detail, String> details, final boolean egressDefaultPolicy, final Integer maxconn, final boolean enableKeepAlive) {
    final String multicastRateStr = _configDao.getValue("multicast.throttling.rate");
    final int multicastRate = multicastRateStr == null ? 10 : Integer.parseInt(multicastRateStr);
    tags = StringUtils.cleanupTags(tags);
    // specifyVlan should always be true for Shared network offerings
    if (!specifyVlan && type == GuestType.Shared) {
        Set<Provider> connectivityProviders = serviceProviderMap != null ? serviceProviderMap.get(Service.Connectivity) : null;
        if (CollectionUtils.isEmpty(connectivityProviders) || !_networkModel.providerSupportsCapability(connectivityProviders, Service.Connectivity, Capability.NoVlan)) {
            throw new InvalidParameterValueException("SpecifyVlan should be true if network offering's type is " + type);
        }
    }
    // Nat service
    if (specifyIpRanges) {
        if (type == GuestType.Isolated) {
            if (serviceProviderMap.containsKey(Service.SourceNat)) {
                throw new InvalidParameterValueException("SpecifyIpRanges can only be true for Shared network offerings and Isolated with no SourceNat service");
            }
        }
    } else {
        if (type == GuestType.Shared) {
            throw new InvalidParameterValueException("SpecifyIpRanges should always be true for Shared network offerings");
        }
    }
    // isPersistent should always be false for Shared network Offerings
    if (isPersistent && type == GuestType.Shared) {
        throw new InvalidParameterValueException("isPersistent should be false if network offering's type is " + type);
    }
    // validate availability value
    if (availability == NetworkOffering.Availability.Required) {
        final boolean canOffBeRequired = type == GuestType.Isolated && serviceProviderMap.containsKey(Service.SourceNat);
        if (!canOffBeRequired) {
            throw new InvalidParameterValueException("Availability can be " + NetworkOffering.Availability.Required + " only for networkOfferings of type " + GuestType.Isolated + " and with " + Service.SourceNat.getName() + " enabled");
        }
        // only one network offering in the system can be Required
        final List<NetworkOfferingVO> offerings = _networkOfferingDao.listByAvailability(Availability.Required, false);
        if (!offerings.isEmpty()) {
            throw new InvalidParameterValueException("System already has network offering id=" + offerings.get(0).getId() + " with availability " + Availability.Required);
        }
    }
    boolean dedicatedLb = false;
    boolean elasticLb = false;
    boolean sharedSourceNat = false;
    boolean redundantRouter = false;
    boolean elasticIp = false;
    boolean associatePublicIp = false;
    boolean inline = false;
    boolean publicLb = false;
    boolean internalLb = false;
    boolean strechedL2Subnet = false;
    boolean publicAccess = false;
    if (serviceCapabilityMap != null && !serviceCapabilityMap.isEmpty()) {
        final Map<Capability, String> lbServiceCapabilityMap = serviceCapabilityMap.get(Service.Lb);
        if (lbServiceCapabilityMap != null && !lbServiceCapabilityMap.isEmpty()) {
            final String isolationCapability = lbServiceCapabilityMap.get(Capability.SupportedLBIsolation);
            if (isolationCapability != null) {
                _networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.Lb), Service.Lb, Capability.SupportedLBIsolation, isolationCapability);
                dedicatedLb = isolationCapability.contains("dedicated");
            } else {
                dedicatedLb = true;
            }
            final String param = lbServiceCapabilityMap.get(Capability.ElasticLb);
            if (param != null) {
                elasticLb = param.contains("true");
            }
            final String inlineMode = lbServiceCapabilityMap.get(Capability.InlineMode);
            if (inlineMode != null) {
                _networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.Lb), Service.Lb, Capability.InlineMode, inlineMode);
                inline = inlineMode.contains("true");
            } else {
                inline = false;
            }
            final String publicLbStr = lbServiceCapabilityMap.get(Capability.LbSchemes);
            if (serviceProviderMap.containsKey(Service.Lb)) {
                if (publicLbStr != null) {
                    _networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.Lb), Service.Lb, Capability.LbSchemes, publicLbStr);
                    internalLb = publicLbStr.contains("internal");
                    publicLb = publicLbStr.contains("public");
                }
            }
        }
        // both be set to true for the same network offering
        if (publicLb && internalLb) {
            throw new InvalidParameterValueException("Public lb and internal lb can't be enabled at the same time on the offering");
        }
        final Map<Capability, String> sourceNatServiceCapabilityMap = serviceCapabilityMap.get(Service.SourceNat);
        if (sourceNatServiceCapabilityMap != null && !sourceNatServiceCapabilityMap.isEmpty()) {
            final String sourceNatType = sourceNatServiceCapabilityMap.get(Capability.SupportedSourceNatTypes);
            if (sourceNatType != null) {
                _networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.SourceNat), Service.SourceNat, Capability.SupportedSourceNatTypes, sourceNatType);
                sharedSourceNat = sourceNatType.contains("perzone");
            }
            final String param = sourceNatServiceCapabilityMap.get(Capability.RedundantRouter);
            if (param != null) {
                _networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.SourceNat), Service.SourceNat, Capability.RedundantRouter, param);
                redundantRouter = param.contains("true");
            }
        }
        final Map<Capability, String> staticNatServiceCapabilityMap = serviceCapabilityMap.get(Service.StaticNat);
        if (staticNatServiceCapabilityMap != null && !staticNatServiceCapabilityMap.isEmpty()) {
            final String param = staticNatServiceCapabilityMap.get(Capability.ElasticIp);
            if (param != null) {
                elasticIp = param.contains("true");
                final String associatePublicIP = staticNatServiceCapabilityMap.get(Capability.AssociatePublicIP);
                if (associatePublicIP != null) {
                    associatePublicIp = associatePublicIP.contains("true");
                }
            }
        }
        final Map<Capability, String> connectivityServiceCapabilityMap = serviceCapabilityMap.get(Service.Connectivity);
        if (connectivityServiceCapabilityMap != null && !connectivityServiceCapabilityMap.isEmpty()) {
            if (connectivityServiceCapabilityMap.containsKey(Capability.StretchedL2Subnet)) {
                final String value = connectivityServiceCapabilityMap.get(Capability.StretchedL2Subnet);
                if ("true".equalsIgnoreCase(value)) {
                    strechedL2Subnet = true;
                }
            }
            if (connectivityServiceCapabilityMap.containsKey(Capability.PublicAccess)) {
                final String value = connectivityServiceCapabilityMap.get(Capability.PublicAccess);
                if ("true".equalsIgnoreCase(value)) {
                    publicAccess = true;
                }
            }
        }
    }
    if (serviceProviderMap != null && serviceProviderMap.containsKey(Service.Lb) && !internalLb && !publicLb) {
        //if not specified, default public lb to true
        publicLb = true;
    }
    final NetworkOfferingVO offeringFinal = new NetworkOfferingVO(name, displayText, trafficType, systemOnly, specifyVlan, networkRate, multicastRate, isDefault, availability, tags, type, conserveMode, dedicatedLb, sharedSourceNat, redundantRouter, elasticIp, elasticLb, specifyIpRanges, inline, isPersistent, associatePublicIp, publicLb, internalLb, egressDefaultPolicy, strechedL2Subnet, publicAccess);
    if (serviceOfferingId != null) {
        offeringFinal.setServiceOfferingId(serviceOfferingId);
    }
    // validate the details
    if (details != null) {
        validateNtwkOffDetails(details, serviceProviderMap);
    }
    return Transaction.execute(new TransactionCallback<NetworkOfferingVO>() {

        @Override
        public NetworkOfferingVO doInTransaction(final TransactionStatus status) {
            NetworkOfferingVO offering = offeringFinal;
            // 1) create network offering object
            s_logger.debug("Adding network offering " + offering);
            offering.setConcurrentConnections(maxconn);
            offering.setKeepAliveEnabled(enableKeepAlive);
            offering = _networkOfferingDao.persist(offering, details);
            // 2) populate services and providers
            if (serviceProviderMap != null) {
                for (final Network.Service service : serviceProviderMap.keySet()) {
                    final Set<Provider> providers = serviceProviderMap.get(service);
                    if (providers != null && !providers.isEmpty()) {
                        boolean vpcOff = false;
                        for (final Network.Provider provider : providers) {
                            if (provider == Provider.VPCVirtualRouter) {
                                vpcOff = true;
                            }
                            final NetworkOfferingServiceMapVO offService = new NetworkOfferingServiceMapVO(offering.getId(), service, provider);
                            _ntwkOffServiceMapDao.persist(offService);
                            s_logger.trace("Added service for the network offering: " + offService + " with provider " + provider.getName());
                        }
                        if (vpcOff) {
                            final List<Service> supportedSvcs = new ArrayList<Service>();
                            supportedSvcs.addAll(serviceProviderMap.keySet());
                            _vpcMgr.validateNtwkOffForVpc(offering, supportedSvcs);
                        }
                    } else {
                        final NetworkOfferingServiceMapVO offService = new NetworkOfferingServiceMapVO(offering.getId(), service, null);
                        _ntwkOffServiceMapDao.persist(offService);
                        s_logger.trace("Added service for the network offering: " + offService + " with null provider");
                    }
                }
            }
            return offering;
        }
    });
}
Also used : NetworkOfferingServiceMapVO(com.cloud.offerings.NetworkOfferingServiceMapVO) HashSet(java.util.HashSet) Set(java.util.Set) Capability(com.cloud.network.Network.Capability) TransactionStatus(com.cloud.utils.db.TransactionStatus) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) NetworkService(com.cloud.network.NetworkService) ManagementService(com.cloud.server.ManagementService) ResourceLimitService(com.cloud.user.ResourceLimitService) AffinityGroupService(org.apache.cloudstack.affinity.AffinityGroupService) Provider(com.cloud.network.Network.Provider) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) ArrayList(java.util.ArrayList) List(java.util.List) DB(com.cloud.utils.db.DB)

Example 63 with NetworkOfferingVO

use of com.cloud.offerings.NetworkOfferingVO in project cloudstack by apache.

the class ConfigurationManagerImpl method createDefaultSystemNetworks.

@Override
public void createDefaultSystemNetworks(final long zoneId) throws ConcurrentOperationException {
    final DataCenterVO zone = _zoneDao.findById(zoneId);
    final String networkDomain = null;
    // the zone creation
    if (zone != null) {
        final List<NetworkOfferingVO> ntwkOff = _networkOfferingDao.listSystemNetworkOfferings();
        for (final NetworkOfferingVO offering : ntwkOff) {
            final DataCenterDeployment plan = new DataCenterDeployment(zone.getId(), null, null, null, null, null);
            final NetworkVO userNetwork = new NetworkVO();
            final Account systemAccount = _accountDao.findById(Account.ACCOUNT_ID_SYSTEM);
            BroadcastDomainType broadcastDomainType = null;
            if (offering.getTrafficType() == TrafficType.Management) {
                broadcastDomainType = BroadcastDomainType.Native;
            } else if (offering.getTrafficType() == TrafficType.Control) {
                broadcastDomainType = BroadcastDomainType.LinkLocal;
            } else if (offering.getTrafficType() == TrafficType.Public) {
                if (zone.getNetworkType() == NetworkType.Advanced && !zone.isSecurityGroupEnabled() || zone.getNetworkType() == NetworkType.Basic) {
                    broadcastDomainType = BroadcastDomainType.Vlan;
                } else {
                    // so broadcastDomainType remains null! why have None/Undecided/UnKnown?
                    continue;
                }
            } else if (offering.getTrafficType() == TrafficType.Guest) {
                continue;
            }
            userNetwork.setBroadcastDomainType(broadcastDomainType);
            userNetwork.setNetworkDomain(networkDomain);
            _networkMgr.setupNetwork(systemAccount, offering, userNetwork, plan, null, null, false, Domain.ROOT_DOMAIN, null, null, null, true);
        }
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) BroadcastDomainType(com.cloud.network.Networks.BroadcastDomainType) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO)

Example 64 with NetworkOfferingVO

use of com.cloud.offerings.NetworkOfferingVO in project cloudstack by apache.

the class ConfigurationManagerImpl method updateNetworkOffering.

@Override
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_OFFERING_EDIT, eventDescription = "updating network offering")
public NetworkOffering updateNetworkOffering(final UpdateNetworkOfferingCmd cmd) {
    final String displayText = cmd.getDisplayText();
    final Long id = cmd.getId();
    final String name = cmd.getNetworkOfferingName();
    final String availabilityStr = cmd.getAvailability();
    final Integer sortKey = cmd.getSortKey();
    final Integer maxconn = cmd.getMaxconnections();
    Availability availability = null;
    final String state = cmd.getState();
    CallContext.current().setEventDetails(" Id: " + id);
    // Verify input parameters
    final NetworkOfferingVO offeringToUpdate = _networkOfferingDao.findById(id);
    if (offeringToUpdate == null) {
        throw new InvalidParameterValueException("unable to find network offering " + id);
    }
    // Don't allow to update system network offering
    if (offeringToUpdate.isSystemOnly()) {
        throw new InvalidParameterValueException("Can't update system network offerings");
    }
    final NetworkOfferingVO offering = _networkOfferingDao.createForUpdate(id);
    if (name != null) {
        offering.setName(name);
    }
    if (displayText != null) {
        offering.setDisplayText(displayText);
    }
    if (sortKey != null) {
        offering.setSortKey(sortKey);
    }
    if (state != null) {
        boolean validState = false;
        for (final NetworkOffering.State st : NetworkOffering.State.values()) {
            if (st.name().equalsIgnoreCase(state)) {
                validState = true;
                offering.setState(st);
            }
        }
        if (!validState) {
            throw new InvalidParameterValueException("Incorrect state value: " + state);
        }
    }
    // Verify availability
    if (availabilityStr != null) {
        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);
        } else {
            if (availability == NetworkOffering.Availability.Required) {
                final boolean canOffBeRequired = offeringToUpdate.getGuestType() == GuestType.Isolated && _networkModel.areServicesSupportedByNetworkOffering(offeringToUpdate.getId(), Service.SourceNat);
                if (!canOffBeRequired) {
                    throw new InvalidParameterValueException("Availability can be " + NetworkOffering.Availability.Required + " only for networkOfferings of type " + GuestType.Isolated + " and with " + Service.SourceNat.getName() + " enabled");
                }
                // only one network offering in the system can be Required
                final List<NetworkOfferingVO> offerings = _networkOfferingDao.listByAvailability(Availability.Required, false);
                if (!offerings.isEmpty() && offerings.get(0).getId() != offeringToUpdate.getId()) {
                    throw new InvalidParameterValueException("System already has network offering id=" + offerings.get(0).getId() + " with availability " + Availability.Required);
                }
            }
            offering.setAvailability(availability);
        }
    }
    if (_ntwkOffServiceMapDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.Lb)) {
        if (maxconn != null) {
            offering.setConcurrentConnections(maxconn);
        }
    }
    if (_networkOfferingDao.update(id, offering)) {
        return _networkOfferingDao.findById(id);
    } else {
        return null;
    }
}
Also used : Availability(com.cloud.offering.NetworkOffering.Availability) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) NetworkOffering(com.cloud.offering.NetworkOffering) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) ActionEvent(com.cloud.event.ActionEvent)

Example 65 with NetworkOfferingVO

use of com.cloud.offerings.NetworkOfferingVO in project cloudstack by apache.

the class ConfigurationManagerImpl method deleteNetworkOffering.

@Override
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_OFFERING_DELETE, eventDescription = "deleting network offering")
public boolean deleteNetworkOffering(final DeleteNetworkOfferingCmd cmd) {
    final Long offeringId = cmd.getId();
    CallContext.current().setEventDetails(" Id: " + offeringId);
    // Verify network offering id
    final NetworkOfferingVO offering = _networkOfferingDao.findById(offeringId);
    if (offering == null) {
        throw new InvalidParameterValueException("unable to find network offering " + offeringId);
    } else if (offering.getRemoved() != null || offering.isSystemOnly()) {
        throw new InvalidParameterValueException("unable to find network offering " + offeringId);
    }
    // Don't allow to delete default network offerings
    if (offering.isDefault() == true) {
        throw new InvalidParameterValueException("Default network offering can't be deleted");
    }
    // don't allow to delete network offering if it's in use by existing
    // networks (the offering can be disabled
    // though)
    final int networkCount = _networkDao.getNetworkCountByNetworkOffId(offeringId);
    if (networkCount > 0) {
        throw new InvalidParameterValueException("Can't delete network offering " + offeringId + " as its used by " + networkCount + " networks. " + "To make the network offering unavaiable, disable it");
    }
    if (_networkOfferingDao.remove(offeringId)) {
        return true;
    } else {
        return false;
    }
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) ActionEvent(com.cloud.event.ActionEvent)

Aggregations

NetworkOfferingVO (com.cloud.offerings.NetworkOfferingVO)65 NetworkVO (com.cloud.network.dao.NetworkVO)22 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)18 ArrayList (java.util.ArrayList)18 Network (com.cloud.network.Network)17 Test (org.junit.Test)17 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)16 Service (com.cloud.network.Network.Service)15 DB (com.cloud.utils.db.DB)13 Provider (com.cloud.network.Network.Provider)12 Account (com.cloud.user.Account)12 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)12 DataCenterVO (com.cloud.dc.DataCenterVO)11 HashMap (java.util.HashMap)11 HashSet (java.util.HashSet)11 Set (java.util.Set)11 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)10 PhysicalNetwork (com.cloud.network.PhysicalNetwork)10 TransactionStatus (com.cloud.utils.db.TransactionStatus)10 DomainVO (com.cloud.domain.DomainVO)9