Search in sources :

Example 1 with Capability

use of com.cloud.network.Network.Capability in project CloudStack-archive by CloudStack-extras.

the class CreateNetworkOfferingCmd method getServiceCapabilities.

public Map<Capability, String> getServiceCapabilities(Service service) {
    Map<Capability, String> capabilityMap = null;
    if (serviceCapabilitystList != null && !serviceCapabilitystList.isEmpty()) {
        capabilityMap = new HashMap<Capability, String>();
        Collection serviceCapabilityCollection = serviceCapabilitystList.values();
        Iterator iter = serviceCapabilityCollection.iterator();
        while (iter.hasNext()) {
            HashMap<String, String> svcCapabilityMap = (HashMap<String, String>) iter.next();
            Capability capability = null;
            String svc = (String) svcCapabilityMap.get("service");
            String capabilityName = (String) svcCapabilityMap.get("capabilitytype");
            String capabilityValue = (String) svcCapabilityMap.get("capabilityvalue");
            if (capabilityName != null) {
                capability = Capability.getCapability(capabilityName);
            }
            if ((capability == null) || (capabilityName == null) || (capabilityValue == null)) {
                throw new InvalidParameterValueException("Invalid capability:" + capabilityName + " capability value:" + capabilityValue);
            }
            if (svc.equalsIgnoreCase(service.getName())) {
                capabilityMap.put(capability, capabilityValue);
            } else {
            //throw new InvalidParameterValueException("Service is not equal ")
            }
        }
    }
    return capabilityMap;
}
Also used : Capability(com.cloud.network.Network.Capability) HashMap(java.util.HashMap) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Iterator(java.util.Iterator) Collection(java.util.Collection)

Example 2 with Capability

use of com.cloud.network.Network.Capability in project cloudstack by apache.

the class VpcVirtualRouterElement method stopSite2SiteVpn.

@Override
public boolean stopSite2SiteVpn(final Site2SiteVpnConnection conn) throws ResourceUnavailableException {
    final Site2SiteVpnGateway vpnGw = _vpnGatewayDao.findById(conn.getVpnGatewayId());
    final IpAddress ip = _ipAddressDao.findById(vpnGw.getAddrId());
    final Map<Capability, String> vpnCapabilities = capabilities.get(Service.Vpn);
    if (!vpnCapabilities.get(Capability.VpnTypes).contains("s2svpn")) {
        s_logger.error("try to stop site 2 site vpn on unsupported network element?");
        return false;
    }
    final Long vpcId = ip.getVpcId();
    final Vpc vpc = _entityMgr.findById(Vpc.class, vpcId);
    if (!_ntwkModel.isProviderEnabledInZone(vpc.getZoneId(), Provider.VPCVirtualRouter.getName())) {
        throw new ResourceUnavailableException("VPC provider is not enabled in zone " + vpc.getZoneId(), DataCenter.class, vpc.getZoneId());
    }
    final List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(ip.getVpcId());
    if (routers == null) {
        throw new ResourceUnavailableException("Cannot enable site-to-site VPN on the backend; virtual router doesn't exist in the vpc " + ip.getVpcId(), DataCenter.class, vpc.getZoneId());
    }
    boolean result = true;
    for (final DomainRouterVO domainRouterVO : routers) {
        result = result && _vpcRouterMgr.stopSite2SiteVpn(conn, domainRouterVO);
    }
    return result;
}
Also used : Site2SiteVpnGateway(com.cloud.network.Site2SiteVpnGateway) Capability(com.cloud.network.Network.Capability) Vpc(com.cloud.network.vpc.Vpc) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 3 with Capability

use of com.cloud.network.Network.Capability in project cloudstack by apache.

the class VpcVirtualRouterElement method startSite2SiteVpn.

@Override
public boolean startSite2SiteVpn(final Site2SiteVpnConnection conn) throws ResourceUnavailableException {
    final Site2SiteVpnGateway vpnGw = _vpnGatewayDao.findById(conn.getVpnGatewayId());
    final IpAddress ip = _ipAddressDao.findById(vpnGw.getAddrId());
    final Map<Capability, String> vpnCapabilities = capabilities.get(Service.Vpn);
    if (!vpnCapabilities.get(Capability.VpnTypes).contains("s2svpn")) {
        s_logger.error("try to start site 2 site vpn on unsupported network element?");
        return false;
    }
    final Long vpcId = ip.getVpcId();
    final Vpc vpc = _entityMgr.findById(Vpc.class, vpcId);
    if (!_ntwkModel.isProviderEnabledInZone(vpc.getZoneId(), Provider.VPCVirtualRouter.getName())) {
        throw new ResourceUnavailableException("VPC provider is not enabled in zone " + vpc.getZoneId(), DataCenter.class, vpc.getZoneId());
    }
    final List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(ip.getVpcId());
    if (routers == null) {
        throw new ResourceUnavailableException("Cannot enable site-to-site VPN on the backend; virtual router doesn't exist in the vpc " + ip.getVpcId(), DataCenter.class, vpc.getZoneId());
    }
    boolean result = true;
    for (final DomainRouterVO domainRouterVO : routers) {
        result = result && _vpcRouterMgr.startSite2SiteVpn(conn, domainRouterVO);
    }
    return result;
}
Also used : Site2SiteVpnGateway(com.cloud.network.Site2SiteVpnGateway) Capability(com.cloud.network.Network.Capability) Vpc(com.cloud.network.vpc.Vpc) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 4 with Capability

