Search in sources :

Example 31 with Zone

use of com.cloud.db.model.Zone in project cosmic by MissionCriticalCloud.

the class VpcVirtualRouterElement method applyStaticRoutes.

@Override
public boolean applyStaticRoutes(final Vpc vpc, final List<StaticRouteProfile> routes) throws ResourceUnavailableException {
    final List<DomainRouterVO> routers = _routerDao.listByVpcId(vpc.getId());
    if (routers == null || routers.isEmpty()) {
        s_logger.debug("Virtual router element doesn't need to static routes on the backend; virtual router doesn't exist in the vpc " + vpc);
        return true;
    }
    final Zone zone = zoneRepository.findOne(vpc.getZoneId());
    final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(zone);
    if (!networkTopology.applyStaticRoutes(routes, routers)) {
        throw new CloudRuntimeException("Failed to apply static routes in vpc " + vpc);
    } else {
        s_logger.debug("Applied static routes on vpc " + vpc);
        return true;
    }
}
Also used : Zone(com.cloud.db.model.Zone) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NetworkTopology(com.cloud.network.topology.NetworkTopology) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 32 with Zone

use of com.cloud.db.model.Zone in project cosmic by MissionCriticalCloud.

the class VpcVirtualRouterElement method applyACLItemsToPrivateGw.

