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