Search in sources :

Example 1 with NetworkTopology

use of com.cloud.network.topology.NetworkTopology 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 2 with NetworkTopology

use of com.cloud.network.topology.NetworkTopology 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 3 with NetworkTopology

use of com.cloud.network.topology.NetworkTopology 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 4 with NetworkTopology

use of com.cloud.network.topology.NetworkTopology in project cosmic by MissionCriticalCloud.

the class VirtualRouterElement method saveSSHKey.

@Override
public boolean saveSSHKey(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final String sshPublicKey) throws ResourceUnavailableException {
    if (!canHandle(network, null)) {
        return false;
    }
    final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
    if (routers == null || routers.isEmpty()) {
        s_logger.debug("Can't find virtual router element in network " + network.getId());
        return true;
    }
    final VirtualMachineProfile uservm = vm;
    final Zone zone = zoneRepository.findOne(network.getDataCenterId());
    final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(zone);
    boolean result = true;
    for (final DomainRouterVO domainRouterVO : routers) {
        result = result && networkTopology.saveSSHPublicKeyToRouter(network, nic, uservm, domainRouterVO, sshPublicKey);
    }
    return result;
}
Also used : Zone(com.cloud.db.model.Zone) NetworkTopology(com.cloud.network.topology.NetworkTopology) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 5 with NetworkTopology

use of com.cloud.network.topology.NetworkTopology in project cosmic by MissionCriticalCloud.

the class VirtualRouterElement method addDhcpEntry.

@Override
public boolean addDhcpEntry(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
    boolean result = true;
    if (canHandle(network, Service.Dhcp)) {
        if (vm.getType() != VirtualMachine.Type.User) {
            return false;
        }
        final VirtualMachineProfile uservm = vm;
        final List<DomainRouterVO> routers = getRouters(network, dest);
        if (routers == null || routers.size() == 0) {
            throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
        }
        final Zone zone = zoneRepository.findOne(network.getDataCenterId());
        final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(zone);
        for (final DomainRouterVO domainRouterVO : routers) {
            result = result && networkTopology.applyDhcpEntry(network, nic, uservm, dest, domainRouterVO);
        }
    }
    return result;
}
Also used : Zone(com.cloud.db.model.Zone) NetworkTopology(com.cloud.network.topology.NetworkTopology) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

Zone (com.cloud.db.model.Zone)23 NetworkTopology (com.cloud.network.topology.NetworkTopology)23 DomainRouterVO (com.cloud.vm.DomainRouterVO)23 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)9 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)6 Network (com.cloud.network.Network)5 UserVmVO (com.cloud.vm.UserVmVO)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 NicProfile (com.cloud.vm.NicProfile)3 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)2 IllegalVirtualMachineException (com.cloud.exception.IllegalVirtualMachineException)2 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)2 Service (com.cloud.network.Network.Service)2 ArrayList (java.util.ArrayList)2 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)1 Answer (com.cloud.agent.api.Answer)1 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)1 CheckS2SVpnConnectionsAnswer (com.cloud.agent.api.CheckS2SVpnConnectionsAnswer)1 GetDomRVersionAnswer (com.cloud.agent.api.GetDomRVersionAnswer)1 NetworkUsageAnswer (com.cloud.agent.api.NetworkUsageAnswer)1