Search in sources :

Example 1 with Vpc

use of com.cloud.network.vpc.Vpc in project cloudstack by apache.

the class VpcVirtualRouterElement method implement.

@Override
public boolean implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException {
    final Long vpcId = network.getVpcId();
    if (vpcId == null) {
        s_logger.trace("Network " + network + " is not associated with any VPC");
        return false;
    }
    final Vpc vpc = _vpcMgr.getActiveVpc(vpcId);
    if (vpc == null) {
        s_logger.warn("Unable to find Enabled VPC by id " + vpcId);
        return false;
    }
    final Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
    params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
    final RouterDeploymentDefinition routerDeploymentDefinition = routerDeploymentDefinitionBuilder.create().setGuestNetwork(network).setVpc(vpc).setDeployDestination(dest).setAccountOwner(_accountMgr.getAccount(vpc.getAccountId())).setParams(params).build();
    final List<DomainRouterVO> routers = routerDeploymentDefinition.deployVirtualRouter();
    if (routers == null || routers.size() == 0) {
        throw new ResourceUnavailableException("Can't find at least one running router!", DataCenter.class, network.getDataCenterId());
    }
    configureGuestNetwork(network, routers);
    return true;
}
Also used : RouterDeploymentDefinition(org.cloud.network.router.deployment.RouterDeploymentDefinition) HashMap(java.util.HashMap) Vpc(com.cloud.network.vpc.Vpc) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 2 with Vpc

use of com.cloud.network.vpc.Vpc in project cloudstack by apache.

the class VpcVirtualRouterElement method getRouters.

@Override
protected List<DomainRouterVO> getRouters(final Network network, final DeployDestination dest) {
    //1st time it runs the domain router of the VM shall be returned
    List<DomainRouterVO> routers = super.getRouters(network, dest);
    if (routers.size() > 0) {
        return routers;
    }
    //For the 2nd time it returns the VPC routers.
    final Long vpcId = network.getVpcId();
    if (vpcId == null) {
        s_logger.error("Network " + network + " is not associated with any VPC");
        return routers;
    }
    final Vpc vpc = _vpcMgr.getActiveVpc(vpcId);
    if (vpc == null) {
        s_logger.warn("Unable to find Enabled VPC by id " + vpcId);
        return routers;
    }
    final RouterDeploymentDefinition routerDeploymentDefinition = routerDeploymentDefinitionBuilder.create().setGuestNetwork(network).setVpc(vpc).setDeployDestination(dest).setAccountOwner(_accountMgr.getAccount(vpc.getAccountId())).build();
    try {
        routers = routerDeploymentDefinition.deployVirtualRouter();
    } catch (final ConcurrentOperationException e) {
        s_logger.error("Error occurred when loading routers from routerDeploymentDefinition.deployVirtualRouter()!", e);
    } catch (final InsufficientCapacityException e) {
        s_logger.error("Error occurred when loading routers from routerDeploymentDefinition.deployVirtualRouter()!", e);
    } catch (final ResourceUnavailableException e) {
        s_logger.error("Error occurred when loading routers from routerDeploymentDefinition.deployVirtualRouter()!", e);
    }
    return routers;
}
Also used : RouterDeploymentDefinition(org.cloud.network.router.deployment.RouterDeploymentDefinition) Vpc(com.cloud.network.vpc.Vpc) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 3 with Vpc

use of com.cloud.network.vpc.Vpc in project cloudstack by apache.

the class VpcVirtualRouterElement method prepare.

@Override
public boolean prepare(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
    final Long vpcId = network.getVpcId();
    if (vpcId == null) {
        s_logger.trace("Network " + network + " is not associated with any VPC");
        return false;
    }
    final Vpc vpc = _vpcMgr.getActiveVpc(vpcId);
    if (vpc == null) {
        s_logger.warn("Unable to find Enabled VPC by id " + vpcId);
        return false;
    }
    if (vm.getType() == VirtualMachine.Type.User) {
        final Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
        params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
        final RouterDeploymentDefinition routerDeploymentDefinition = routerDeploymentDefinitionBuilder.create().setGuestNetwork(network).setVpc(vpc).setDeployDestination(dest).setAccountOwner(_accountMgr.getAccount(vpc.getAccountId())).setParams(params).build();
        final List<DomainRouterVO> routers = routerDeploymentDefinition.deployVirtualRouter();
        if (routers == null || routers.size() == 0) {
            throw new ResourceUnavailableException("Can't find at least one running router!", DataCenter.class, network.getDataCenterId());
        }
        configureGuestNetwork(network, routers);
    }
    return true;
}
Also used : RouterDeploymentDefinition(org.cloud.network.router.deployment.RouterDeploymentDefinition) HashMap(java.util.HashMap) Vpc(com.cloud.network.vpc.Vpc) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 4 with Vpc

