Search in sources :

Example 11 with DataCenterVO

use of com.cloud.dc.DataCenterVO in project cloudstack by apache.

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;
    }
    s_logger.info("Adding VPC routers to Guest Network: " + routers.size() + " to be added!");
    final DataCenterVO dcVO = _dcDao.findById(gateway.getZoneId());
    final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
    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 : DataCenterVO(com.cloud.dc.DataCenterVO) NetworkTopology(org.apache.cloudstack.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) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 12 with DataCenterVO

use of com.cloud.dc.DataCenterVO in project cloudstack by apache.

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 elemnt doesn't need to static routes on the backend; virtual " + "router doesn't exist in the vpc " + vpc);
        return true;
    }
    final DataCenterVO dcVO = _dcDao.findById(vpc.getZoneId());
    final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
    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 : DataCenterVO(com.cloud.dc.DataCenterVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NetworkTopology(org.apache.cloudstack.network.topology.NetworkTopology) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 13 with DataCenterVO

use of com.cloud.dc.DataCenterVO in project cloudstack by apache.

the class VirtualRouterElement method addPasswordAndUserdata.

@Override
public boolean addPasswordAndUserdata(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.UserData)) {
        if (vm.getType() != VirtualMachine.Type.User) {
            return false;
        }
        if (network.getIp6Gateway() != null) {
            s_logger.info("Skip password and userdata service setup for IPv6 VM");
            return true;
        }
        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 DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
        final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
        for (final DomainRouterVO domainRouterVO : routers) {
            result = result && networkTopology.applyUserData(network, nic, uservm, dest, domainRouterVO);
        }
    }
    return result;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) NetworkTopology(org.apache.cloudstack.network.topology.NetworkTopology) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 14 with DataCenterVO

use of com.cloud.dc.DataCenterVO in project cloudstack by apache.

the class VirtualRouterElement method configureDhcpSupport.

protected boolean configureDhcpSupport(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, Service service) throws ResourceUnavailableException {
    if (canHandle(network, service)) {
        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 DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
        final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
        return networkTopology.configDhcpForSubnet(network, nic, uservm, dest, routers);
    }
    return false;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) NetworkTopology(org.apache.cloudstack.network.topology.NetworkTopology) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 15 with DataCenterVO

use of com.cloud.dc.DataCenterVO in project cloudstack by apache.

the class VirtualRouterElement method applyStaticNats.

@Override
public boolean applyStaticNats(final Network network, final List<? extends StaticNat> rules) throws ResourceUnavailableException {
    boolean result = true;
    if (canHandle(network, Service.StaticNat)) {
        final List<DomainRouterVO> routers = getRouters(network);
        if (routers == null || routers.isEmpty()) {
            s_logger.debug("Virtual router elemnt doesn't need to apply static nat on the backend; virtual " + "router doesn't exist in the network " + network.getId());
            return true;
        }
        final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
        final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
        for (final DomainRouterVO domainRouterVO : routers) {
            result = result && networkTopology.applyStaticNats(network, rules, domainRouterVO);
        }
    }
    return result;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) NetworkTopology(org.apache.cloudstack.network.topology.NetworkTopology) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

DataCenterVO (com.cloud.dc.DataCenterVO)214 ArrayList (java.util.ArrayList)60 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)54 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)53 HostVO (com.cloud.host.HostVO)42 Account (com.cloud.user.Account)37 NetworkVO (com.cloud.network.dao.NetworkVO)35 DomainRouterVO (com.cloud.vm.DomainRouterVO)33 HostPodVO (com.cloud.dc.HostPodVO)32 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)30 ClusterVO (com.cloud.dc.ClusterVO)27 NetworkTopology (org.apache.cloudstack.network.topology.NetworkTopology)27 DB (com.cloud.utils.db.DB)26 Network (com.cloud.network.Network)25 HashMap (java.util.HashMap)25 ConfigurationException (javax.naming.ConfigurationException)25 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)20 Test (org.junit.Test)20 NicProfile (com.cloud.vm.NicProfile)19 ActionEvent (com.cloud.event.ActionEvent)18