Search in sources :

Example 11 with Capability

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

the class NetscalerElement method getCapabilities.

@Override
public Map<Service, Map<Capability, String>> getCapabilities() {
    Map<Service, Map<Capability, String>> capabilities = new HashMap<Service, Map<Capability, String>>();
    // Set capabilities for LB service
    Map<Capability, String> lbCapabilities = new HashMap<Capability, String>();
    // Specifies that the RoundRobin and Leastconn algorithms are supported for load balancing rules
    lbCapabilities.put(Capability.SupportedLBAlgorithms, "roundrobin, leastconn, source");
    // specifies that Netscaler network element can provided both shared and isolation modes
    lbCapabilities.put(Capability.SupportedLBIsolation, "dedicated, shared");
    // Specifies that load balancing rules can be made for either TCP or UDP traffic
    lbCapabilities.put(Capability.SupportedProtocols, "tcp,udp");
    // Specifies that this element can measure network usage on a per public IP basis
    lbCapabilities.put(Capability.TrafficStatistics, "per public ip");
    // Specifies that load balancing rules can only be made with public IPs that aren't source NAT IPs
    lbCapabilities.put(Capability.LoadBalancingSupportedIps, "additional");
    // Supports only Public load balancing
    lbCapabilities.put(Capability.LbSchemes, LoadBalancerContainer.Scheme.Public.toString());
    // Specifies that load balancing rules can support autoscaling and the list of counters it supports
    AutoScaleCounter counter;
    List<AutoScaleCounter> counterList = new ArrayList<AutoScaleCounter>();
    counter = new AutoScaleCounter(AutoScaleCounterSnmp);
    counterList.add(counter);
    counter.addParam("snmpcommunity", true, "the community string that has to be used to do a SNMP GET on the AutoScaled Vm", false);
    counter.addParam("snmpport", false, "the port at which SNMP agent is running on the AutoScaled Vm", false);
    counter = new AutoScaleCounter(AutoScaleCounterNetscaler);
    counterList.add(counter);
    Gson gson = new Gson();
    String autoScaleCounterList = gson.toJson(counterList);
    lbCapabilities.put(Capability.AutoScaleCounters, autoScaleCounterList);
    LbStickinessMethod method;
    List<LbStickinessMethod> methodList = new ArrayList<LbStickinessMethod>();
    method = new LbStickinessMethod(StickinessMethodType.LBCookieBased, "This is cookie based sticky method, can be used only for http");
    methodList.add(method);
    method.addParam("holdtime", false, "time period in minutes for which persistence is in effect.", false);
    method = new LbStickinessMethod(StickinessMethodType.AppCookieBased, "This is app session based sticky method, can be used only for http");
    methodList.add(method);
    method.addParam("name", true, "cookie name passed in http header by apllication to the client", false);
    method = new LbStickinessMethod(StickinessMethodType.SourceBased, "This is source based sticky method, can be used for any type of protocol.");
    methodList.add(method);
    method.addParam("holdtime", false, "time period for which persistence is in effect.", false);
    String stickyMethodList = gson.toJson(methodList);
    lbCapabilities.put(Capability.SupportedStickinessMethods, stickyMethodList);
    lbCapabilities.put(Capability.ElasticLb, "true");
    //Setting HealthCheck Capability to True for Netscaler element
    lbCapabilities.put(Capability.HealthCheckPolicy, "true");
    capabilities.put(Service.Lb, lbCapabilities);
    Map<Capability, String> staticNatCapabilities = new HashMap<Capability, String>();
    staticNatCapabilities.put(Capability.ElasticIp, "true");
    capabilities.put(Service.StaticNat, staticNatCapabilities);
    // Supports SSL offloading
    lbCapabilities.put(Capability.SslTermination, "true");
    // TODO - Murali, please put correct capabilities here
    Map<Capability, String> firewallCapabilities = new HashMap<Capability, String>();
    firewallCapabilities.put(Capability.TrafficStatistics, "per public ip");
    firewallCapabilities.put(Capability.SupportedProtocols, "tcp,udp,icmp");
    firewallCapabilities.put(Capability.MultipleIps, "true");
    capabilities.put(Service.Firewall, firewallCapabilities);
    return capabilities;
}
Also used : AutoScaleCounter(com.cloud.network.as.AutoScaleCounter) Capability(com.cloud.network.Network.Capability) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) Gson(com.google.gson.Gson) LbStickinessMethod(com.cloud.network.rules.LbStickinessMethod) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 with Capability

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

