|
54 | 54 | import org.apache.cloudstack.context.CallContext; |
55 | 55 | import org.apache.commons.collections.CollectionUtils; |
56 | 56 | import org.apache.commons.collections.MapUtils; |
| 57 | +import org.apache.commons.lang3.BooleanUtils; |
| 58 | +import org.apache.commons.lang3.StringUtils; |
57 | 59 | import org.apache.log4j.Logger; |
58 | 60 |
|
59 | 61 | import com.cloud.agent.api.LogLevel; |
|
75 | 77 | import com.cloud.vm.VirtualMachine; |
76 | 78 | import com.cloud.vm.VmDetailConstants; |
77 | 79 |
|
78 | | -import org.apache.commons.lang3.BooleanUtils; |
79 | | -import org.apache.commons.lang3.StringUtils; |
80 | | - |
81 | 80 | @APICommand(name = "deployVirtualMachine", description = "Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, |
82 | 81 | requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) |
83 | 82 | public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityGroupAction, UserCmd { |
@@ -766,32 +765,28 @@ public ApiCommandResourceType getApiResourceType() { |
766 | 765 | public void execute() { |
767 | 766 | UserVm result; |
768 | 767 |
|
769 | | - if (getStartVm()) { |
770 | | - try { |
771 | | - CallContext.current().setEventDetails("Vm Id: " + getEntityUuid()); |
772 | | - result = _userVmService.startVirtualMachine(this); |
773 | | - } catch (ResourceUnavailableException ex) { |
774 | | - s_logger.warn("Exception: ", ex); |
775 | | - throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); |
776 | | - } catch (ResourceAllocationException ex) { |
777 | | - s_logger.warn("Exception: ", ex); |
778 | | - throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage()); |
779 | | - } catch (ConcurrentOperationException ex) { |
780 | | - s_logger.warn("Exception: ", ex); |
781 | | - throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); |
782 | | - } catch (InsufficientCapacityException ex) { |
783 | | - StringBuilder message = new StringBuilder(ex.getMessage()); |
784 | | - if (ex instanceof InsufficientServerCapacityException) { |
785 | | - if (((InsufficientServerCapacityException)ex).isAffinityApplied()) { |
786 | | - message.append(", Please check the affinity groups provided, there may not be sufficient capacity to follow them"); |
787 | | - } |
| 768 | + try { |
| 769 | + CallContext.current().setEventDetails("Vm Id: " + getEntityUuid()); |
| 770 | + result = _userVmService.startVirtualMachine(this); |
| 771 | + } catch (ResourceUnavailableException ex) { |
| 772 | + s_logger.warn("Exception: ", ex); |
| 773 | + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); |
| 774 | + } catch (ResourceAllocationException ex) { |
| 775 | + s_logger.warn("Exception: ", ex); |
| 776 | + throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage()); |
| 777 | + } catch (ConcurrentOperationException ex) { |
| 778 | + s_logger.warn("Exception: ", ex); |
| 779 | + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); |
| 780 | + } catch (InsufficientCapacityException ex) { |
| 781 | + StringBuilder message = new StringBuilder(ex.getMessage()); |
| 782 | + if (ex instanceof InsufficientServerCapacityException) { |
| 783 | + if (((InsufficientServerCapacityException)ex).isAffinityApplied()) { |
| 784 | + message.append(", Please check the affinity groups provided, there may not be sufficient capacity to follow them"); |
788 | 785 | } |
789 | | - s_logger.info(ex); |
790 | | - s_logger.info(message.toString(), ex); |
791 | | - throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, message.toString()); |
792 | 786 | } |
793 | | - } else { |
794 | | - result = _userVmService.getUserVm(getEntityId()); |
| 787 | + s_logger.info(ex); |
| 788 | + s_logger.info(message.toString(), ex); |
| 789 | + throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, message.toString()); |
795 | 790 | } |
796 | 791 |
|
797 | 792 | if (result != null) { |
|
0 commit comments