Search in sources :

Example 46 with NetworkOfferingVO

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

the class CreateNetworkOfferingTest method createIsolatedNtwkOffWithSpecifyIpRangesAndSourceNat.

@Test(expected = InvalidParameterValueException.class)
public void createIsolatedNtwkOffWithSpecifyIpRangesAndSourceNat() {
    Map<Service, Set<Provider>> serviceProviderMap = new HashMap<Network.Service, Set<Network.Provider>>();
    Set<Network.Provider> vrProvider = new HashSet<Network.Provider>();
    vrProvider.add(Provider.VirtualRouter);
    serviceProviderMap.put(Network.Service.SourceNat, vrProvider);
    NetworkOfferingVO off = configMgr.createNetworkOffering("isolated", "isolated", TrafficType.Guest, null, false, Availability.Optional, 200, serviceProviderMap, false, Network.GuestType.Isolated, false, null, false, null, true, false, null, false, null, true);
    assertNull("Isolated network offering with specifyIpRanges=true and source nat service enabled, was created", off);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Network(com.cloud.network.Network) Service(com.cloud.network.Network.Service) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) Provider(com.cloud.network.Network.Provider) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 47 with NetworkOfferingVO

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

the class NetworkServiceImpl method searchForNetworks.

@Override
public Pair<List<? extends Network>, Integer> searchForNetworks(ListNetworksCmd cmd) {
    Long id = cmd.getId();
    String keyword = cmd.getKeyword();
    Long zoneId = cmd.getZoneId();
    Account caller = CallContext.current().getCallingAccount();
    Long domainId = cmd.getDomainId();
    String accountName = cmd.getAccountName();
    String guestIpType = cmd.getGuestIpType();
    String trafficType = cmd.getTrafficType();
    Boolean isSystem = cmd.getIsSystem();
    String aclType = cmd.getAclType();
    Long projectId = cmd.getProjectId();
    List<Long> permittedAccounts = new ArrayList<Long>();
    String path = null;
    Long physicalNetworkId = cmd.getPhysicalNetworkId();
    List<String> supportedServicesStr = cmd.getSupportedServices();
    Boolean restartRequired = cmd.getRestartRequired();
    boolean listAll = cmd.listAll();
    boolean isRecursive = cmd.isRecursive();
    Boolean specifyIpRanges = cmd.getSpecifyIpRanges();
    Long vpcId = cmd.getVpcId();
    Boolean canUseForDeploy = cmd.canUseForDeploy();
    Map<String, String> tags = cmd.getTags();
    Boolean forVpc = cmd.getForVpc();
    Boolean display = cmd.getDisplay();
    // 2) reset parameter to false if it's specified by the regular user
    if ((isSystem == null || _accountMgr.isNormalUser(caller.getId())) && id == null) {
        isSystem = false;
    }
    // Account/domainId parameters and isSystem are mutually exclusive
    if (isSystem != null && isSystem && (accountName != null || domainId != null)) {
        throw new InvalidParameterValueException("System network belongs to system, account and domainId parameters can't be specified");
    }
    if (domainId != null) {
        DomainVO domain = _domainDao.findById(domainId);
        if (domain == null) {
            // see DomainVO.java
            throw new InvalidParameterValueException("Specified domain id doesn't exist in the system");
        }
        _accountMgr.checkAccess(caller, domain);
        if (accountName != null) {
            Account owner = _accountMgr.getActiveAccountByName(accountName, domainId);
            if (owner == null) {
                // see DomainVO.java
                throw new InvalidParameterValueException("Unable to find account " + accountName + " in specified domain");
            }
            _accountMgr.checkAccess(caller, null, true, owner);
            permittedAccounts.add(owner.getId());
        }
    }
    if (!_accountMgr.isAdmin(caller.getId()) || (projectId != null && projectId.longValue() != -1 && domainId == null)) {
        permittedAccounts.add(caller.getId());
        domainId = caller.getDomainId();
    }
    // set project information
    boolean skipProjectNetworks = true;
    if (projectId != null) {
        if (projectId.longValue() == -1) {
            if (!_accountMgr.isAdmin(caller.getId())) {
                permittedAccounts.addAll(_projectMgr.listPermittedProjectAccounts(caller.getId()));
            }
        } else {
            permittedAccounts.clear();
            Project project = _projectMgr.getProject(projectId);
            if (project == null) {
                throw new InvalidParameterValueException("Unable to find project by specified id");
            }
            if (!_projectMgr.canAccessProjectAccount(caller, project.getProjectAccountId())) {
                // getProject() returns type ProjectVO.
                InvalidParameterValueException ex = new InvalidParameterValueException("Account " + caller + " cannot access specified project id");
                ex.addProxyObject(project.getUuid(), "projectId");
                throw ex;
            }
            //add project account
            permittedAccounts.add(project.getProjectAccountId());
            //add caller account (if admin)
            if (_accountMgr.isAdmin(caller.getId())) {
                permittedAccounts.add(caller.getId());
            }
        }
        skipProjectNetworks = false;
    }
    if (domainId != null) {
        path = _domainDao.findById(domainId).getPath();
    } else {
        path = _domainDao.findById(caller.getDomainId()).getPath();
    }
    if (listAll && domainId == null) {
        isRecursive = true;
    }
    Filter searchFilter = new Filter(NetworkVO.class, "id", false, null, null);
    SearchBuilder<NetworkVO> sb = _networksDao.createSearchBuilder();
    if (forVpc != null) {
        if (forVpc) {
            sb.and("vpc", sb.entity().getVpcId(), Op.NNULL);
        } else {
            sb.and("vpc", sb.entity().getVpcId(), Op.NULL);
        }
    }
    // Don't display networks created of system network offerings
    SearchBuilder<NetworkOfferingVO> networkOfferingSearch = _networkOfferingDao.createSearchBuilder();
    networkOfferingSearch.and("systemOnly", networkOfferingSearch.entity().isSystemOnly(), SearchCriteria.Op.EQ);
    if (isSystem != null && isSystem) {
        networkOfferingSearch.and("trafficType", networkOfferingSearch.entity().getTrafficType(), SearchCriteria.Op.EQ);
    }
    sb.join("networkOfferingSearch", networkOfferingSearch, sb.entity().getNetworkOfferingId(), networkOfferingSearch.entity().getId(), JoinBuilder.JoinType.INNER);
    SearchBuilder<DataCenterVO> zoneSearch = _dcDao.createSearchBuilder();
    zoneSearch.and("networkType", zoneSearch.entity().getNetworkType(), SearchCriteria.Op.EQ);
    sb.join("zoneSearch", zoneSearch, sb.entity().getDataCenterId(), zoneSearch.entity().getId(), JoinBuilder.JoinType.INNER);
    sb.and("removed", sb.entity().getRemoved(), Op.NULL);
    if (tags != null && !tags.isEmpty()) {
        SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
        for (int count = 0; count < tags.size(); count++) {
            tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ);
            tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ);
            tagSearch.cp();
        }
        tagSearch.and("resourceType", tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
        sb.groupBy(sb.entity().getId());
        sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER);
    }
    if (permittedAccounts.isEmpty()) {
        SearchBuilder<DomainVO> domainSearch = _domainDao.createSearchBuilder();
        domainSearch.and("path", domainSearch.entity().getPath(), SearchCriteria.Op.LIKE);
        sb.join("domainSearch", domainSearch, sb.entity().getDomainId(), domainSearch.entity().getId(), JoinBuilder.JoinType.INNER);
    }
    SearchBuilder<AccountVO> accountSearch = _accountDao.createSearchBuilder();
    accountSearch.and("typeNEQ", accountSearch.entity().getType(), SearchCriteria.Op.NEQ);
    accountSearch.and("typeEQ", accountSearch.entity().getType(), SearchCriteria.Op.EQ);
    sb.join("accountSearch", accountSearch, sb.entity().getAccountId(), accountSearch.entity().getId(), JoinBuilder.JoinType.INNER);
    List<NetworkVO> networksToReturn = new ArrayList<NetworkVO>();
    if (isSystem == null || !isSystem) {
        if (!permittedAccounts.isEmpty()) {
            //get account level networks
            networksToReturn.addAll(listAccountSpecificNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags, display), searchFilter, permittedAccounts));
            //get domain level networks
            if (domainId != null) {
                networksToReturn.addAll(listDomainLevelNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, true, restartRequired, specifyIpRanges, vpcId, tags, display), searchFilter, domainId, false));
            }
        } else {
            //add account specific networks
            networksToReturn.addAll(listAccountSpecificNetworksByDomainPath(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags, display), searchFilter, path, isRecursive));
            //add domain specific networks of domain + parent domains
            networksToReturn.addAll(listDomainSpecificNetworksByDomainPath(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags, display), searchFilter, path, isRecursive));
            //add networks of subdomains
            if (domainId == null) {
                networksToReturn.addAll(listDomainLevelNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, true, restartRequired, specifyIpRanges, vpcId, tags, display), searchFilter, caller.getDomainId(), true));
            }
        }
    } else {
        networksToReturn = _networksDao.search(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, null, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags, display), searchFilter);
    }
    if (supportedServicesStr != null && !supportedServicesStr.isEmpty() && !networksToReturn.isEmpty()) {
        List<NetworkVO> supportedNetworks = new ArrayList<NetworkVO>();
        Service[] suppportedServices = new Service[supportedServicesStr.size()];
        int i = 0;
        for (String supportedServiceStr : supportedServicesStr) {
            Service service = Service.getService(supportedServiceStr);
            if (service == null) {
                throw new InvalidParameterValueException("Invalid service specified " + supportedServiceStr);
            } else {
                suppportedServices[i] = service;
            }
            i++;
        }
        for (NetworkVO network : networksToReturn) {
            if (areServicesSupportedInNetwork(network.getId(), suppportedServices)) {
                supportedNetworks.add(network);
            }
        }
        networksToReturn = supportedNetworks;
    }
    if (canUseForDeploy != null) {
        List<NetworkVO> networksForDeploy = new ArrayList<NetworkVO>();
        for (NetworkVO network : networksToReturn) {
            if (_networkModel.canUseForDeploy(network) == canUseForDeploy) {
                networksForDeploy.add(network);
            }
        }
        networksToReturn = networksForDeploy;
    }
    //Now apply pagination
    List<? extends Network> wPagination = StringUtils.applyPagination(networksToReturn, cmd.getStartIndex(), cmd.getPageSizeVal());
    if (wPagination != null) {
        Pair<List<? extends Network>, Integer> listWPagination = new Pair<List<? extends Network>, Integer>(wPagination, networksToReturn.size());
        return listWPagination;
    }
    return new Pair<List<? extends Network>, Integer>(networksToReturn, networksToReturn.size());
}
Also used : Account(com.cloud.user.Account) ArrayList(java.util.ArrayList) AccountVO(com.cloud.user.AccountVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceTagVO(com.cloud.tags.ResourceTagVO) ArrayList(java.util.ArrayList) List(java.util.List) Pair(com.cloud.utils.Pair) DataCenterVO(com.cloud.dc.DataCenterVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) 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) NetworkDomainVO(com.cloud.network.dao.NetworkDomainVO) DomainVO(com.cloud.domain.DomainVO) Project(com.cloud.projects.Project) Filter(com.cloud.utils.db.Filter) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO)

