Search in sources :

Example 1 with StartVMCmd

use of org.apache.cloudstack.api.command.user.vm.StartVMCmd in project cloudstack by apache.

the class KubernetesClusterResourceModifierActionWorker method startKubernetesVM.

protected void startKubernetesVM(final UserVm vm) throws ManagementServerException {
    try {
        StartVMCmd startVm = new StartVMCmd();
        startVm = ComponentContext.inject(startVm);
        Field f = startVm.getClass().getDeclaredField("id");
        f.setAccessible(true);
        f.set(startVm, vm.getId());
        itMgr.advanceStart(vm.getUuid(), null, null);
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info(String.format("Started VM : %s in the Kubernetes cluster : %s", vm.getDisplayName(), kubernetesCluster.getName()));
        }
    } catch (IllegalAccessException | NoSuchFieldException | OperationTimedoutException | ResourceUnavailableException | InsufficientCapacityException ex) {
        throw new ManagementServerException(String.format("Failed to start VM in the Kubernetes cluster : %s", kubernetesCluster.getName()), ex);
    }
    UserVm startVm = userVmDao.findById(vm.getId());
    if (!startVm.getState().equals(VirtualMachine.State.Running)) {
        throw new ManagementServerException(String.format("Failed to start VM in the Kubernetes cluster : %s", kubernetesCluster.getName()));
    }
}
Also used : Field(java.lang.reflect.Field) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) UserVm(com.cloud.uservm.UserVm) ManagementServerException(com.cloud.exception.ManagementServerException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) StartVMCmd(org.apache.cloudstack.api.command.user.vm.StartVMCmd)

Aggregations

InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 ManagementServerException (com.cloud.exception.ManagementServerException)1 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 UserVm (com.cloud.uservm.UserVm)1 Field (java.lang.reflect.Field)1 StartVMCmd (org.apache.cloudstack.api.command.user.vm.StartVMCmd)1