@Override
public boolean applyACLItemsToPrivateGw(final PrivateGateway gateway, final List<? extends NetworkACLItem> rules) throws ResourceUnavailableException {
    final Network network = _networkDao.findById(gateway.getNetworkId());
    final boolean isPrivateGateway = true;
    final List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(gateway.getVpcId());
    if (routers == null || routers.isEmpty()) {
        s_logger.debug("Virtual router element doesn't need to apply network acl rules on the backend; virtual router doesn't exist in the network " + network.getId());
        return true;
    }
    final Zone zone = zoneRepository.findOne(network.getDataCenterId());
    final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(zone);
    final Network privateNetwork = _networkModel.getNetwork(gateway.getNetworkId());
    boolean result = true;
    for (final DomainRouterVO domainRouterVO : routers) {
        final NicProfile nicProfile = _networkModel.getNicProfile(domainRouterVO, privateNetwork.getId(), null);
        if (nicProfile != null) {
            result = result && networkTopology.applyNetworkACLs(network, rules, domainRouterVO, isPrivateGateway);
        } else {
            s_logger.warn("Nic Profile for router '" + domainRouterVO + "' has already been removed. Router is redundant = " + domainRouterVO.getIsRedundantRouter());
        }
    }
    return result;
}
Also used : Zone(com.cloud.db.model.Zone) Network(com.cloud.network.Network) NetworkTopology(com.cloud.network.topology.NetworkTopology) NicProfile(com.cloud.vm.NicProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 33 with Zone

use of com.cloud.db.model.Zone in project cosmic by MissionCriticalCloud.

the class VpcVirtualRouterElement method createPrivateGateway.

@Override
public boolean createPrivateGateway(final PrivateGateway gateway) throws ConcurrentOperationException, ResourceUnavailableException {
    if (gateway.getType() != VpcGateway.Type.Private) {
        s_logger.warn("Type of vpc gateway is not " + VpcGateway.Type.Private);
        return true;
    }
    final List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(gateway.getVpcId());
    if (routers == null || routers.isEmpty()) {
        s_logger.debug(getName() + " element doesn't need to create Private gateway on the backend; VPC virtual router doesn't exist in the vpc id=" + gateway.getVpcId());
        return true;
    }
    final Zone zone = zoneRepository.findOne(gateway.getZoneId());
    final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(zone);
    boolean result = true;
    final Network network = _networkDao.findById(gateway.getNetworkId());
    final boolean isPrivateGateway = true;
    for (final DomainRouterVO domainRouterVO : routers) {
        if (networkTopology.setupPrivateGateway(gateway, domainRouterVO)) {
            try {
                final List<NetworkACLItemVO> rules = _networkACLItemDao.listByACL(gateway.getNetworkACLId());
                result = result && networkTopology.applyNetworkACLs(network, rules, domainRouterVO, isPrivateGateway);
            } catch (final Exception ex) {
                s_logger.debug("Failed to apply network acl id  " + gateway.getNetworkACLId() + "  on gateway ");
                return false;
            }
        }
    }
    return result;
}
Also used : Zone(com.cloud.db.model.Zone) NetworkTopology(com.cloud.network.topology.NetworkTopology) Network(com.cloud.network.Network) DomainRouterVO(com.cloud.vm.DomainRouterVO) NetworkACLItemVO(com.cloud.network.vpc.NetworkACLItemVO) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) IllegalVirtualMachineException(com.cloud.exception.IllegalVirtualMachineException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 34 with Zone

use of com.cloud.db.model.Zone in project cosmic by MissionCriticalCloud.

the class DirectNetworkGuru method allocate.

@Override
public NicProfile allocate(final Network network, NicProfile nic, final VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException {
    final Zone zone = zoneRepository.findOne(network.getDataCenterId());
    if (nic == null) {
        nic = new NicProfile(ReservationStrategy.Create, null, null, null, null);
    } else if (nic.getIPv4Address() == null && nic.getIPv6Address() == null) {
        nic.setReservationStrategy(ReservationStrategy.Start);
    } else {
        nic.setReservationStrategy(ReservationStrategy.Create);
    }
    allocateDirectIp(nic, network, vm, zone, nic.getRequestedIPv4(), nic.getRequestedIPv6());
    nic.setReservationStrategy(ReservationStrategy.Create);
    if (nic.getMacAddress() == null) {
        nic.setMacAddress(_networkModel.getNextAvailableMacAddressInNetwork(network.getId()));
        if (nic.getMacAddress() == null) {
            throw new InsufficientAddressCapacityException("Unable to allocate more mac addresses", Network.class, network.getId());
        }
    }
    return nic;
}
Also used : Zone(com.cloud.db.model.Zone) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) NicProfile(com.cloud.vm.NicProfile)

Example 35 with Zone

use of com.cloud.db.model.Zone in project cosmic by MissionCriticalCloud.

the class GuestNetworkGuru method allocate.

@Override
public NicProfile allocate(final Network network, NicProfile nic, final VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
    assert network.getTrafficType() == TrafficType.Guest : "Look at my name!  Why are you calling" + " me when the traffic type is : " + network.getTrafficType();
    if (nic == null) {
        nic = new NicProfile(ReservationStrategy.Start, null, null, null, null);
    }
    final Zone zone = zoneRepository.findOne(network.getDataCenterId());
    if (nic.getIPv4Address() == null && !GuestType.Sync.equals(network.getGuestType())) {
        nic.setBroadcastUri(network.getBroadcastUri());
        nic.setIsolationUri(network.getBroadcastUri());
        nic.setIPv4Gateway(network.getGateway());
        final String guestIp;
        if (network.getSpecifyIpRanges()) {
            _ipAddrMgr.allocateDirectIp(nic, zone, vm, network, nic.getRequestedIPv4(), null);
        } else {
            final VirtualMachine.Type vmtype = vm.getVirtualMachine().getType();
            switch(vmtype) {
                case User:
                    guestIp = _ipAddrMgr.acquireGuestIpAddress(network, nic.getRequestedIPv4());
                    break;
                case DomainRouter:
                    if (_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Gateway, Provider.VPCVirtualRouter)) {
                        // Networks that support the Gateway service acquire the gateway ip on their nic
                        guestIp = network.getGateway();
                    } else {
                        // In other cases, acquire an ip address from the DHCP range (take lowest possible)
                        guestIp = _ipAddrMgr.acquireGuestIpAddressForRouter(network, nic.getRequestedIPv4());
                    }
                    break;
                default:
                    // Backwards compatibility
                    guestIp = _ipAddrMgr.acquireGuestIpAddress(network, nic.getRequestedIPv4());
                    break;
            }
            if (guestIp == null) {
                throw new InsufficientVirtualNetworkCapacityException("Unable to acquire Guest IP" + " address for network " + network, DataCenter.class, zone.getId());
            }
            nic.setIPv4Address(guestIp);
            nic.setIPv4Netmask(NetUtils.cidr2Netmask(network.getCidr()));
            if (network.getDns1() != null && network.getDns1().equals("")) {
                nic.setIPv4Dns1(zone.getDns1());
            } else {
                nic.setIPv4Dns1(network.getDns1());
            }
            if (network.getDns2() != null && network.getDns2().equals("")) {
                nic.setIPv4Dns2(zone.getDns2());
            } else {
                nic.setIPv4Dns2(network.getDns2());
            }
            nic.setFormat(AddressFormat.Ip4);
        }
    }
    nic.setReservationStrategy(ReservationStrategy.Start);
    if (nic.getMacAddress() == null) {
        nic.setMacAddress(_networkModel.getNextAvailableMacAddressInNetwork(network.getId()));
        if (nic.getMacAddress() == null) {
            throw new InsufficientAddressCapacityException("Unable to allocate more mac addresses", Network.class, network.getId());
        }
    }
    return nic;
}
Also used : Zone(com.cloud.db.model.Zone) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) NicProfile(com.cloud.vm.NicProfile) VirtualMachine(com.cloud.vm.VirtualMachine)

Aggregations

Zone (com.cloud.db.model.Zone)106 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)34 ArrayList (java.util.ArrayList)32 DomainRouterVO (com.cloud.vm.DomainRouterVO)28 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)26 Network (com.cloud.network.Network)23 NetworkTopology (com.cloud.network.topology.NetworkTopology)23 Account (com.cloud.user.Account)23 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)23 NetworkVO (com.cloud.network.dao.NetworkVO)22 DeployDestination (com.cloud.deploy.DeployDestination)18 NicProfile (com.cloud.vm.NicProfile)16 List (java.util.List)16 HostPodVO (com.cloud.dc.HostPodVO)15 HostVO (com.cloud.host.HostVO)15 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)14 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)14 DB (com.cloud.utils.db.DB)14 TransactionStatus (com.cloud.utils.db.TransactionStatus)12 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)11