Search in sources :

Example 1 with ServiceVirtualMachine

use of org.apache.cloudstack.network.contrail.management.ServiceVirtualMachine 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)

Aggregations

DataCenter (com.cloud.dc.DataCenter)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)1 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 Network (com.cloud.network.Network)1 ServiceOffering (com.cloud.offering.ServiceOffering)1 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)1 Account (com.cloud.user.Account)1 ServerApiException (org.apache.cloudstack.api.ServerApiException)1 ServiceVirtualMachine (org.apache.cloudstack.network.contrail.management.ServiceVirtualMachine)1