Search in sources :

Example 1 with Vpc

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

the class CreateVPCCmdByAdmin method execute.

@Override
public void execute() {
    Vpc vpc = null;
    try {
        if (isStart()) {
            _vpcService.startVpc(getEntityId(), true);
        } else {
            s_logger.debug("Not starting VPC as " + ApiConstants.START + "=false was passed to the API");
        }
        vpc = _entityMgr.findById(Vpc.class, getEntityId());
    } catch (final ResourceUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (final ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (final InsufficientCapacityException ex) {
        s_logger.info(ex.toString());
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
    }
    if (vpc != null) {
        final VpcResponse response = _responseGenerator.createVpcResponse(ResponseView.Full, vpc);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create VPC");
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) VpcResponse(com.cloud.api.response.VpcResponse) Vpc(com.cloud.legacymodel.network.vpc.Vpc) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException)

Example 2 with Vpc

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

the class AssociateIPAddrCmd method getEntityOwnerId.

@Override
public long getEntityOwnerId() {
    final Account caller = CallContext.current().getCallingAccount();
    if (accountName != null && domainId != null) {
        final Account account = _accountService.finalizeOwner(caller, accountName, domainId, projectId);
        return account.getId();
    } else if (projectId != null) {
        final Project project = _projectService.getProject(projectId);
        if (project != null) {
            if (project.getState() == Project.State.Active) {
                return project.getProjectAccountId();
            } else {
                throw new PermissionDeniedException("Can't add resources to the project with specified projectId in state=" + project.getState() + " as it's no longer active");
            }
        } else {
            throw new InvalidParameterValueException("Unable to find project by ID");
        }
    } else if (networkId != null) {
        final Network network = _networkService.getNetwork(networkId);
        if (network == null) {
            throw new InvalidParameterValueException("Unable to find network by network id specified");
        }
        final NetworkOffering offering = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
        final DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
        if (zone.getNetworkType() == NetworkType.Basic && offering.getElasticIp() && offering.getElasticLb()) {
            // shared network with EIP/ELB service.
            return caller.getAccountId();
        }
        return network.getAccountId();
    } else if (vpcId != null) {
        final Vpc vpc = _entityMgr.findById(Vpc.class, getVpcId());
        if (vpc == null) {
            throw new InvalidParameterValueException("Can't find enabled VPC by ID specified");
        }
        return vpc.getAccountId();
    }
    return caller.getAccountId();
}
Also used : Account(com.cloud.legacymodel.user.Account) Project(com.cloud.projects.Project) DataCenter(com.cloud.legacymodel.dc.DataCenter) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) NetworkOffering(com.cloud.offering.NetworkOffering) Network(com.cloud.legacymodel.network.Network) Vpc(com.cloud.legacymodel.network.vpc.Vpc) PermissionDeniedException(com.cloud.legacymodel.exceptions.PermissionDeniedException)

Example 3 with Vpc

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

the class UpdateVPCCmdByAdmin method execute.

@Override
public void execute() {
    final Vpc result = _vpcService.updateVpc(getId(), getVpcName(), getDisplayText(), getCustomId(), getDisplayVpc(), getVpcOfferingId(), getSourceNatList(), getSyslogServerList(), getAdvertInterval(), getAdvertMethod(), getComplianceStatus());
    if (result != null) {
        final VpcResponse response = _responseGenerator.createVpcResponse(ResponseView.Full, result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update VPC");
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) VpcResponse(com.cloud.api.response.VpcResponse) Vpc(com.cloud.legacymodel.network.vpc.Vpc)

Example 4 with Vpc

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

the class NetworkOrchestrator method implementNetworkElementsAndResources.

@Override
public void implementNetworkElementsAndResources(final DeployDestination dest, final ReservationContext context, final Network network, final NetworkOffering offering) throws ConcurrentOperationException, InsufficientAddressCapacityException, ResourceUnavailableException, InsufficientCapacityException {
    // Associate a source NAT IP (if one isn't already associated with the network) if this is a
    // 1) 'Isolated' or 'Shared' guest virtual network in the advance zone
    // 2) network has sourceNat service
    // 3) network offering does not support a shared source NAT rule
    final boolean sharedSourceNat = offering.getSharedSourceNat();
    final Zone zone = _zoneRepository.findById(network.getDataCenterId()).orElse(null);
    if (!sharedSourceNat && _networkModel.areServicesSupportedInNetwork(network.getId(), Service.SourceNat) && (network.getGuestType() == GuestType.Isolated || network.getGuestType() == GuestType.Shared && zone.getNetworkType() == com.cloud.model.enumeration.NetworkType.Advanced)) {
        List<IPAddressVO> ips = null;
        final Account owner = _entityMgr.findById(Account.class, network.getAccountId());
        if (network.getVpcId() != null) {
            ips = _ipAddressDao.listByVpc(network.getVpcId(), true);
            if (ips.isEmpty()) {
                final Vpc vpc = _vpcMgr.getActiveVpc(network.getVpcId());
                s_logger.debug("Creating a source nat ip for vpc " + vpc);
                _vpcMgr.assignSourceNatIpAddressToVpc(owner, vpc);
            }
        } else {
            ips = _ipAddressDao.listByAssociatedNetwork(network.getId(), true);
            if (ips.isEmpty()) {
                s_logger.debug("Creating a source nat ip for network " + network);
                _ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network);
            }
        }
    }
    // get providers to implement
    final List<Provider> providersToImplement = getNetworkProviders(network.getId());
    implementNetworkElements(dest, context, network, offering, providersToImplement);
    for (final NetworkElement element : networkElements) {
        if (element instanceof AggregatedCommandExecutor && providersToImplement.contains(element.getProvider())) {
            ((AggregatedCommandExecutor) element).prepareAggregatedExecution(network, dest);
        }
    }
    try {
        // reapply all the firewall/staticNat/lb rules
        s_logger.debug("Reprogramming network " + network + " as a part of network implement");
        if (!reprogramNetworkRules(network.getId(), CallContext.current().getCallingAccount(), network)) {
            s_logger.warn("Failed to re-program the network as a part of network " + network + " implement");
            // see DataCenterVO.java
            final ResourceUnavailableException ex = new ResourceUnavailableException("Unable to apply network rules as a part of network " + network + " implement", DataCenter.class, network.getDataCenterId());
            ex.addProxyObject(_entityMgr.findById(DataCenter.class, network.getDataCenterId()).getUuid());
            throw ex;
        }
        for (final NetworkElement element : networkElements) {
            if (element instanceof AggregatedCommandExecutor && providersToImplement.contains(element.getProvider())) {
                if (!((AggregatedCommandExecutor) element).completeAggregatedExecution(network, dest)) {
                    s_logger.warn("Failed to re-program the network as a part of network " + network + " implement due to aggregated commands execution failure!");
                    // see DataCenterVO.java
                    final ResourceUnavailableException ex = new ResourceUnavailableException("Unable to apply network rules as a part of network " + network + " implement", DataCenter.class, network.getDataCenterId());
                    ex.addProxyObject(_entityMgr.findById(DataCenter.class, network.getDataCenterId()).getUuid());
                    throw ex;
                }
            }
        }
    } finally {
        for (final NetworkElement element : networkElements) {
            if (element instanceof AggregatedCommandExecutor && providersToImplement.contains(element.getProvider())) {
                ((AggregatedCommandExecutor) element).cleanupAggregatedExecution(network, dest);
            }
        }
    }
}
Also used : Account(com.cloud.legacymodel.user.Account) AggregatedCommandExecutor(com.cloud.network.element.AggregatedCommandExecutor) NetworkElement(com.cloud.network.element.NetworkElement) Zone(com.cloud.db.model.Zone) Vpc(com.cloud.legacymodel.network.vpc.Vpc) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) IPAddressVO(com.cloud.network.dao.IPAddressVO) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) Provider(com.cloud.legacymodel.network.Network.Provider) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider)