the class ConfigurationManagerImpl method createVlanAndPublicIpRange.

@Override
@DB
public Vlan createVlanAndPublicIpRange(final long zoneId, final long networkId, final long physicalNetworkId, final boolean forVirtualNetwork, final Long podId, final String startIP, final String endIP, final String vlanGateway, final String vlanNetmask, String vlanId, Domain domain, final Account vlanOwner, final String startIPv6, final String endIPv6, final String vlanIp6Gateway, final String vlanIp6Cidr) {
    final Network network = _networkModel.getNetwork(networkId);
    boolean ipv4 = false, ipv6 = false;
    if (startIP != null) {
        ipv4 = true;
    }
    if (startIPv6 != null) {
        ipv6 = true;
    }
    if (!ipv4 && !ipv6) {
        throw new InvalidParameterValueException("Please specify IPv4 or IPv6 address.");
    }
    // Validate the zone
    final DataCenterVO zone = _zoneDao.findById(zoneId);
    if (zone == null) {
        throw new InvalidParameterValueException("Please specify a valid zone.");
    }
    // ACL check
    checkZoneAccess(CallContext.current().getCallingAccount(), zone);
    // Validate the physical network
    if (_physicalNetworkDao.findById(physicalNetworkId) == null) {
        throw new InvalidParameterValueException("Please specify a valid physical network id");
    }
    // Validate the pod
    if (podId != null) {
        final Pod pod = _podDao.findById(podId);
        if (pod == null) {
            throw new InvalidParameterValueException("Please specify a valid pod.");
        }
        if (pod.getDataCenterId() != zoneId) {
            throw new InvalidParameterValueException("Pod id=" + podId + " doesn't belong to zone id=" + zoneId);
        }
        // pod vlans can be created in basic zone only
        if (zone.getNetworkType() != NetworkType.Basic || network.getTrafficType() != TrafficType.Guest) {
            throw new InvalidParameterValueException("Pod id can be specified only for the networks of type " + TrafficType.Guest + " in zone of type " + NetworkType.Basic);
        }
    }
    // 2) if vlan is missing, default it to the guest network's vlan
    if (network.getTrafficType() == TrafficType.Guest) {
        String networkVlanId = null;
        boolean connectivityWithoutVlan = false;
        if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Connectivity)) {
            Map<Capability, String> connectivityCapabilities = _networkModel.getNetworkServiceCapabilities(network.getId(), Service.Connectivity);
            connectivityWithoutVlan = MapUtils.isNotEmpty(connectivityCapabilities) && connectivityCapabilities.containsKey(Capability.NoVlan);
        }
        final URI uri = network.getBroadcastUri();
        if (connectivityWithoutVlan) {
            networkVlanId = network.getBroadcastDomainType().toUri(network.getUuid()).toString();
        } else if (uri != null) {
            // Do not search for the VLAN tag when the network doesn't support VLAN
            if (uri.toString().startsWith("vlan")) {
                final String[] vlan = uri.toString().split("vlan:\\/\\/");
                networkVlanId = vlan[1];
                // For pvlan
                networkVlanId = networkVlanId.split("-")[0];
            }
        }
        if (vlanId != null && !connectivityWithoutVlan) {
            // network's vlanId
            if (networkVlanId != null && !NetUtils.isSameIsolationId(networkVlanId, vlanId)) {
                throw new InvalidParameterValueException("Vlan doesn't match vlan of the network");
            }
        } else {
            vlanId = networkVlanId;
        }
    } else if (network.getTrafficType() == TrafficType.Public && vlanId == null) {
        throw new InvalidParameterValueException("Unable to determine vlan id or untagged vlan for public network");
    }
    if (vlanId == null) {
        vlanId = Vlan.UNTAGGED;
    }
    final VlanType vlanType = forVirtualNetwork ? VlanType.VirtualNetwork : VlanType.DirectAttached;
    if ((domain != null || vlanOwner != null) && zone.getNetworkType() != NetworkType.Advanced) {
        throw new InvalidParameterValueException("Vlan owner can be defined only in the zone of type " + NetworkType.Advanced);
    }
    if (ipv4) {
        // Make sure the gateway is valid
        if (!NetUtils.isValidIp(vlanGateway)) {
            throw new InvalidParameterValueException("Please specify a valid gateway");
        }
        // Make sure the netmask is valid
        if (!NetUtils.isValidNetmask(vlanNetmask)) {
            throw new InvalidParameterValueException("Please specify a valid netmask");
        }
    }
    if (ipv6) {
        if (!NetUtils.isValidIpv6(vlanIp6Gateway)) {
            throw new InvalidParameterValueException("Please specify a valid IPv6 gateway");
        }
        if (!NetUtils.isValidIp6Cidr(vlanIp6Cidr)) {
            throw new InvalidParameterValueException("Please specify a valid IPv6 CIDR");
        }
    }
    if (ipv4) {
        final String newCidr = NetUtils.getCidrFromGatewayAndNetmask(vlanGateway, vlanNetmask);
        //Make sure start and end ips are with in the range of cidr calculated for this gateway and netmask {
        if (!NetUtils.isIpWithtInCidrRange(vlanGateway, newCidr) || !NetUtils.isIpWithtInCidrRange(startIP, newCidr) || !NetUtils.isIpWithtInCidrRange(endIP, newCidr)) {
            throw new InvalidParameterValueException("Please specify a valid IP range or valid netmask or valid gateway");
        }
        // Check if the new VLAN's subnet conflicts with the guest network
        // in
        // the specified zone (guestCidr is null for basic zone)
        // when adding shared network with same cidr of zone guest cidr,
        // if the specified vlan is not present in zone, physical network, allow to create the network as the isolation is based on VLAN.
        final String guestNetworkCidr = zone.getGuestNetworkCidr();
        if (guestNetworkCidr != null && NetUtils.isNetworksOverlap(newCidr, guestNetworkCidr) && _zoneDao.findVnet(zoneId, physicalNetworkId, vlanId).isEmpty() != true) {
            throw new InvalidParameterValueException("The new IP range you have specified has  overlapped with the guest network in zone: " + zone.getName() + "along with existing Vlan also. Please specify a different gateway/netmask");
        }
        // Check if there are any errors with the IP range
        checkPublicIpRangeErrors(zoneId, vlanId, vlanGateway, vlanNetmask, startIP, endIP);
        checkConflictsWithPortableIpRange(zoneId, vlanId, vlanGateway, vlanNetmask, startIP, endIP);
        // Throw an exception if this subnet overlaps with subnet on other VLAN,
        // if this is ip range extension, gateway, network mask should be same and ip range should not overlap
        final List<VlanVO> vlans = _vlanDao.listByZone(zone.getId());
        for (final VlanVO vlan : vlans) {
            final String otherVlanGateway = vlan.getVlanGateway();
            final String otherVlanNetmask = vlan.getVlanNetmask();
            // Continue if it's not IPv4
            if (otherVlanGateway == null || otherVlanNetmask == null) {
                continue;
            }
            if (vlan.getNetworkId() == null) {
                continue;
            }
            final String otherCidr = NetUtils.getCidrFromGatewayAndNetmask(otherVlanGateway, otherVlanNetmask);
            if (!NetUtils.isNetworksOverlap(newCidr, otherCidr)) {
                continue;
            }
            // from here, subnet overlaps
            if (!vlanId.equals(vlan.getVlanTag())) {
                boolean overlapped = false;
                if (network.getTrafficType() == TrafficType.Public) {
                    overlapped = true;
                } else {
                    final Long nwId = vlan.getNetworkId();
                    if (nwId != null) {
                        final Network nw = _networkModel.getNetwork(nwId);
                        if (nw != null && nw.getTrafficType() == TrafficType.Public) {
                            overlapped = true;
                        }
                    }
                }
                if (overlapped) {
                    throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + " in zone " + zone.getName() + " has overlapped with the subnet. Please specify a different gateway/netmask.");
                }
            } else {
                final String[] otherVlanIpRange = vlan.getIpRange().split("\\-");
                final String otherVlanStartIP = otherVlanIpRange[0];
                String otherVlanEndIP = null;
                if (otherVlanIpRange.length > 1) {
                    otherVlanEndIP = otherVlanIpRange[1];
                }
                // extend IP range
                if (!vlanGateway.equals(otherVlanGateway) || !vlanNetmask.equals(vlan.getVlanNetmask())) {
                    throw new InvalidParameterValueException("The IP range has already been added with gateway " + otherVlanGateway + " ,and netmask " + otherVlanNetmask + ", Please specify the gateway/netmask if you want to extend ip range");
                }
                if (!NetUtils.is31PrefixCidr(newCidr)) {
                    if (NetUtils.ipRangesOverlap(startIP, endIP, otherVlanStartIP, otherVlanEndIP)) {
                        throw new InvalidParameterValueException("The IP range already has IPs that overlap with the new range." + " Please specify a different start IP/end IP.");
                    }
                }
            }
        }
    }
    String ipv6Range = null;
    if (ipv6) {
        ipv6Range = startIPv6;
        if (endIPv6 != null) {
            ipv6Range += "-" + endIPv6;
        }
        final List<VlanVO> vlans = _vlanDao.listByZone(zone.getId());
        for (final VlanVO vlan : vlans) {
            if (vlan.getIp6Gateway() == null) {
                continue;
            }
            if (NetUtils.isSameIsolationId(vlanId, vlan.getVlanTag())) {
                if (NetUtils.isIp6RangeOverlap(ipv6Range, vlan.getIp6Range())) {
                    throw new InvalidParameterValueException("The IPv6 range with tag: " + vlan.getVlanTag() + " already has IPs that overlap with the new range. Please specify a different start IP/end IP.");
                }
                if (!vlanIp6Gateway.equals(vlan.getIp6Gateway())) {
                    throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + " has already been added with gateway " + vlan.getIp6Gateway() + ". Please specify a different tag.");
                }
            }
        }
    }
    // Check if the vlan is being used
    if (_zoneDao.findVnet(zoneId, physicalNetworkId, vlanId).size() > 0) {
        throw new InvalidParameterValueException("The VLAN tag " + vlanId + " is already being used for dynamic vlan allocation for the guest network in zone " + zone.getName());
    }
    String ipRange = null;
    if (ipv4) {
        ipRange = startIP;
        if (endIP != null) {
            ipRange += "-" + endIP;
        }
    }
    // Everything was fine, so persist the VLAN
    final VlanVO vlan = commitVlanAndIpRange(zoneId, networkId, physicalNetworkId, podId, startIP, endIP, vlanGateway, vlanNetmask, vlanId, domain, vlanOwner, vlanIp6Gateway, vlanIp6Cidr, ipv4, zone, vlanType, ipv6Range, ipRange);
    return vlan;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Pod(com.cloud.dc.Pod) Capability(com.cloud.network.Network.Capability) URI(java.net.URI) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) VlanVO(com.cloud.dc.VlanVO) VlanType(com.cloud.dc.Vlan.VlanType) DB(com.cloud.utils.db.DB)

