use of com.vmware.vim25.mo.Task in project cloudstack by apache.
the class DistributedVirtualSwitchMO method updateVMWareDVSwitchGetTask.
public TaskInfo updateVMWareDVSwitchGetTask(ManagedObjectReference dvSwitchMor, VMwareDVSConfigSpec dvsSpec) throws Exception {
ManagedObjectReference task = _context.getService().reconfigureDvsTask(dvSwitchMor, dvsSpec);
TaskInfo info = (TaskInfo) (_context.getVimClient().getDynamicProperty(task, "info"));
_context.getVimClient().waitForTask(task);
return info;
}
use of com.vmware.vim25.mo.Task in project cloudstack by apache.
the class VirtualMachineMO method createSnapshotGetReference.
public ManagedObjectReference createSnapshotGetReference(String snapshotName, String snapshotDescription, boolean dumpMemory, boolean quiesce) throws Exception {
long apiTimeout = _context.getVimClient().getVcenterSessionTimeout();
ManagedObjectReference morTask = _context.getService().createSnapshotTask(_mor, snapshotName, snapshotDescription, dumpMemory, quiesce);
boolean result = _context.getVimClient().waitForTask(morTask);
if (result) {
_context.waitForTaskProgressDone(morTask);
ManagedObjectReference morSnapshot = null;
// We still need to wait until the object appear in vCenter
long startTick = System.currentTimeMillis();
while (System.currentTimeMillis() - startTick < apiTimeout) {
morSnapshot = getSnapshotMor(snapshotName);
if (morSnapshot != null) {
break;
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
s_logger.debug("[ignored] interupted while waiting for snapshot to be done.");
}
}
if (morSnapshot == null) {
s_logger.error("We've been waiting for over " + apiTimeout + " milli seconds for snapshot MOR to be appearing in vCenter after CreateSnapshot task is done, " + "but it is still not there?!");
return null;
}
s_logger.debug("Waited for " + (System.currentTimeMillis() - startTick) + " seconds for snapshot object [" + snapshotName + "] to appear in vCenter.");
return morSnapshot;
} else {
s_logger.error("VMware createSnapshot_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
return null;
}
use of com.vmware.vim25.mo.Task in project cloudstack by apache.
the class VirtualMachineMO method cancelPendingTasks.
public void cancelPendingTasks() throws Exception {
String vmName = getVmName();
s_logger.debug("Checking for pending tasks of the VM: " + vmName);
ManagedObjectReference taskmgr = _context.getServiceContent().getTaskManager();
List<ManagedObjectReference> tasks = _context.getVimClient().getDynamicProperty(taskmgr, "recentTask");
int vmTasks = 0, vmPendingTasks = 0;
for (ManagedObjectReference task : tasks) {
TaskInfo info = (TaskInfo) (_context.getVimClient().getDynamicProperty(task, "info"));
if (info.getEntityName().equals(vmName)) {
vmTasks++;
if (!(info.getState().equals(TaskInfoState.SUCCESS) || info.getState().equals(TaskInfoState.ERROR))) {
String taskName = StringUtils.isNotBlank(info.getName()) ? info.getName() : "Unknown";
s_logger.debug(taskName + " task pending for the VM: " + vmName + ", cancelling it");
vmPendingTasks++;
_context.getVimClient().cancelTask(task);
}
}
}
s_logger.debug(vmPendingTasks + " pending tasks for the VM: " + vmName + " found, out of " + vmTasks + " recent VM tasks");
}
use of com.vmware.vim25.mo.Task in project cloudstack by apache.
the class VirtualMachineMO method consolidateAllSnapshots.
/**
* Deletes all of the snapshots of a VM.
*/
public void consolidateAllSnapshots() throws Exception {
ManagedObjectReference task = _context.getService().removeAllSnapshotsTask(_mor, true);
boolean result = _context.getVimClient().waitForTask(task);
if (result) {
_context.waitForTaskProgressDone(task);
} else {
throw new Exception("Unable to register VM due to the following issue: " + TaskMO.getTaskFailureInfo(_context, task));
}
}
use of com.vmware.vim25.mo.Task in project cloudstack by apache.
the class VirtualMachineMO method powerOffNoCheck.
private boolean powerOffNoCheck() throws Exception {
ManagedObjectReference morTask = _context.getService().powerOffVMTask(_mor);
boolean result = _context.getVimClient().waitForTask(morTask);
if (result) {
_context.waitForTaskProgressDone(morTask);
// It seems that even if a power-off task is returned done, VM state may still not be marked,
// wait up to 5 seconds to make sure to avoid race conditioning for immediate following on operations
// that relies on a powered-off VM
long startTick = System.currentTimeMillis();
while (getResetSafePowerState() != VirtualMachinePowerState.POWERED_OFF && System.currentTimeMillis() - startTick < 5000) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
s_logger.debug("[ignored] interrupted while powering of vm unconditionally.");
}
}
return true;
} else {
if (getResetSafePowerState() == VirtualMachinePowerState.POWERED_OFF) {
// to help deal with possible race-condition
s_logger.info("Current power-off task failed. However, VM has been switched to the state we are expecting for");
return true;
}
s_logger.error("VMware powerOffVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
return false;
}
Aggregations