Search in sources :

Example 6 with PrivateGateway

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

the class ListPrivateGatewaysCmd method execute.

@Override
public void execute() {
    Pair<List<PrivateGateway>, Integer> gateways = _vpcService.listPrivateGateway(this);
    ListResponse<PrivateGatewayResponse> response = new ListResponse<PrivateGatewayResponse>();
    List<PrivateGatewayResponse> projectResponses = new ArrayList<PrivateGatewayResponse>();
    for (PrivateGateway gateway : gateways.first()) {
        PrivateGatewayResponse gatewayResponse = _responseGenerator.createPrivateGatewayResponse(gateway);
        projectResponses.add(gatewayResponse);
    }
    response.setResponses(projectResponses, gateways.second());
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : PrivateGatewayResponse(org.apache.cloudstack.api.response.PrivateGatewayResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) PrivateGateway(com.cloud.network.vpc.PrivateGateway)

Example 7 with PrivateGateway

use of com.cloud.network.vpc.PrivateGateway in project cosmic by MissionCriticalCloud.

the class VpcNetworkHelperImpl method reallocateRouterNetworks.

@Override
public void reallocateRouterNetworks(final RouterDeploymentDefinition vpcRouterDeploymentDefinition, final VirtualRouter router, final VMTemplateVO template, final HypervisorType hType) throws ConcurrentOperationException, InsufficientCapacityException {
    final TreeSet<String> publicVlans = new TreeSet<>();
    if (vpcRouterDeploymentDefinition.needsPublicNic()) {
        publicVlans.add(vpcRouterDeploymentDefinition.getSourceNatIP().getVlanTag());
    } else {
        s_logger.debug("VPC " + vpcRouterDeploymentDefinition.getVpc().getName() + " does not need a public nic.");
    }
    // 1) allocate nic for control and source nat public ip
    final LinkedHashMap<Network, List<? extends NicProfile>> networks = configureDefaultNics(vpcRouterDeploymentDefinition);
    final Long vpcId = vpcRouterDeploymentDefinition.getVpc().getId();
    // 2) allocate nic for private gateways if needed
    final List<PrivateGateway> privateGateways = vpcMgr.getVpcPrivateGateways(vpcId);
    if (privateGateways != null && !privateGateways.isEmpty()) {
        for (final PrivateGateway privateGateway : privateGateways) {
            final NicProfile privateNic = nicProfileHelper.createPrivateNicProfileForGateway(privateGateway, router);
            final Network privateNetwork = _networkModel.getNetwork(privateGateway.getNetworkId());
            networks.put(privateNetwork, new ArrayList<>(Arrays.asList(privateNic)));
        }
    }
    // 3) allocate nic for guest gateway if needed
    final List<? extends Network> guestNetworks = vpcMgr.getVpcNetworks(vpcId);
    for (final Network guestNetwork : guestNetworks) {
        if (_networkModel.isPrivateGateway(guestNetwork.getId())) {
            continue;
        }
        if (guestNetwork.getState() == Network.State.Implemented || guestNetwork.getState() == Network.State.Setup) {
            final NicProfile guestNic = nicProfileHelper.createGuestNicProfileForVpcRouter(vpcRouterDeploymentDefinition, guestNetwork);
            networks.put(guestNetwork, new ArrayList<>(Arrays.asList(guestNic)));
        }
    }
    // 4) allocate nic for additional public network(s)
    final List<IPAddressVO> ips = _ipAddressDao.listByVpc(vpcId, false);
    final List<NicProfile> publicNics = new ArrayList<>();
    Network publicNetwork = null;
    for (final IPAddressVO ip : ips) {
        final PublicIp publicIp = PublicIp.createFromAddrAndVlan(ip, _vlanDao.findById(ip.getVlanId()));
        if ((ip.getState() == IpAddress.State.Allocated || ip.getState() == IpAddress.State.Allocating) && vpcMgr.isIpAllocatedToVpc(ip) && !publicVlans.contains(publicIp.getVlanTag())) {
            s_logger.debug("Allocating nic for router in vlan " + publicIp.getVlanTag());
            final NicProfile publicNic = new NicProfile();
            publicNic.setDefaultNic(false);
            publicNic.setIPv4Address(publicIp.getAddress().addr());
            publicNic.setIPv4Gateway(publicIp.getGateway());
            publicNic.setIPv4Netmask(publicIp.getNetmask());
            publicNic.setMacAddress(publicIp.getMacAddress());
            publicNic.setBroadcastType(BroadcastDomainType.Vlan);
            publicNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(publicIp.getVlanTag()));
            publicNic.setIsolationUri(IsolationType.Vlan.toUri(publicIp.getVlanTag()));
            final NetworkOffering publicOffering = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemPublicNetwork).get(0);
            if (publicNetwork == null) {
                final List<? extends Network> publicNetworks = _networkMgr.setupNetwork(s_systemAccount, publicOffering, vpcRouterDeploymentDefinition.getPlan(), null, null, false);
                publicNetwork = publicNetworks.get(0);
            }
            publicNics.add(publicNic);
            publicVlans.add(publicIp.getVlanTag());
        }
    }
    if (publicNetwork != null) {
        if (networks.get(publicNetwork) != null) {
            final List<NicProfile> publicNicProfiles = (List<NicProfile>) networks.get(publicNetwork);
            publicNicProfiles.addAll(publicNics);
            networks.put(publicNetwork, publicNicProfiles);
        } else {
            networks.put(publicNetwork, publicNics);
        }
    }
    final ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(vpcRouterDeploymentDefinition.getServiceOfferingId());
    _itMgr.allocate(router.getInstanceName(), template, routerOffering, networks, vpcRouterDeploymentDefinition.getPlan(), hType);
}
Also used : PublicIp(com.cloud.network.addr.PublicIp) NetworkOffering(com.cloud.offering.NetworkOffering) ArrayList(java.util.ArrayList) NicProfile(com.cloud.vm.NicProfile) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) PrivateGateway(com.cloud.network.vpc.PrivateGateway) TreeSet(java.util.TreeSet) Network(com.cloud.network.Network) ArrayList(java.util.ArrayList) List(java.util.List) IPAddressVO(com.cloud.network.dao.IPAddressVO)