use of com.cloud.network.vpc.Vpc in project cloudstack by apache.

the class VpcVirtualRouterElement method stopSite2SiteVpn.

@Override
public boolean stopSite2SiteVpn(final Site2SiteVpnConnection conn) throws ResourceUnavailableException {
    final Site2SiteVpnGateway vpnGw = _vpnGatewayDao.findById(conn.getVpnGatewayId());
    final IpAddress ip = _ipAddressDao.findById(vpnGw.getAddrId());
    final Map<Capability, String> vpnCapabilities = capabilities.get(Service.Vpn);
    if (!vpnCapabilities.get(Capability.VpnTypes).contains("s2svpn")) {
        s_logger.error("try to stop site 2 site vpn on unsupported network element?");
        return false;
    }
    final Long vpcId = ip.getVpcId();
    final Vpc vpc = _entityMgr.findById(Vpc.class, vpcId);
    if (!_ntwkModel.isProviderEnabledInZone(vpc.getZoneId(), Provider.VPCVirtualRouter.getName())) {
        throw new ResourceUnavailableException("VPC provider is not enabled in zone " + vpc.getZoneId(), DataCenter.class, vpc.getZoneId());
    }
    final List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(ip.getVpcId());
    if (routers == null) {
        throw new ResourceUnavailableException("Cannot enable site-to-site VPN on the backend; virtual router doesn't exist in the vpc " + ip.getVpcId(), DataCenter.class, vpc.getZoneId());
    }
    boolean result = true;
    for (final DomainRouterVO domainRouterVO : routers) {
        result = result && _vpcRouterMgr.stopSite2SiteVpn(conn, domainRouterVO);
    }
    return result;
}
Also used : Site2SiteVpnGateway(com.cloud.network.Site2SiteVpnGateway) Capability(com.cloud.network.Network.Capability) Vpc(com.cloud.network.vpc.Vpc) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 5 with Vpc

use of com.cloud.network.vpc.Vpc in project cloudstack by apache.

the class VpcVirtualRouterElement method startSite2SiteVpn.

@Override
public boolean startSite2SiteVpn(final Site2SiteVpnConnection conn) throws ResourceUnavailableException {
    final Site2SiteVpnGateway vpnGw = _vpnGatewayDao.findById(conn.getVpnGatewayId());
    final IpAddress ip = _ipAddressDao.findById(vpnGw.getAddrId());
    final Map<Capability, String> vpnCapabilities = capabilities.get(Service.Vpn);
    if (!vpnCapabilities.get(Capability.VpnTypes).contains("s2svpn")) {
        s_logger.error("try to start site 2 site vpn on unsupported network element?");
        return false;
    }
    final Long vpcId = ip.getVpcId();
    final Vpc vpc = _entityMgr.findById(Vpc.class, vpcId);
    if (!_ntwkModel.isProviderEnabledInZone(vpc.getZoneId(), Provider.VPCVirtualRouter.getName())) {
        throw new ResourceUnavailableException("VPC provider is not enabled in zone " + vpc.getZoneId(), DataCenter.class, vpc.getZoneId());
    }
    final List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(ip.getVpcId());
    if (routers == null) {
        throw new ResourceUnavailableException("Cannot enable site-to-site VPN on the backend; virtual router doesn't exist in the vpc " + ip.getVpcId(), DataCenter.class, vpc.getZoneId());
    }
    boolean result = true;
    for (final DomainRouterVO domainRouterVO : routers) {
        result = result && _vpcRouterMgr.startSite2SiteVpn(conn, domainRouterVO);
    }
    return result;
}
Also used : Site2SiteVpnGateway(com.cloud.network.Site2SiteVpnGateway) Capability(com.cloud.network.Network.Capability) Vpc(com.cloud.network.vpc.Vpc) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

Vpc (com.cloud.network.vpc.Vpc)45 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)12 DomainRouterVO (com.cloud.vm.DomainRouterVO)10 ArrayList (java.util.ArrayList)10 DataCenter (com.cloud.dc.DataCenter)9 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)7 Account (com.cloud.user.Account)7 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)6 Network (com.cloud.network.Network)6 NetworkVO (com.cloud.network.dao.NetworkVO)6 VpcResponse (org.apache.cloudstack.api.response.VpcResponse)6 IpAddress (com.cloud.network.IpAddress)5 PublicIpAddress (com.cloud.network.PublicIpAddress)5 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)5 ServerApiException (org.apache.cloudstack.api.ServerApiException)5 DataCenterVO (com.cloud.dc.DataCenterVO)4 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)4 Capability (com.cloud.network.Network.Capability)4 HashMap (java.util.HashMap)4 VlanVO (com.cloud.dc.VlanVO)3