Search in sources :

Example 61 with Network

use of com.cloud.legacymodel.network.Network in project cosmic by MissionCriticalCloud.

the class NetworkHelperImpl method reallocateRouterNetworks.

@Override
public void reallocateRouterNetworks(final RouterDeploymentDefinition routerDeploymentDefinition, final VirtualRouter router, final VMTemplateVO template, final HypervisorType hType) throws ConcurrentOperationException, InsufficientCapacityException {
    final ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(routerDeploymentDefinition.getServiceOfferingId());
    final LinkedHashMap<Network, List<? extends NicProfile>> networks = configureDefaultNics(routerDeploymentDefinition);
    _itMgr.allocate(router.getInstanceName(), template, routerOffering, networks, routerDeploymentDefinition.getPlan(), hType);
}
Also used : Network(com.cloud.legacymodel.network.Network) List(java.util.List) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) NicProfile(com.cloud.vm.NicProfile) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO)

Example 62 with Network

use of com.cloud.legacymodel.network.Network in project cosmic by MissionCriticalCloud.

the class NetworkHelperImpl method configureControlNic.

protected LinkedHashMap<Network, List<? extends NicProfile>> configureControlNic(final RouterDeploymentDefinition routerDeploymentDefinition) {
    final LinkedHashMap<Network, List<? extends NicProfile>> controlConfig = new LinkedHashMap<>(3);
    logger.debug("Adding nic for Virtual Router in Control network ");
    final List<? extends NetworkOffering> offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork);
    final NetworkOffering controlOffering = offerings.get(0);
    final Network controlNic = _networkMgr.setupNetwork(s_systemAccount, controlOffering, routerDeploymentDefinition.getPlan(), null, null, false).get(0);
    controlConfig.put(controlNic, new ArrayList<>());
    return controlConfig;
}
Also used : NetworkOffering(com.cloud.offering.NetworkOffering) Network(com.cloud.legacymodel.network.Network) List(java.util.List) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) NicProfile(com.cloud.vm.NicProfile) LinkedHashMap(java.util.LinkedHashMap)

Example 63 with Network

use of com.cloud.legacymodel.network.Network in project cosmic by MissionCriticalCloud.

the class NetworkHelperImpl method configureGuestNic.

