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());
}
}
Aggregations