Search in sources :

Example 6 with DataCenter

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

the class CreateServiceInstanceCmd method create.

@Override
public void create() throws ResourceAllocationException {
    // Parameter validation
    try {
        DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
        if (zone == null) {
            throw new InvalidParameterValueException("Unable to find zone ID " + zoneId);
        }
        Account owner = _accountService.getActiveAccountById(getEntityOwnerId());
        VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, templateId);
        if (template == null) {
            throw new InvalidParameterValueException("Invalid template ID " + templateId);
        }
        ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
        if (serviceOffering == null) {
            throw new InvalidParameterValueException("Invalid service offering ID " + serviceOfferingId);
        }
        Network left = _networkService.getNetwork(leftNetworkId);
        if (left == null) {
            throw new InvalidParameterValueException("Invalid ID for left network " + leftNetworkId);
        }
        Network right = _networkService.getNetwork(rightNetworkId);
        if (right == null) {
            throw new InvalidParameterValueException("Invalid ID for right network " + rightNetworkId);
        }
        if (name.isEmpty()) {
            throw new InvalidParameterValueException("service instance name is empty");
        }
        ServiceVirtualMachine svm = _vrouterService.createServiceInstance(zone, owner, template, serviceOffering, name, left, right);
        if (svm == null) {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Unable to create service instance");
        }
        setEntityId(svm.getId());
        setEntityUuid(svm.getUuid());
    } catch (Exception ex) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    }
}
Also used : Account(com.cloud.user.Account) DataCenter(com.cloud.dc.DataCenter) VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ServiceOffering(com.cloud.offering.ServiceOffering) Network(com.cloud.network.Network) ServiceVirtualMachine(org.apache.cloudstack.network.contrail.management.ServiceVirtualMachine) ServerApiException(org.apache.cloudstack.api.ServerApiException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException)

Example 7 with DataCenter

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

the class ContrailGuru method design.

@Override
public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
    // Check of the isolation type of the related physical network is L3VPN
    PhysicalNetworkVO physnet = _physicalNetworkDao.findById(plan.getPhysicalNetworkId());
    DataCenter dc = _dcDao.findById(plan.getDataCenterId());
    if (!canHandle(offering, dc.getNetworkType(), physnet)) {
        s_logger.debug("Refusing to design this network");
        return null;
    }
    NetworkVO network = new NetworkVO(offering.getTrafficType(), Mode.Dhcp, BroadcastDomainType.Lswitch, offering.getId(), State.Allocated, plan.getDataCenterId(), plan.getPhysicalNetworkId(), offering.getRedundantRouter());
    if (userSpecified.getCidr() != null) {
        network.setCidr(userSpecified.getCidr());
        network.setGateway(userSpecified.getGateway());
    }
    s_logger.debug("Allocated network " + userSpecified.getName() + (network.getCidr() == null ? "" : " subnet: " + network.getCidr()));
    return network;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) DataCenter(com.cloud.dc.DataCenter) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO)

Example 8 with DataCenter

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

the class ContrailManagerImpl method getCanonicalName.

@Override
public String getCanonicalName(Network net) {
    String netname;
    if (net.getTrafficType() == TrafficType.Guest) {
        return net.getName();
    } else if (net.getTrafficType() == TrafficType.Management || net.getTrafficType() == TrafficType.Storage) {
        return managementNetworkName;
    } else if (net.getTrafficType() == TrafficType.Control) {
        return "__link_local__";
    } else {
        DataCenter zone = _dcDao.findById(net.getDataCenterId());
        String zonename = zone.getName();
        zonename = zonename.replaceAll("\\s", "");
        zonename = zonename.replace("-", "_");
        netname = "__" + zonename + "_" + net.getTrafficType().toString() + "__";
    }
    return netname;
}
Also used : DataCenter(com.cloud.dc.DataCenter)

Example 9 with DataCenter

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

the class NuageVspGuestNetworkGuru method allocate.

@Override
public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
    if (vm.getType() != VirtualMachine.Type.DomainRouter && _nuageVspEntityBuilder.usesVirtualRouter(network.getNetworkOfferingId())) {
        VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(network);
        if (nic != null && nic.getRequestedIPv4() != null && vspNetwork.getVirtualRouterIp().equals(nic.getRequestedIPv4())) {
            DataCenter dc = _dcDao.findById(network.getDataCenterId());
            s_logger.error("Unable to acquire requested Guest IP address " + nic.getRequestedIPv4() + " because it is reserved for the VR in network " + network);
            throw new InsufficientVirtualNetworkCapacityException("Unable to acquire requested Guest IP address " + nic.getRequestedIPv4() + " because it is reserved " + "for the VR in network " + network, DataCenter.class, dc.getId());
        }
    }
    return super.allocate(network, nic, vm);
}
Also used : DataCenter(com.cloud.dc.DataCenter) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) VspNetwork(net.nuage.vsp.acs.client.api.model.VspNetwork)

Example 10 with DataCenter

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

the class ApiResponseHelper method createPrivateGatewayResponse.

@Override
public PrivateGatewayResponse createPrivateGatewayResponse(PrivateGateway result) {
    PrivateGatewayResponse response = new PrivateGatewayResponse();
    response.setId(result.getUuid());
    response.setBroadcastUri(result.getBroadcastUri());
    response.setGateway(result.getGateway());
    response.setNetmask(result.getNetmask());
    if (result.getVpcId() != null) {
        Vpc vpc = ApiDBUtils.findVpcById(result.getVpcId());
        response.setVpcId(vpc.getUuid());
    }
    DataCenter zone = ApiDBUtils.findZoneById(result.getZoneId());
    if (zone != null) {
        response.setZoneId(zone.getUuid());
        response.setZoneName(zone.getName());
    }
    response.setAddress(result.getIp4Address());
    PhysicalNetwork pnet = ApiDBUtils.findPhysicalNetworkById(result.getPhysicalNetworkId());
    if (pnet != null) {
        response.setPhysicalNetworkId(pnet.getUuid());
    }
    populateAccount(response, result.getAccountId());
    populateDomain(response, result.getDomainId());
    response.setState(result.getState().toString());
    response.setSourceNat(result.getSourceNat());
    NetworkACL acl = ApiDBUtils.findByNetworkACLId(result.getNetworkACLId());
    if (acl != null) {
        response.setAclId(acl.getUuid());
    }
    response.setObjectName("privategateway");
    return response;
}
Also used : PrivateGatewayResponse(org.apache.cloudstack.api.response.PrivateGatewayResponse) DataCenter(com.cloud.dc.DataCenter) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Vpc(com.cloud.network.vpc.Vpc) NetworkACL(com.cloud.network.vpc.NetworkACL)

Aggregations

DataCenter (com.cloud.dc.DataCenter)144 Account (com.cloud.user.Account)50 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)37 NetworkVO (com.cloud.network.dao.NetworkVO)33 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)32 Network (com.cloud.network.Network)30 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)27 ArrayList (java.util.ArrayList)27 DeployDestination (com.cloud.deploy.DeployDestination)25 NetworkOffering (com.cloud.offering.NetworkOffering)23 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)17 IPAddressVO (com.cloud.network.dao.IPAddressVO)17 DB (com.cloud.utils.db.DB)17 Domain (com.cloud.domain.Domain)16 ReservationContext (com.cloud.vm.ReservationContext)16 HostVO (com.cloud.host.HostVO)15 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)13 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)13 PhysicalNetwork (com.cloud.network.PhysicalNetwork)11 ServiceOffering (com.cloud.offering.ServiceOffering)11