@Override
public LinkedHashMap<Network, List<? extends NicProfile>> configureGuestNic(final RouterDeploymentDefinition routerDeploymentDefinition) throws ConcurrentOperationException, InsufficientAddressCapacityException {
    // Form networks
    final LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<>(3);
    // 1) Guest network
    final Network guestNetwork = routerDeploymentDefinition.getGuestNetwork();
    if (guestNetwork != null) {
        logger.debug("Adding nic for Virtual Router in Guest network " + guestNetwork);
        String defaultNetworkStartIp = null, defaultNetworkStartIpv6 = null;
        if (!routerDeploymentDefinition.isPublicNetwork()) {
            final Nic placeholder = _networkModel.getPlaceholderNicForRouter(guestNetwork, routerDeploymentDefinition.getPodId());
            if (guestNetwork.getCidr() != null) {
                if (placeholder != null && placeholder.getIPv4Address() != null) {
                    logger.debug("Requesting ipv4 address " + placeholder.getIPv4Address() + " stored in placeholder nic for the network " + guestNetwork);
                    defaultNetworkStartIp = placeholder.getIPv4Address();
                } else {
                    final String startIp = _networkModel.getStartIpAddress(guestNetwork.getId());
                    if (startIp != null && _ipAddressDao.findByIpAndSourceNetworkId(guestNetwork.getId(), startIp).getAllocatedTime() == null) {
                        defaultNetworkStartIp = startIp;
                    } else if (logger.isDebugEnabled()) {
                        logger.debug("First ipv4 " + startIp + " in network id=" + guestNetwork.getId() + " is already allocated, can't use it for domain router; will get random ip address from the range");
                    }
                }
            }
            if (guestNetwork.getIp6Cidr() != null) {
                if (placeholder != null && placeholder.getIPv6Address() != null) {
                    logger.debug("Requesting ipv6 address " + placeholder.getIPv6Address() + " stored in placeholder nic for the network " + guestNetwork);
                    defaultNetworkStartIpv6 = placeholder.getIPv6Address();
                } else {
                    final String startIpv6 = _networkModel.getStartIpv6Address(guestNetwork.getId());
                    if (startIpv6 != null && _ipv6Dao.findByNetworkIdAndIp(guestNetwork.getId(), startIpv6) == null) {
                        defaultNetworkStartIpv6 = startIpv6;
                    } else if (logger.isDebugEnabled()) {
                        logger.debug("First ipv6 " + startIpv6 + " in network id=" + guestNetwork.getId() + " is already allocated, can't use it for domain router; will get random ipv6 address from the range");
                    }
                }
            }
        }
        final NicProfile gatewayNic = new NicProfile(defaultNetworkStartIp, defaultNetworkStartIpv6);
        if (routerDeploymentDefinition.isPublicNetwork()) {
            if (routerDeploymentDefinition.isRedundant()) {
                gatewayNic.setIPv4Address(_ipAddrMgr.acquireGuestIpAddressForRouter(guestNetwork, null));
            } else {
                gatewayNic.setIPv4Address(guestNetwork.getGateway());
            }
            gatewayNic.setBroadcastUri(guestNetwork.getBroadcastUri());
            gatewayNic.setBroadcastType(guestNetwork.getBroadcastDomainType());
            gatewayNic.setIsolationUri(guestNetwork.getBroadcastUri());
            gatewayNic.setMode(guestNetwork.getMode());
            final String gatewayCidr = guestNetwork.getCidr();
            gatewayNic.setIPv4Netmask(NetUtils.getCidrNetmask(gatewayCidr));
        } else {
            gatewayNic.setDefaultNic(true);
        }
        networks.put(guestNetwork, new ArrayList<>(Arrays.asList(gatewayNic)));
    }
    return networks;
}
Also used : Network(com.cloud.legacymodel.network.Network) Nic(com.cloud.legacymodel.network.Nic) List(java.util.List) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) NicProfile(com.cloud.vm.NicProfile) LinkedHashMap(java.util.LinkedHashMap)

Example 64 with Network

use of com.cloud.legacymodel.network.Network in project cosmic by MissionCriticalCloud.

the class NetworkHelperImpl method configurePublicNic.

protected LinkedHashMap<Network, List<? extends NicProfile>> configurePublicNic(final RouterDeploymentDefinition routerDeploymentDefinition, final boolean hasGuestNic) throws InsufficientAddressCapacityException {
    final LinkedHashMap<Network, List<? extends NicProfile>> publicConfig = new LinkedHashMap<>(3);
    if (routerDeploymentDefinition.isPublicNetwork()) {
        logger.debug("Adding nic for Virtual Router in Public network ");
        // if source nat service is supported by the network, get the source
        // nat ip address
        final NicProfile defaultNic = new NicProfile();
        defaultNic.setDefaultNic(true);
        final PublicIp sourceNatIp = routerDeploymentDefinition.getSourceNatIP();
        defaultNic.setIPv4Address(sourceNatIp.getAddress().addr());
        defaultNic.setIPv4Gateway(sourceNatIp.getGateway());
        defaultNic.setIPv4Netmask(sourceNatIp.getNetmask());
        defaultNic.setMacAddress(_networkModel.getNextAvailableMacAddressInNetwork(sourceNatIp.getNetworkId()));
        // get broadcast from public network
        final Network pubNet = _networkDao.findById(sourceNatIp.getNetworkId());
        if (pubNet.getBroadcastDomainType() == BroadcastDomainType.Vxlan) {
            defaultNic.setBroadcastType(BroadcastDomainType.Vxlan);
            defaultNic.setBroadcastUri(BroadcastDomainType.Vxlan.toUri(sourceNatIp.getVlanTag()));
            defaultNic.setIsolationUri(BroadcastDomainType.Vxlan.toUri(sourceNatIp.getVlanTag()));
        } else {
            defaultNic.setBroadcastType(BroadcastDomainType.Vlan);
            defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(sourceNatIp.getVlanTag()));
            defaultNic.setIsolationUri(IsolationType.Vlan.toUri(sourceNatIp.getVlanTag()));
        }
        final NetworkOffering publicOffering = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemPublicNetwork).get(0);
        final List<? extends Network> publicNetworks = _networkMgr.setupNetwork(s_systemAccount, publicOffering, routerDeploymentDefinition.getPlan(), null, null, false);
        publicConfig.put(publicNetworks.get(0), new ArrayList<>(Arrays.asList(defaultNic)));
    }
    return publicConfig;
}
Also used : PublicIp(com.cloud.network.addr.PublicIp) NetworkOffering(com.cloud.offering.NetworkOffering) Network(com.cloud.legacymodel.network.Network) List(java.util.List) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) NicProfile(com.cloud.vm.NicProfile) LinkedHashMap(java.util.LinkedHashMap)