Example 8 with PrivateGateway

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

the class CreatePrivateGatewayCmd method execute.

@Override
public void execute() throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException, ResourceUnavailableException {
    PrivateGateway result = _vpcService.applyVpcPrivateGateway(getEntityId(), true);
    if (result != null) {
        PrivateGatewayResponse response = _responseGenerator.createPrivateGatewayResponse(result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create private gateway");
    }
}
Also used : PrivateGatewayResponse(org.apache.cloudstack.api.response.PrivateGatewayResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) PrivateGateway(com.cloud.network.vpc.PrivateGateway)

Example 9 with PrivateGateway

use of com.cloud.network.vpc.PrivateGateway in project cosmic by MissionCriticalCloud.

the class CreatePrivateGatewayCmd method create.

// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public void create() throws ResourceAllocationException {
    PrivateGateway result;
    try {
        result = _vpcService.createVpcPrivateGateway(getVpcId(), getStartIp(), getGateway(), getNetmask(), getEntityDomainId(), getNetworkId(), getIsSourceNat(), getAclId());
    } catch (final InsufficientCapacityException ex) {
        s_logger.info(ex.toString());
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
    } catch (final ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    }
    if (result != null) {
        setEntityId(result.getId());
        setEntityUuid(result.getUuid());
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create private gateway");
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) PrivateGateway(com.cloud.network.vpc.PrivateGateway)

Example 10 with PrivateGateway

use of com.cloud.network.vpc.PrivateGateway in project cosmic by MissionCriticalCloud.

the class CreatePrivateGatewayCmd method execute.

@Override
public void execute() throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException, ResourceUnavailableException {
    final PrivateGateway result = _vpcService.applyVpcPrivateGateway(getEntityId(), true);
    if (result != null) {
        final PrivateGatewayResponse response = _responseGenerator.createPrivateGatewayResponse(result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create private gateway");
    }
}
Also used : PrivateGatewayResponse(com.cloud.api.response.PrivateGatewayResponse) ServerApiException(com.cloud.api.ServerApiException) PrivateGateway(com.cloud.network.vpc.PrivateGateway)

Aggregations

PrivateGateway (com.cloud.network.vpc.PrivateGateway)10 ArrayList (java.util.ArrayList)6 Network (com.cloud.network.Network)4 List (java.util.List)4 ServerApiException (com.cloud.api.ServerApiException)2 PrivateGatewayResponse (com.cloud.api.response.PrivateGatewayResponse)2 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)2 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)2 PublicIp (com.cloud.network.addr.PublicIp)2 IPAddressVO (com.cloud.network.dao.IPAddressVO)2 NetworkVO (com.cloud.network.dao.NetworkVO)2 NetworkACLServiceProvider (com.cloud.network.element.NetworkACLServiceProvider)2 NetworkACLItemVO (com.cloud.network.vpc.NetworkACLItemVO)2 NetworkACLManager (com.cloud.network.vpc.NetworkACLManager)2 VpcGatewayVO (com.cloud.network.vpc.VpcGatewayVO)2 VpcService (com.cloud.network.vpc.VpcService)2 NetworkOffering (com.cloud.offering.NetworkOffering)2 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)2 NicProfile (com.cloud.vm.NicProfile)2 TreeSet (java.util.TreeSet)2