use of com.cloud.network.Network.Capability in project cloudstack by apache.

the class NetworkOrchestrator method prepareElement.

protected boolean prepareElement(final NetworkElement element, final Network network, final NicProfile profile, final VirtualMachineProfile vmProfile, final DeployDestination dest, final ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
    element.prepare(network, profile, vmProfile, dest, context);
    if (vmProfile.getType() == Type.User && element.getProvider() != null) {
        if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Dhcp) && _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp, element.getProvider()) && element instanceof DhcpServiceProvider) {
            final DhcpServiceProvider sp = (DhcpServiceProvider) element;
            final Map<Capability, String> dhcpCapabilities = element.getCapabilities().get(Service.Dhcp);
            final String supportsMultipleSubnets = dhcpCapabilities.get(Capability.DhcpAccrossMultipleSubnets);
            if (supportsMultipleSubnets != null && Boolean.valueOf(supportsMultipleSubnets) && profile.getIPv6Address() == null) {
                if (!sp.configDhcpSupportForSubnet(network, profile, vmProfile, dest, context)) {
                    return false;
                }
            }
            if (!sp.addDhcpEntry(network, profile, vmProfile, dest, context)) {
                return false;
            }
        }
        if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Dns) && _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dns, element.getProvider()) && element instanceof DnsServiceProvider) {
            final DnsServiceProvider sp = (DnsServiceProvider) element;
            if (profile.getIPv6Address() == null) {
                if (!sp.configDnsSupportForSubnet(network, profile, vmProfile, dest, context)) {
                    return false;
                }
            }
            if (!sp.addDnsEntry(network, profile, vmProfile, dest, context)) {
                return false;
            }
        }
        if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.UserData) && _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.UserData, element.getProvider()) && element instanceof UserDataServiceProvider) {
            final UserDataServiceProvider sp = (UserDataServiceProvider) element;
            if (!sp.addPasswordAndUserdata(network, profile, vmProfile, dest, context)) {
                return false;
            }
        }
    }
    return true;
}
Also used : Capability(com.cloud.network.Network.Capability) DnsServiceProvider(com.cloud.network.element.DnsServiceProvider) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider)

Example 5 with Capability

use of com.cloud.network.Network.Capability in project cloudstack by apache.

the class NetworkServiceImpl method getNetworkOfferingServiceCapabilities.

@Override
public Map<Capability, String> getNetworkOfferingServiceCapabilities(NetworkOffering offering, Service service) {
    if (!areServicesSupportedByNetworkOffering(offering.getId(), service)) {
        // TBD: We should be sending networkOfferingId and not the offering object itself.
        throw new UnsupportedServiceException("Service " + service.getName() + " is not supported by the network offering " + offering);
    }
    Map<Capability, String> serviceCapabilities = new HashMap<Capability, String>();
    // get the Provider for this Service for this offering
    List<String> providers = _ntwkOfferingSrvcDao.listProvidersForServiceForNetworkOffering(offering.getId(), service);
    if (providers.isEmpty()) {
        // TBD: We should be sending networkOfferingId and not the offering object itself.
        throw new InvalidParameterValueException("Service " + service.getName() + " is not supported by the network offering " + offering);
    }
    // FIXME - in post 3.0 we are going to support multiple providers for the same service per network offering, so
    // we have to calculate capabilities for all of them
    String provider = providers.get(0);
    // FIXME we return the capabilities of the first provider of the service - what if we have multiple providers
    // for same Service?
    NetworkElement element = _networkModel.getElementImplementingProvider(provider);
    if (element != null) {
        Map<Service, Map<Capability, String>> elementCapabilities = element.getCapabilities();
        ;
        if (elementCapabilities == null || !elementCapabilities.containsKey(service)) {
            // TBD: We should be sending providerId and not the offering object itself.
            throw new UnsupportedServiceException("Service " + service.getName() + " is not supported by the element=" + element.getName() + " implementing Provider=" + provider);
        }
        serviceCapabilities = elementCapabilities.get(service);
    }
    return serviceCapabilities;
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) Capability(com.cloud.network.Network.Capability) HashMap(java.util.HashMap) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) LoadBalancingRulesService(com.cloud.network.lb.LoadBalancingRulesService) SecurityGroupService(com.cloud.network.security.SecurityGroupService) ResourceLimitService(com.cloud.user.ResourceLimitService) InternalLoadBalancerElementService(org.apache.cloudstack.network.element.InternalLoadBalancerElementService) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Capability (com.cloud.network.Network.Capability)28 HashMap (java.util.HashMap)19 Service (com.cloud.network.Network.Service)17 Map (java.util.Map)16 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)12 Provider (com.cloud.network.Network.Provider)8 NetworkElement (com.cloud.network.element.NetworkElement)8 ArrayList (java.util.ArrayList)7 NetworkOrchestrationService (org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService)7 ResourceLimitService (com.cloud.user.ResourceLimitService)6 UnsupportedServiceException (com.cloud.exception.UnsupportedServiceException)5 Network (com.cloud.network.Network)5 NetworkService (com.cloud.network.NetworkService)4 PhysicalNetwork (com.cloud.network.PhysicalNetwork)4 UserDataServiceProvider (com.cloud.network.element.UserDataServiceProvider)4 HashSet (java.util.HashSet)4 Vpc (com.cloud.network.vpc.Vpc)3 Collection (java.util.Collection)3 Iterator (java.util.Iterator)3 Set (java.util.Set)3