use of com.vmware.vim25.mo.Task in project vsphere-cloud-plugin by jenkinsci.
the class VSphere method suspendVm.
public void suspendVm(VirtualMachine vm) throws VSphereException {
if (isPoweredOn(vm)) {
try {
// TODO is this better?
// vm.shutdownGuest()
final Task task = vm.suspendVM_Task();
final String status = task.waitForTask();
if (Task.SUCCESS.equals(status)) {
LOGGER.log(Level.FINER, "VM was suspended successfully.");
return;
}
throw newVSphereException(task.getTaskInfo(), "Machine could not be suspended!");
} catch (RuntimeException | VSphereException e) {
throw e;
} catch (Exception e) {
throw new VSphereException(e);
}
} else {
LOGGER.log(Level.FINER, "Machine not powered on.");
return;
}
}
use of com.vmware.vim25.mo.Task in project vsphere-cloud-plugin by jenkinsci.
the class VSphere method revertToSnapshot.
public void revertToSnapshot(String vmName, String snapName) throws VSphereException {
VirtualMachine vm = getVmByName(vmName);
VirtualMachineSnapshot snap = getSnapshotInTree(vm, snapName);
if (snap == null) {
LOGGER.log(Level.SEVERE, "Cannot find snapshot: '" + snapName + "' for virtual machine: '" + vm.getName() + "'");
throw new VSphereNotFoundException("Snapshot", snapName);
}
try {
Task task = snap.revertToSnapshot_Task(null);
if (!task.waitForTask().equals(Task.SUCCESS)) {
final String msg = "Could not revert to snapshot '" + snap.toString() + "' for virtual machine:'" + vm.getName() + "'";
LOGGER.log(Level.SEVERE, msg);
throw newVSphereException(task.getTaskInfo(), msg);
}
} catch (RuntimeException | VSphereException e) {
throw e;
} catch (Exception e) {
throw new VSphereException(e);
}
}
use of com.vmware.vim25.mo.Task in project vsphere-cloud-plugin by jenkinsci.
the class VSphere method deleteSnapshot.
public void deleteSnapshot(String vmName, String snapName, boolean consolidate, boolean failOnNoExist) throws VSphereException {
VirtualMachine vm = getVmByName(vmName);
VirtualMachineSnapshot snap = getSnapshotInTree(vm, snapName);
if (snap == null && failOnNoExist) {
throw new VSphereNotFoundException("Snapshot", snapName);
}
try {
Task task;
if (snap != null) {
// Does not delete subtree; Implicitly consolidates disk
task = snap.removeSnapshot_Task(false);
if (!task.waitForTask().equals(Task.SUCCESS)) {
throw newVSphereException(task.getTaskInfo(), "Could not delete snapshot");
}
}
if (!consolidate)
return;
// This might be redundant, but I think it consolidates all disks,
// where as the removeSnapshot only consolidates the individual disk
task = vm.consolidateVMDisks_Task();
if (!task.waitForTask().equals(Task.SUCCESS)) {
throw newVSphereException(task.getTaskInfo(), "Could not consolidate VM disks");
}
} catch (RuntimeException | VSphereException e) {
throw e;
} catch (Exception e) {
throw new VSphereException(e);
}
}
use of com.vmware.vim25.mo.Task in project vsphere-cloud-plugin by jenkinsci.
the class vSphereCloudLauncher method resetVM.
private void resetVM(VirtualMachine vm, SlaveComputer slaveComputer, TaskListener taskListener) throws RemoteException, InterruptedException {
vSphereCloud.Log(slaveComputer, taskListener, "Resetting the VM");
Task taskReset = vm.resetVM_Task();
if (!taskReset.waitForTask().equals(Task.SUCCESS)) {
vSphereCloud.Log(slaveComputer, taskListener, "Unable to reset the VM");
}
}
use of com.vmware.vim25.mo.Task in project vsphere-cloud-plugin by jenkinsci.
the class vSphereCloudLauncher method revertVM.
private void revertVM(VirtualMachine vm, vSphereCloud vsC, SlaveComputer slaveComputer, TaskListener taskListener) throws IOException, InterruptedException, VSphereException {
if (!snapName.isEmpty()) {
VirtualMachineSnapshot snap = vsC.vSphereInstance().getSnapshotInTree(vm, snapName);
if (snap == null) {
throw new IOException("Virtual Machine snapshot cannot be found");
}
vSphereCloud.Log(slaveComputer, taskListener, "Reverting to snapshot:" + snapName);
Task task = snap.revertToSnapshot_Task(null);
if (!task.waitForTask().equals(Task.SUCCESS)) {
throw new IOException("Error while reverting to virtual machine snapshot");
}
} else {
vSphereCloud.Log(slaveComputer, taskListener, "Reverting to current snapshot");
Task task = vm.revertToCurrentSnapshot_Task(null);
if (!task.waitForTask().equals(Task.SUCCESS)) {
throw new IOException("Error while reverting to virtual machine snapshot");
}
}
}
Aggregations