Example 5 with Vpc

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

the class VpcManagerImpl method startVpc.

@Override
public boolean startVpc(final long vpcId, final boolean destroyOnFailure) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    final CallContext ctx = CallContext.current();
    final Account caller = ctx.getCallingAccount();
    final User callerUser = _accountMgr.getActiveUser(ctx.getCallingUserId());
    // check if vpc exists
    final Vpc vpc = getActiveVpc(vpcId);
    if (vpc == null) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find Enabled VPC by id specified");
        ex.addProxyObject(String.valueOf(vpcId), "VPC");
        throw ex;
    }
    // permission check
    _accountMgr.checkAccess(caller, null, false, vpc);
    final Zone zone = zoneRepository.findById(vpc.getZoneId()).orElse(null);
    final DeployDestination dest = new DeployDestination(zone, null, null, null);
    final ReservationContext context = new ReservationContextImpl(null, null, callerUser, _accountMgr.getAccount(vpc.getAccountId()));
    boolean result = true;
    try {
        if (!startVpc(vpc, dest, context)) {
            s_logger.warn("Failed to start vpc " + vpc);
            result = false;
        }
    } catch (final Exception ex) {
        s_logger.warn("Failed to start vpc " + vpc + " due to ", ex);
        result = false;
    } finally {
        // do cleanup
        if (!result && destroyOnFailure) {
            s_logger.debug("Destroying vpc " + vpc + " that failed to start");
            if (destroyVpc(vpc, caller, callerUser.getId())) {
                s_logger.warn("Successfully destroyed vpc " + vpc + " that failed to start");
            } else {
                s_logger.warn("Failed to destroy vpc " + vpc + " that failed to start");
            }
        }
    }
    return result;
}
Also used : Account(com.cloud.legacymodel.user.Account) User(com.cloud.legacymodel.user.User) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) Zone(com.cloud.db.model.Zone) DeployDestination(com.cloud.deploy.DeployDestination) Vpc(com.cloud.legacymodel.network.vpc.Vpc) CallContext(com.cloud.context.CallContext) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) PermissionDeniedException(com.cloud.legacymodel.exceptions.PermissionDeniedException) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) ResourceAllocationException(com.cloud.legacymodel.exceptions.ResourceAllocationException) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) ExecutionException(java.util.concurrent.ExecutionException) InsufficientAddressCapacityException(com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) NetworkRuleConflictException(com.cloud.legacymodel.exceptions.NetworkRuleConflictException) ConfigurationException(javax.naming.ConfigurationException) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) ServerApiException(com.cloud.api.ServerApiException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ReservationContext(com.cloud.vm.ReservationContext)

Aggregations

Vpc (com.cloud.legacymodel.network.vpc.Vpc)60 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)24 Account (com.cloud.legacymodel.user.Account)24 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)17 DomainRouterVO (com.cloud.vm.DomainRouterVO)17 Network (com.cloud.legacymodel.network.Network)15 ArrayList (java.util.ArrayList)14 NetworkACL (com.cloud.legacymodel.network.vpc.NetworkACL)11 ActionEvent (com.cloud.event.ActionEvent)9 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)9 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)8 NetworkVO (com.cloud.network.dao.NetworkVO)8 List (java.util.List)8 ServerApiException (com.cloud.api.ServerApiException)7 InsufficientCapacityException (com.cloud.legacymodel.exceptions.InsufficientCapacityException)7 IPAddressVO (com.cloud.network.dao.IPAddressVO)7 DB (com.cloud.utils.db.DB)7 VpcResponse (com.cloud.api.response.VpcResponse)6 CallContext (com.cloud.context.CallContext)6 DataCenter (com.cloud.legacymodel.dc.DataCenter)6