Example 48 with NetworkOfferingVO

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

the class NetworkServiceImpl method createGuestNetwork.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_CREATE, eventDescription = "creating network")
public Network createGuestNetwork(CreateNetworkCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException {
    Long networkOfferingId = cmd.getNetworkOfferingId();
    String gateway = cmd.getGateway();
    String startIP = cmd.getStartIp();
    String endIP = cmd.getEndIp();
    String netmask = cmd.getNetmask();
    String networkDomain = cmd.getNetworkDomain();
    String vlanId = null;
    if (cmd instanceof CreateNetworkCmdByAdmin) {
        vlanId = ((CreateNetworkCmdByAdmin) cmd).getVlan();
    }
    String name = cmd.getNetworkName();
    String displayText = cmd.getDisplayText();
    Account caller = CallContext.current().getCallingAccount();
    Long physicalNetworkId = cmd.getPhysicalNetworkId();
    Long zoneId = cmd.getZoneId();
    String aclTypeStr = cmd.getAclType();
    Long domainId = cmd.getDomainId();
    boolean isDomainSpecific = false;
    Boolean subdomainAccess = cmd.getSubdomainAccess();
    Long vpcId = cmd.getVpcId();
    String startIPv6 = cmd.getStartIpv6();
    String endIPv6 = cmd.getEndIpv6();
    String ip6Gateway = cmd.getIp6Gateway();
    String ip6Cidr = cmd.getIp6Cidr();
    Boolean displayNetwork = cmd.getDisplayNetwork();
    Long aclId = cmd.getAclId();
    String isolatedPvlan = cmd.getIsolatedPvlan();
    // Validate network offering
    NetworkOfferingVO ntwkOff = _networkOfferingDao.findById(networkOfferingId);
    if (ntwkOff == null || ntwkOff.isSystemOnly()) {
        InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find network offering by specified id");
        if (ntwkOff != null) {
            ex.addProxyObject(ntwkOff.getUuid(), "networkOfferingId");
        }
        throw ex;
    }
    // validate physical network and zone
    // Check if physical network exists
    PhysicalNetwork pNtwk = null;
    if (physicalNetworkId != null) {
        pNtwk = _physicalNetworkDao.findById(physicalNetworkId);
        if (pNtwk == null) {
            throw new InvalidParameterValueException("Unable to find a physical network having the specified physical network id");
        }
    }
    if (zoneId == null) {
        zoneId = pNtwk.getDataCenterId();
    }
    if (displayNetwork == null) {
        displayNetwork = true;
    }
    DataCenter zone = _dcDao.findById(zoneId);
    if (zone == null) {
        throw new InvalidParameterValueException("Specified zone id was not found");
    }
    if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getId())) {
        // See DataCenterVO.java
        PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation since specified Zone is currently disabled");
        ex.addProxyObject(zone.getUuid(), "zoneId");
        throw ex;
    }
    // Only domain and account ACL types are supported in Acton.
    ACLType aclType = null;
    if (aclTypeStr != null) {
        if (aclTypeStr.equalsIgnoreCase(ACLType.Account.toString())) {
            aclType = ACLType.Account;
        } else if (aclTypeStr.equalsIgnoreCase(ACLType.Domain.toString())) {
            aclType = ACLType.Domain;
        } else {
            throw new InvalidParameterValueException("Incorrect aclType specified. Check the API documentation for supported types");
        }
        // In 3.0 all Shared networks should have aclType == Domain, all Isolated networks aclType==Account
        if (ntwkOff.getGuestType() == GuestType.Isolated) {
            if (aclType != ACLType.Account) {
                throw new InvalidParameterValueException("AclType should be " + ACLType.Account + " for network of type " + Network.GuestType.Isolated);
            }
        } else if (ntwkOff.getGuestType() == GuestType.Shared) {
            if (!(aclType == ACLType.Domain || aclType == ACLType.Account)) {
                throw new InvalidParameterValueException("AclType should be " + ACLType.Domain + " or " + ACLType.Account + " for network of type " + Network.GuestType.Shared);
            }
        }
    } else {
        if (ntwkOff.getGuestType() == GuestType.Isolated) {
            aclType = ACLType.Account;
        } else if (ntwkOff.getGuestType() == GuestType.Shared) {
            aclType = ACLType.Domain;
        }
    }
    // Only Admin can create Shared networks
    if (ntwkOff.getGuestType() == GuestType.Shared && !_accountMgr.isAdmin(caller.getId())) {
        throw new InvalidParameterValueException("Only Admins can create network with guest type " + GuestType.Shared);
    }
    // Check if the network is domain specific
    if (aclType == ACLType.Domain) {
        // only Admin can create domain with aclType=Domain
        if (!_accountMgr.isAdmin(caller.getId())) {
            throw new PermissionDeniedException("Only admin can create networks with aclType=Domain");
        }
        // only shared networks can be Domain specific
        if (ntwkOff.getGuestType() != GuestType.Shared) {
            throw new InvalidParameterValueException("Only " + GuestType.Shared + " networks can have aclType=" + ACLType.Domain);
        }
        if (domainId != null) {
            if (ntwkOff.getTrafficType() != TrafficType.Guest || ntwkOff.getGuestType() != Network.GuestType.Shared) {
                throw new InvalidParameterValueException("Domain level networks are supported just for traffic type " + TrafficType.Guest + " and guest type " + Network.GuestType.Shared);
            }
            DomainVO domain = _domainDao.findById(domainId);
            if (domain == null) {
                throw new InvalidParameterValueException("Unable to find domain by specified id");
            }
            _accountMgr.checkAccess(caller, domain);
        }
        isDomainSpecific = true;
    } else if (subdomainAccess != null) {
        throw new InvalidParameterValueException("Parameter subDomainAccess can be specified only with aclType=Domain");
    }
    Account owner = null;
    if ((cmd.getAccountName() != null && domainId != null) || cmd.getProjectId() != null) {
        owner = _accountMgr.finalizeOwner(caller, cmd.getAccountName(), domainId, cmd.getProjectId());
    } else {
        owner = caller;
    }
    boolean ipv4 = true, ipv6 = false;
    if (startIP != null) {
        ipv4 = true;
    }
    if (startIPv6 != null) {
        ipv6 = true;
    }
    if (gateway != null) {
        try {
            // getByName on a literal representation will only check validity of the address
            // http://docs.oracle.com/javase/6/docs/api/java/net/InetAddress.html#getByName(java.lang.String)
            InetAddress gatewayAddress = InetAddress.getByName(gateway);
            if (gatewayAddress instanceof Inet6Address) {
                ipv6 = true;
            } else {
                ipv4 = true;
            }
        } catch (UnknownHostException e) {
            s_logger.error("Unable to convert gateway IP to a InetAddress", e);
            throw new InvalidParameterValueException("Gateway parameter is invalid");
        }
    }
    String cidr = null;
    if (ipv4) {
        // if end ip is not specified, default it to startIp
        if (startIP != null) {
            if (!NetUtils.isValidIp(startIP)) {
                throw new InvalidParameterValueException("Invalid format for the startIp parameter");
            }
            if (endIP == null) {
                endIP = startIP;
            } else if (!NetUtils.isValidIp(endIP)) {
                throw new InvalidParameterValueException("Invalid format for the endIp parameter");
            }
        }
        if (startIP != null && endIP != null) {
            if (!(gateway != null && netmask != null)) {
                throw new InvalidParameterValueException("gateway and netmask should be defined when startIP/endIP are passed in");
            }
        }
        if (gateway != null && netmask != null) {
            if (NetUtils.isNetworkorBroadcastIP(gateway, netmask)) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("The gateway IP provided is " + gateway + " and netmask is " + netmask + ". The IP is either broadcast or network IP.");
                }
                throw new InvalidParameterValueException("Invalid gateway IP provided. Either the IP is broadcast or network IP.");
            }
            if (!NetUtils.isValidIp(gateway)) {
                throw new InvalidParameterValueException("Invalid gateway");
            }
            if (!NetUtils.isValidNetmask(netmask)) {
                throw new InvalidParameterValueException("Invalid netmask");
            }
            cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask);
        }
    }
    if (ipv6) {
        if (endIPv6 == null) {
            endIPv6 = startIPv6;
        }
        _networkModel.checkIp6Parameters(startIPv6, endIPv6, ip6Gateway, ip6Cidr);
        if (zone.getNetworkType() != NetworkType.Advanced || ntwkOff.getGuestType() != Network.GuestType.Shared) {
            throw new InvalidParameterValueException("Can only support create IPv6 network with advance shared network!");
        }
    }
    if (isolatedPvlan != null && (zone.getNetworkType() != NetworkType.Advanced || ntwkOff.getGuestType() != Network.GuestType.Shared)) {
        throw new InvalidParameterValueException("Can only support create Private VLAN network with advance shared network!");
    }
    if (isolatedPvlan != null && ipv6) {
        throw new InvalidParameterValueException("Can only support create Private VLAN network with IPv4!");
    }
    // Regular user can create Guest Isolated Source Nat enabled network only
    if (_accountMgr.isNormalUser(caller.getId()) && (ntwkOff.getTrafficType() != TrafficType.Guest || ntwkOff.getGuestType() != Network.GuestType.Isolated && areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat))) {
        throw new InvalidParameterValueException("Regular user can create a network only from the network" + " offering having traffic type " + TrafficType.Guest + " and network type " + Network.GuestType.Isolated + " with a service " + Service.SourceNat.getName() + " enabled");
    }
    // Don't allow to specify vlan if the caller is not ROOT admin
    if (!_accountMgr.isRootAdmin(caller.getId()) && (ntwkOff.getSpecifyVlan() || vlanId != null)) {
        throw new InvalidParameterValueException("Only ROOT admin is allowed to specify vlanId");
    }
    if (ipv4) {
        // For non-root admins check cidr limit - if it's allowed by global config value
        if (!_accountMgr.isRootAdmin(caller.getId()) && cidr != null) {
            String[] cidrPair = cidr.split("\\/");
            int cidrSize = Integer.parseInt(cidrPair[1]);
            if (cidrSize < _cidrLimit) {
                throw new InvalidParameterValueException("Cidr size can't be less than " + _cidrLimit);
            }
        }
    }
    Collection<String> ntwkProviders = _networkMgr.finalizeServicesAndProvidersForNetwork(ntwkOff, physicalNetworkId).values();
    if (ipv6 && providersConfiguredForExternalNetworking(ntwkProviders)) {
        throw new InvalidParameterValueException("Cannot support IPv6 on network offering with external devices!");
    }
    if (isolatedPvlan != null && providersConfiguredForExternalNetworking(ntwkProviders)) {
        throw new InvalidParameterValueException("Cannot support private vlan on network offering with external devices!");
    }
    if (cidr != null && providersConfiguredForExternalNetworking(ntwkProviders)) {
        if (ntwkOff.getGuestType() == GuestType.Shared && (zone.getNetworkType() == NetworkType.Advanced) && isSharedNetworkOfferingWithServices(networkOfferingId)) {
            // validate if CIDR specified overlaps with any of the CIDR's allocated for isolated networks and shared networks in the zone
            checkSharedNetworkCidrOverlap(zoneId, pNtwk.getId(), cidr);
        } else {
            // if cidr is not null and network is not part of vpc then throw the exception
            if (vpcId == null)
                throw new InvalidParameterValueException("Cannot specify CIDR when using network offering with external devices!");
        }
    }
    // Vlan is created in 1 cases - works in Advance zone only:
    // 1) GuestType is Shared
    boolean createVlan = (startIP != null && endIP != null && zone.getNetworkType() == NetworkType.Advanced && ((ntwkOff.getGuestType() == Network.GuestType.Shared) || (ntwkOff.getGuestType() == GuestType.Isolated && !areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat))));
    if (!createVlan) {
        // Only support advance shared network in IPv6, which means createVlan is a must
        if (ipv6) {
            createVlan = true;
        }
    }
    // Can add vlan range only to the network which allows it
    if (createVlan && !ntwkOff.getSpecifyIpRanges()) {
        InvalidParameterValueException ex = new InvalidParameterValueException("Network offering with specified id doesn't support adding multiple ip ranges");
        ex.addProxyObject(ntwkOff.getUuid(), "networkOfferingId");
        throw ex;
    }
    Network network = commitNetwork(networkOfferingId, gateway, startIP, endIP, netmask, networkDomain, vlanId, name, displayText, caller, physicalNetworkId, zoneId, domainId, isDomainSpecific, subdomainAccess, vpcId, startIPv6, endIPv6, ip6Gateway, ip6Cidr, displayNetwork, aclId, isolatedPvlan, ntwkOff, pNtwk, aclType, owner, cidr, createVlan);
    // if the network offering has persistent set to true, implement the network
    if (ntwkOff.getIsPersistent()) {
        try {
            if (network.getState() == Network.State.Setup) {
                s_logger.debug("Network id=" + network.getId() + " is already provisioned");
                return network;
            }
            DeployDestination dest = new DeployDestination(zone, null, null, null);
            UserVO callerUser = _userDao.findById(CallContext.current().getCallingUserId());
            Journal journal = new Journal.LogJournal("Implementing " + network, s_logger);
            ReservationContext context = new ReservationContextImpl(UUID.randomUUID().toString(), journal, callerUser, caller);
            s_logger.debug("Implementing network " + network + " as a part of network provision for persistent network");
            Pair<? extends NetworkGuru, ? extends Network> implementedNetwork = _networkMgr.implementNetwork(network.getId(), dest, context);
            if (implementedNetwork == null || implementedNetwork.first() == null) {
                s_logger.warn("Failed to provision the network " + network);
            }
            network = implementedNetwork.second();
        } catch (ResourceUnavailableException ex) {
            s_logger.warn("Failed to implement persistent guest network " + network + "due to ", ex);
            CloudRuntimeException e = new CloudRuntimeException("Failed to implement persistent guest network");
            e.addProxyObject(network.getUuid(), "networkId");
            throw e;
        }
    }
    return network;
}
Also used : Account(com.cloud.user.Account) CreateNetworkCmdByAdmin(org.apache.cloudstack.api.command.admin.network.CreateNetworkCmdByAdmin) Journal(com.cloud.utils.Journal) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) ReservationContext(com.cloud.vm.ReservationContext) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ACLType(org.apache.cloudstack.acl.ControlledEntity.ACLType) UnknownHostException(java.net.UnknownHostException) Inet6Address(java.net.Inet6Address) NetworkDomainVO(com.cloud.network.dao.NetworkDomainVO) DomainVO(com.cloud.domain.DomainVO) DataCenter(com.cloud.dc.DataCenter) UserVO(com.cloud.user.UserVO) DeployDestination(com.cloud.deploy.DeployDestination) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) InetAddress(java.net.InetAddress) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 49 with NetworkOfferingVO

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