Example 65 with Network

use of com.cloud.legacymodel.network.Network in project cosmic by MissionCriticalCloud.

the class NetworkHelperImpl method deployRouter.

@Override
public DomainRouterVO deployRouter(final RouterDeploymentDefinition routerDeploymentDefinition, final boolean startRouter) throws InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException {
    final List<DomainRouterVO> routers;
    final boolean isRedundant;
    if (routerDeploymentDefinition.isVpcRouter()) {
        final Vpc vpc = routerDeploymentDefinition.getVpc();
        routers = _routerDao.listByVpcId(vpc.getId());
        isRedundant = vpc.isRedundant();
    } else {
        final Network guestnetwork = routerDeploymentDefinition.getGuestNetwork();
        routers = _routerDao.listByNetworkAndRole(guestnetwork.getId(), Role.VIRTUAL_ROUTER);
        isRedundant = guestnetwork.isRedundant();
    }
    ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(routerDeploymentDefinition.getServiceOfferingId());
    if (isRedundant && routers != null && routers.size() == 1 && routers.get(0).getServiceOfferingId() == routerDeploymentDefinition.getServiceOfferingId()) {
        routerOffering = _serviceOfferingDao.findById(routerDeploymentDefinition.getSecondaryServiceOfferingId());
    }
    Long routerUnicastId = 1L;
    if (isRedundant && routers != null && routers.size() == 1 && routers.get(0).getRouterUnicastId() != null && routers.get(0).getRouterUnicastId() == 1L) {
        routerUnicastId = 2L;
    }
    _serviceOfferingDao.loadDetails(routerOffering);
    final String serviceofferingHypervisor = routerOffering.getDetail("hypervisor");
    if (serviceofferingHypervisor != null && !serviceofferingHypervisor.isEmpty()) {
        logger.debug(String.format("Found hypervisor '%s' in details of serviceoffering with id %s. Going to check if that hypervisor is available.", serviceofferingHypervisor, routerDeploymentDefinition.getServiceOfferingId()));
    }
    final Account owner = routerDeploymentDefinition.getOwner();
    // Router is the network element, we don't know the hypervisor type yet.
    // Try to allocate the domR twice using diff hypervisors, and when
    // failed both times, throw the exception up
    final List<HypervisorType> hypervisors = getHypervisors(routerDeploymentDefinition);
    int allocateRetry = 0;
    int startRetry = 0;
    DomainRouterVO router = null;
    for (final Iterator<HypervisorType> iter = hypervisors.iterator(); iter.hasNext(); ) {
        final HypervisorType hType = iter.next();
        try {
            final long id = _routerDao.getNextInSequence(Long.class, "id");
            if (serviceofferingHypervisor != null && !serviceofferingHypervisor.isEmpty() && !hType.toString().equalsIgnoreCase(serviceofferingHypervisor)) {
                logger.debug(String.format("Skipping hypervisor type '%s' as the service offering details request hypervisor '%s'", hType, serviceofferingHypervisor));
                continue;
            }
            logger.debug(String.format("Allocating the VR with id=%s in datacenter %s with the hypervisor type %s", id, routerDeploymentDefinition.getDest().getZone(), hType));
            final String templateName = retrieveTemplateName(hType, routerDeploymentDefinition.getDest().getZone().getId());
            final VMTemplateVO template = _templateDao.findRoutingTemplate(hType, templateName, routerDeploymentDefinition.getDest().getZone().getId());
            if (template == null) {
                logger.debug(hType + " won't support system vm, skip it");
                continue;
            }
            final boolean offerHA = routerOffering.getOfferHA();
            // routerDeploymentDefinition.getVpc().getId() ==> do not use
            // VPC because it is not a VPC offering.
            final Long vpcId = routerDeploymentDefinition.getVpc() != null ? routerDeploymentDefinition.getVpc().getId() : null;
            long userId = CallContext.current().getCallingUserId();
            if (CallContext.current().getCallingAccount().getId() != owner.getId()) {
                final List<UserVO> userVOs = _userDao.listByAccount(owner.getAccountId());
                if (!userVOs.isEmpty()) {
                    userId = userVOs.get(0).getId();
                }
            }
            router = new DomainRouterVO(id, routerOffering.getId(), routerDeploymentDefinition.getVirtualProvider().getId(), VirtualMachineName.getRouterName(id, s_vmInstanceName), template.getId(), template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), userId, routerDeploymentDefinition.isRedundant(), RedundantState.UNKNOWN, offerHA, false, vpcId, template.getOptimiseFor(), template.getManufacturerString(), template.getCpuFlags(), template.getMacLearning(), false, template.getMaintenancePolicy(), routerUnicastId);
            router.setDynamicallyScalable(template.isDynamicallyScalable());
            router.setRole(Role.VIRTUAL_ROUTER);
            router = _routerDao.persist(router);
            reallocateRouterNetworks(routerDeploymentDefinition, router, template, null);
            router = _routerDao.findById(router.getId());
        } catch (final InsufficientCapacityException ex) {
            if (allocateRetry < 2 && iter.hasNext()) {
                logger.debug("Failed to allocate the VR with hypervisor type " + hType + ", retrying one more time");
                continue;
            } else {
                throw ex;
            }
        } finally {
            allocateRetry++;
        }
        if (startRouter) {
            try {
                final Account caller = CallContext.current().getCallingAccount();
                final User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
                router = startVirtualRouter(router, callerUser, caller, routerDeploymentDefinition.getParams());
                break;
            } catch (final InsufficientCapacityException ex) {
                if (startRetry < 2 && iter.hasNext()) {
                    logger.debug("Failed to start the VR  " + router + " with hypervisor type " + hType + ", " + "destroying it and recreating one more time");
                    // destroy the router
                    destroyRouter(router.getId(), _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM), User.UID_SYSTEM);
                    continue;
                } else {
                    throw ex;
                }
            } finally {
                startRetry++;
            }
        } else {
            // return stopped router
            return router;
        }
    }
    return router;
}
Also used : Account(com.cloud.legacymodel.user.Account) User(com.cloud.legacymodel.user.User) Vpc(com.cloud.legacymodel.network.vpc.Vpc) VMTemplateVO(com.cloud.storage.VMTemplateVO) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) HypervisorType(com.cloud.model.enumeration.HypervisorType) UserVO(com.cloud.user.UserVO) Network(com.cloud.legacymodel.network.Network) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

Network (com.cloud.legacymodel.network.Network)160 ArrayList (java.util.ArrayList)57 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)56 Account (com.cloud.legacymodel.user.Account)46 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)42 NetworkOffering (com.cloud.offering.NetworkOffering)36 PhysicalNetwork (com.cloud.network.PhysicalNetwork)34 IPAddressVO (com.cloud.network.dao.IPAddressVO)32 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)30 NetworkVO (com.cloud.network.dao.NetworkVO)28 List (java.util.List)28 Zone (com.cloud.db.model.Zone)27 DB (com.cloud.utils.db.DB)27 NicProfile (com.cloud.vm.NicProfile)26 Nic (com.cloud.legacymodel.network.Nic)21 DataCenter (com.cloud.legacymodel.dc.DataCenter)20 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)20 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)19 DomainRouterVO (com.cloud.vm.DomainRouterVO)18 ActionEvent (com.cloud.event.ActionEvent)17