Search in sources :

Example 1 with PrepareUnmanageVMInstanceAnswer

use of com.cloud.agent.api.PrepareUnmanageVMInstanceAnswer in project cloudstack by apache.

the class UnmanagedVMsManagerImpl method existsVMToUnmanage.

/**
 * Verify the VM to unmanage exists on the hypervisor
 */
private boolean existsVMToUnmanage(String instanceName, Long hostId) {
    PrepareUnmanageVMInstanceCommand command = new PrepareUnmanageVMInstanceCommand();
    command.setInstanceName(instanceName);
    Answer ans = agentManager.easySend(hostId, command);
    if (!(ans instanceof PrepareUnmanageVMInstanceAnswer)) {
        throw new CloudRuntimeException("Error communicating with host " + hostId);
    }
    PrepareUnmanageVMInstanceAnswer answer = (PrepareUnmanageVMInstanceAnswer) ans;
    if (!answer.getResult()) {
        LOGGER.error("Error verifying VM " + instanceName + " exists on host with ID = " + hostId + ": " + answer.getDetails());
    }
    return answer.getResult();
}
Also used : PrepareUnmanageVMInstanceAnswer(com.cloud.agent.api.PrepareUnmanageVMInstanceAnswer) Answer(com.cloud.agent.api.Answer) GetUnmanagedInstancesAnswer(com.cloud.agent.api.GetUnmanagedInstancesAnswer) PrepareUnmanageVMInstanceAnswer(com.cloud.agent.api.PrepareUnmanageVMInstanceAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PrepareUnmanageVMInstanceCommand(com.cloud.agent.api.PrepareUnmanageVMInstanceCommand)

Example 2 with PrepareUnmanageVMInstanceAnswer

use of com.cloud.agent.api.PrepareUnmanageVMInstanceAnswer in project cloudstack by apache.

the class VmwareResource method execute.

private Answer execute(PrepareUnmanageVMInstanceCommand cmd) {
    VmwareContext context = getServiceContext();
    VmwareHypervisorHost hyperHost = getHyperHost(context);
    String instanceName = cmd.getInstanceName();
    try {
        s_logger.debug(String.format("Verify if VMware instance: [%s] is available before unmanaging VM.", cmd.getInstanceName()));
        ManagedObjectReference dcMor = hyperHost.getHyperHostDatacenter();
        DatacenterMO dataCenterMo = new DatacenterMO(getServiceContext(), dcMor);
        VirtualMachineMO vm = dataCenterMo.findVm(instanceName);
        if (vm == null) {
            return new PrepareUnmanageVMInstanceAnswer(cmd, false, String.format("Cannot find VM with name [%s] in datacenter [%s].", instanceName, dataCenterMo.getName()));
        }
    } catch (Exception e) {
        s_logger.error("Error trying to verify if VM to unmanage exists", e);
        return new PrepareUnmanageVMInstanceAnswer(cmd, false, "Error: " + e.getMessage());
    }
    return new PrepareUnmanageVMInstanceAnswer(cmd, true, "OK");
}
Also used : PrepareUnmanageVMInstanceAnswer(com.cloud.agent.api.PrepareUnmanageVMInstanceAnswer) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) VirtualMachineMO(com.cloud.hypervisor.vmware.mo.VirtualMachineMO) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) DatacenterMO(com.cloud.hypervisor.vmware.mo.DatacenterMO)

Aggregations

PrepareUnmanageVMInstanceAnswer (com.cloud.agent.api.PrepareUnmanageVMInstanceAnswer)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 Answer (com.cloud.agent.api.Answer)1 GetUnmanagedInstancesAnswer (com.cloud.agent.api.GetUnmanagedInstancesAnswer)1 PrepareUnmanageVMInstanceCommand (com.cloud.agent.api.PrepareUnmanageVMInstanceCommand)1 CloudException (com.cloud.exception.CloudException)1 InternalErrorException (com.cloud.exception.InternalErrorException)1 DatacenterMO (com.cloud.hypervisor.vmware.mo.DatacenterMO)1 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)1 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)1 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)1 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ConnectException (java.net.ConnectException)1 RemoteException (java.rmi.RemoteException)1 ConfigurationException (javax.naming.ConfigurationException)1