Example 13 with Capability

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

the class ApiResponseHelper method createNetworkServiceResponse.

@Override
public ServiceResponse createNetworkServiceResponse(Service service) {
    ServiceResponse response = new ServiceResponse();
    response.setName(service.getName());
    // set list of capabilities required for the service
    List<CapabilityResponse> capabilityResponses = new ArrayList<CapabilityResponse>();
    Capability[] capabilities = service.getCapabilities();
    for (Capability cap : capabilities) {
        CapabilityResponse capabilityResponse = new CapabilityResponse();
        capabilityResponse.setName(cap.getName());
        capabilityResponse.setObjectName("capability");
        if (cap.getName().equals(Capability.SupportedLBIsolation.getName()) || cap.getName().equals(Capability.SupportedSourceNatTypes.getName()) || cap.getName().equals(Capability.RedundantRouter.getName())) {
            capabilityResponse.setCanChoose(true);
        } else {
            capabilityResponse.setCanChoose(false);
        }
        capabilityResponses.add(capabilityResponse);
    }
    response.setCapabilities(capabilityResponses);
    // set list of providers providing this service
    List<? extends Network.Provider> serviceProviders = ApiDBUtils.getProvidersForService(service);
    List<ProviderResponse> serviceProvidersResponses = new ArrayList<ProviderResponse>();
    for (Network.Provider serviceProvider : serviceProviders) {
        // return only Virtual Router/JuniperSRX/CiscoVnmc as a provider for the firewall
        if (service == Service.Firewall && !(serviceProvider == Provider.VirtualRouter || serviceProvider == Provider.JuniperSRX || serviceProvider == Provider.CiscoVnmc || serviceProvider == Provider.PaloAlto || serviceProvider == Provider.NuageVsp || serviceProvider == Provider.BigSwitchBcf)) {
            continue;
        }
        ProviderResponse serviceProviderResponse = createServiceProviderResponse(serviceProvider);
        serviceProvidersResponses.add(serviceProviderResponse);
    }
    response.setProviders(serviceProvidersResponses);
    response.setObjectName("networkservice");
    return response;
}
Also used : ServiceResponse(org.apache.cloudstack.api.response.ServiceResponse) ProviderResponse(org.apache.cloudstack.api.response.ProviderResponse) VirtualRouterProviderResponse(org.apache.cloudstack.api.response.VirtualRouterProviderResponse) OvsProviderResponse(org.apache.cloudstack.api.response.OvsProviderResponse) Capability(com.cloud.network.Network.Capability) Provider(com.cloud.network.Network.Provider) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) ArrayList(java.util.ArrayList) CapabilityResponse(org.apache.cloudstack.api.response.CapabilityResponse)