the class ContrailManagerImpl method EnableNetworkOffering.

private NetworkOffering EnableNetworkOffering(long id) {
    NetworkOfferingVO offering = _networkOfferingDao.createForUpdate(id);
    offering.setState(NetworkOffering.State.Enabled);
    _networkOfferingDao.update(id, offering);
    return _networkOfferingDao.findById(id);
}
Also used : NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO)

Example 50 with NetworkOfferingVO

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

the class ContrailManagerImpl method locateNetworkOffering.

private NetworkOffering locateNetworkOffering(String offeringName, String offeringDisplayText, Provider provider) {
    List<? extends NetworkOffering> offerList = _configService.listNetworkOfferings(TrafficType.Guest, false);
    for (NetworkOffering offer : offerList) {
        if (offer.getName().equals(offeringName)) {
            if (offer.getState() != NetworkOffering.State.Enabled) {
                return EnableNetworkOffering(offer.getId());
            }
            return offer;
        }
    }
    Map<Service, Set<Provider>> serviceProviderMap = new HashMap<Service, Set<Provider>>();
    Set<Provider> providerSet = new HashSet<Provider>();
    providerSet.add(provider);
    final Service[] services = { Service.Connectivity, Service.Dhcp, Service.NetworkACL, Service.StaticNat, Service.SourceNat, Service.Lb };
    for (Service svc : services) {
        if (svc == Service.Lb) {
            if (offeringName.equals(vpcRouterOfferingName)) {
                Set<Provider> lbProviderSet = new HashSet<Provider>();
                lbProviderSet.add(Provider.InternalLbVm);
                serviceProviderMap.put(svc, lbProviderSet);
            }
            continue;
        }
        serviceProviderMap.put(svc, providerSet);
    }
    ConfigurationManager configMgr = (ConfigurationManager) _configService;
    NetworkOfferingVO voffer = configMgr.createNetworkOffering(offeringName, offeringDisplayText, TrafficType.Guest, null, false, Availability.Optional, null, serviceProviderMap, true, Network.GuestType.Isolated, false, null, false, null, false, true, null, true, null, false);
    voffer.setState(NetworkOffering.State.Enabled);
    if (offeringName.equals(vpcRouterOfferingName)) {
        voffer.setInternalLb(true);
    }
    long id = voffer.getId();
    _networkOfferingDao.update(id, voffer);
    return _networkOfferingDao.findById(id);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) NetworkOffering(com.cloud.offering.NetworkOffering) HashMap(java.util.HashMap) Service(com.cloud.network.Network.Service) VpcProvisioningService(com.cloud.network.vpc.VpcProvisioningService) ConfigurationService(com.cloud.configuration.ConfigurationService) Provider(com.cloud.network.Network.Provider) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) ConfigurationManager(com.cloud.configuration.ConfigurationManager) HashSet(java.util.HashSet)

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