Example 14 with Capability

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

the class ApiResponseHelper method createNetworkResponse.

@Override
public NetworkResponse createNetworkResponse(ResponseView view, Network network) {
    // need to get network profile in order to retrieve dns information from
    // there
    NetworkProfile profile = ApiDBUtils.getNetworkProfile(network.getId());
    NetworkResponse response = new NetworkResponse();
    response.setId(network.getUuid());
    response.setName(network.getName());
    response.setDisplaytext(network.getDisplayText());
    if (network.getBroadcastDomainType() != null) {
        response.setBroadcastDomainType(network.getBroadcastDomainType().toString());
    }
    if (network.getTrafficType() != null) {
        response.setTrafficType(network.getTrafficType().name());
    }
    if (network.getGuestType() != null) {
        response.setType(network.getGuestType().toString());
    }
    response.setGateway(network.getGateway());
    // FIXME - either set netmask or cidr
    response.setCidr(network.getCidr());
    response.setNetworkCidr((network.getNetworkCidr()));
    // network cidr
    if (network.getNetworkCidr() != null) {
        response.setNetmask(NetUtils.cidr2Netmask(network.getNetworkCidr()));
    }
    if (((network.getCidr()) != null) && (network.getNetworkCidr() == null)) {
        response.setNetmask(NetUtils.cidr2Netmask(network.getCidr()));
    }
    response.setIp6Gateway(network.getIp6Gateway());
    response.setIp6Cidr(network.getIp6Cidr());
    // create response for reserved IP ranges that can be used for
    // non-cloudstack purposes
    String reservation = null;
    if ((network.getCidr() != null) && (NetUtils.isNetworkAWithinNetworkB(network.getCidr(), network.getNetworkCidr()))) {
        String[] guestVmCidrPair = network.getCidr().split("\\/");
        String[] guestCidrPair = network.getNetworkCidr().split("\\/");
        Long guestVmCidrSize = Long.valueOf(guestVmCidrPair[1]);
        Long guestCidrSize = Long.valueOf(guestCidrPair[1]);
        String[] guestVmIpRange = NetUtils.getIpRangeFromCidr(guestVmCidrPair[0], guestVmCidrSize);
        String[] guestIpRange = NetUtils.getIpRangeFromCidr(guestCidrPair[0], guestCidrSize);
        long startGuestIp = NetUtils.ip2Long(guestIpRange[0]);
        long endGuestIp = NetUtils.ip2Long(guestIpRange[1]);
        long startVmIp = NetUtils.ip2Long(guestVmIpRange[0]);
        long endVmIp = NetUtils.ip2Long(guestVmIpRange[1]);
        if (startVmIp == startGuestIp && endVmIp < endGuestIp - 1) {
            reservation = (NetUtils.long2Ip(endVmIp + 1) + "-" + NetUtils.long2Ip(endGuestIp));
        }
        if (endVmIp == endGuestIp && startVmIp > startGuestIp + 1) {
            reservation = (NetUtils.long2Ip(startGuestIp) + "-" + NetUtils.long2Ip(startVmIp - 1));
        }
        if (startVmIp > startGuestIp + 1 && endVmIp < endGuestIp - 1) {
            reservation = (NetUtils.long2Ip(startGuestIp) + "-" + NetUtils.long2Ip(startVmIp - 1) + " ,  " + NetUtils.long2Ip(endVmIp + 1) + "-" + NetUtils.long2Ip(endGuestIp));
        }
    }
    response.setReservedIpRange(reservation);
    // return vlan information only to Root admin
    if (network.getBroadcastUri() != null && view == ResponseView.Full) {
        String broadcastUri = network.getBroadcastUri().toString();
        response.setBroadcastUri(broadcastUri);
        String vlan = "N/A";
        switch(BroadcastDomainType.getSchemeValue(network.getBroadcastUri())) {
            case Vlan:
            case Vxlan:
                vlan = BroadcastDomainType.getValue(network.getBroadcastUri());
                break;
        }
        // return vlan information only to Root admin
        response.setVlan(vlan);
    }
    DataCenter zone = ApiDBUtils.findZoneById(network.getDataCenterId());
    if (zone != null) {
        response.setZoneId(zone.getUuid());
        response.setZoneName(zone.getName());
    }
    if (network.getPhysicalNetworkId() != null) {
        PhysicalNetworkVO pnet = ApiDBUtils.findPhysicalNetworkById(network.getPhysicalNetworkId());
        response.setPhysicalNetworkId(pnet.getUuid());
    }
    // populate network offering information
    NetworkOffering networkOffering = ApiDBUtils.findNetworkOfferingById(network.getNetworkOfferingId());
    if (networkOffering != null) {
        response.setNetworkOfferingId(networkOffering.getUuid());
        response.setNetworkOfferingName(networkOffering.getName());
        response.setNetworkOfferingDisplayText(networkOffering.getDisplayText());
        response.setNetworkOfferingConserveMode(networkOffering.isConserveMode());
        response.setIsSystem(networkOffering.isSystemOnly());
        response.setNetworkOfferingAvailability(networkOffering.getAvailability().toString());
        response.setIsPersistent(networkOffering.getIsPersistent());
    }
    if (network.getAclType() != null) {
        response.setAclType(network.getAclType().toString());
    }
    response.setDisplayNetwork(network.getDisplayNetwork());
    response.setState(network.getState().toString());
    response.setRestartRequired(network.isRestartRequired());
    NetworkVO nw = ApiDBUtils.findNetworkById(network.getRelated());
    if (nw != null) {
        response.setRelated(nw.getUuid());
    }
    response.setNetworkDomain(network.getNetworkDomain());
    response.setDns1(profile.getDns1());
    response.setDns2(profile.getDns2());
    // populate capability
    Map<Service, Map<Capability, String>> serviceCapabilitiesMap = ApiDBUtils.getNetworkCapabilities(network.getId(), network.getDataCenterId());
    List<ServiceResponse> serviceResponses = new ArrayList<ServiceResponse>();
    if (serviceCapabilitiesMap != null) {
        for (Map.Entry<Service, Map<Capability, String>> entry : serviceCapabilitiesMap.entrySet()) {
            Service service = entry.getKey();
            ServiceResponse serviceResponse = new ServiceResponse();
            // skip gateway service
            if (service == Service.Gateway) {
                continue;
            }
            serviceResponse.setName(service.getName());
            // set list of capabilities for the service
            List<CapabilityResponse> capabilityResponses = new ArrayList<CapabilityResponse>();
            Map<Capability, String> serviceCapabilities = entry.getValue();
            if (serviceCapabilities != null) {
                for (Map.Entry<Capability, String> ser_cap_entries : serviceCapabilities.entrySet()) {
                    Capability capability = ser_cap_entries.getKey();
                    CapabilityResponse capabilityResponse = new CapabilityResponse();
                    String capabilityValue = ser_cap_entries.getValue();
                    capabilityResponse.setName(capability.getName());
                    capabilityResponse.setValue(capabilityValue);
                    capabilityResponse.setObjectName("capability");
                    capabilityResponses.add(capabilityResponse);
                }
                serviceResponse.setCapabilities(capabilityResponses);
            }
            serviceResponse.setObjectName("service");
            serviceResponses.add(serviceResponse);
        }
    }
    response.setServices(serviceResponses);
    if (network.getAclType() == null || network.getAclType() == ACLType.Account) {
        populateOwner(response, network);
    } else {
        // get domain from network_domain table
        Pair<Long, Boolean> domainNetworkDetails = ApiDBUtils.getDomainNetworkDetails(network.getId());
        if (domainNetworkDetails.first() != null) {
            Domain domain = ApiDBUtils.findDomainById(domainNetworkDetails.first());
            if (domain != null) {
                response.setDomainId(domain.getUuid());
            }
        }
        response.setSubdomainAccess(domainNetworkDetails.second());
    }
    Long dedicatedDomainId = ApiDBUtils.getDedicatedNetworkDomain(network.getId());
    if (dedicatedDomainId != null) {
        Domain domain = ApiDBUtils.findDomainById(dedicatedDomainId);
        if (domain != null) {
            response.setDomainId(domain.getUuid());
            response.setDomainName(domain.getName());
        }
    }
    response.setSpecifyIpRanges(network.getSpecifyIpRanges());
    if (network.getVpcId() != null) {
        Vpc vpc = ApiDBUtils.findVpcById(network.getVpcId());
        if (vpc != null) {
            response.setVpcId(vpc.getUuid());
        }
    }
    response.setCanUseForDeploy(ApiDBUtils.canUseForDeploy(network));
    // set tag information
    List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.Network, network.getId());
    List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
    for (ResourceTag tag : tags) {
        ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
        CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
    }
    response.setTags(tagResponses);
    if (network.getNetworkACLId() != null) {
        NetworkACL acl = ApiDBUtils.findByNetworkACLId(network.getNetworkACLId());
        if (acl != null) {
            response.setAclId(acl.getUuid());
        }
    }
    response.setStrechedL2Subnet(network.isStrechedL2Network());
    if (network.isStrechedL2Network()) {
        Set<String> networkSpannedZones = new HashSet<String>();
        List<VMInstanceVO> vmInstances = new ArrayList<VMInstanceVO>();
        vmInstances.addAll(ApiDBUtils.listUserVMsByNetworkId(network.getId()));
        vmInstances.addAll(ApiDBUtils.listDomainRoutersByNetworkId(network.getId()));
        for (VirtualMachine vm : vmInstances) {
            DataCenter vmZone = ApiDBUtils.findZoneById(vm.getDataCenterId());
            networkSpannedZones.add(vmZone.getUuid());
        }
        response.setNetworkSpannedZones(networkSpannedZones);
    }
    response.setObjectName("network");
    return response;
}
Also used : ArrayList(java.util.ArrayList) Vpc(com.cloud.network.vpc.Vpc) NetworkACL(com.cloud.network.vpc.NetworkACL) CapabilityResponse(org.apache.cloudstack.api.response.CapabilityResponse) ServiceResponse(org.apache.cloudstack.api.response.ServiceResponse) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ResourceTagResponse(org.apache.cloudstack.api.response.ResourceTagResponse) HashSet(java.util.HashSet) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) Capability(com.cloud.network.Network.Capability) NetworkOffering(com.cloud.offering.NetworkOffering) Service(com.cloud.network.Network.Service) UsageService(org.apache.cloudstack.usage.UsageService) VMInstanceVO(com.cloud.vm.VMInstanceVO) NetworkProfile(com.cloud.network.NetworkProfile) DataCenter(com.cloud.dc.DataCenter) ResourceTag(com.cloud.server.ResourceTag) NetworkResponse(org.apache.cloudstack.api.response.NetworkResponse) PhysicalNetworkResponse(org.apache.cloudstack.api.response.PhysicalNetworkResponse) Domain(com.cloud.domain.Domain) Map(java.util.Map) HashMap(java.util.HashMap) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 15 with Capability

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

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 = svcCapabilityMap.get("service");
            String capabilityName = svcCapabilityMap.get("capabilitytype");
            String capabilityValue = 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)

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