use of com.vmware.vim25.mo.Task in project coprhd-controller by CoprHD.
the class VMwareTask method cancelTask.
public void cancelTask(Task task) throws Exception {
if (task == null || task.getTaskInfo() == null) {
warn("VMware task is null or has no task info. Unable to cancel it.");
} else {
TaskInfoState state = task.getTaskInfo().getState();
if (state == TaskInfoState.queued || state == TaskInfoState.running) {
info("Cancelling task '%s'", getDetail());
task.cancelTask();
}
}
}
use of com.vmware.vim25.mo.Task in project cloudstack by apache.
the class VirtualMachineMO method createSnapshot.
public boolean createSnapshot(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 false;
}
s_logger.debug("Waited for " + (System.currentTimeMillis() - startTick) + " seconds for snapshot object [" + snapshotName + "] to appear in vCenter.");
return true;
} else {
s_logger.error("VMware createSnapshot_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
return false;
}
use of com.vmware.vim25.mo.Task in project photon-model by vmware.
the class TestVSphereCloneTaskWithStorage method verifyBootDiskCustomization.
@Test
public void verifyBootDiskCustomization() throws Throwable {
ComputeService.ComputeState vm = null;
try {
this.auth = createAuth();
this.resourcePool = createResourcePool();
if (isMock()) {
createNetwork(networkId);
}
this.computeHostDescription = createComputeDescription();
this.computeHost = createComputeHost(this.computeHostDescription);
doRefresh();
snapshotFactoryState("clone-refresh", NetworkService.class);
ComputeDescriptionService.ComputeDescription vmDescription = createVmDescription();
vm = createVmState(vmDescription, true, null);
// kick off a provision task to do the actual VM creation
ProvisionComputeTaskService.ProvisionComputeTaskState provisionTask = createProvisionTask(vm);
awaitTaskEnd(provisionTask);
vm = getComputeState(vm);
// put fake moref in the vm
if (isMock()) {
ManagedObjectReference moref = new ManagedObjectReference();
moref.setValue("vm-0");
moref.setType(VimNames.TYPE_VM);
CustomProperties.of(vm).put(MOREF, moref);
vm = doPost(this.host, vm, ComputeService.ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
}
if (!isMock()) {
// Verify that the disk is resized
BasicConnection connection = createConnection();
GetMoRef get = new GetMoRef(connection);
verifyDiskSize(vm, get, HDD_DISK_SIZE);
verifyDiskProperties(vm, get);
}
} finally {
if (!isMock() && vm != null) {
deleteVmAndWait(vm);
}
}
}
use of com.vmware.vim25.mo.Task in project photon-model by vmware.
the class TestVSphereCloneTaskBase method createInstanceFromTemplate.
protected void createInstanceFromTemplate(boolean withAdditionalDisks) throws Throwable {
ComputeService.ComputeState vm = null;
ComputeService.ComputeState clonedVm = null;
try {
this.auth = createAuth();
this.resourcePool = createResourcePool();
if (isMock()) {
createNetwork(networkId);
}
this.computeHostDescription = createComputeDescription();
this.computeHost = createComputeHost(this.computeHostDescription);
EndpointState ep = createEndpointState(this.computeHost, this.computeHostDescription);
this.endpoint = TestUtils.doPost(this.host, ep, EndpointState.class, UriUtils.buildUri(this.host, EndpointService.FACTORY_LINK));
doRefresh();
snapshotFactoryState("clone-refresh", NetworkService.class);
ComputeDescriptionService.ComputeDescription vmDescription = createVmDescription();
vm = createVmState(vmDescription, false, null, withAdditionalDisks);
// kick off a provision task to do the actual VM creation
ProvisionComputeTaskService.ProvisionComputeTaskState provisionTask = createProvisionTask(vm);
awaitTaskEnd(provisionTask);
vm = getComputeState(vm);
// put fake moref in the vm
if (isMock()) {
ManagedObjectReference moref = new ManagedObjectReference();
moref.setValue("vm-0");
moref.setType(VimNames.TYPE_VM);
CustomProperties.of(vm).put(MOREF, moref);
vm = doPost(this.host, vm, ComputeService.ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
}
// create state & desc of the clone
ComputeDescriptionService.ComputeDescription cloneDescription = createCloneDescription(vm.documentSelfLink);
clonedVm = createCloneVmState(cloneDescription, false, withAdditionalDisks);
provisionTask = createProvisionTask(clonedVm);
awaitTaskEnd(provisionTask);
clonedVm = getComputeState(clonedVm);
if (!isMock()) {
// Verify that the disk is resized
BasicConnection connection = createConnection();
GetMoRef get = new GetMoRef(connection);
if (withAdditionalDisks) {
List<VirtualDisk> virtualDisks = fetchAllVirtualDisks(vm, get);
assertEquals(3, virtualDisks.size());
} else {
verifyDiskSize(clonedVm, get, CLONE_HDD_DISK_SIZE);
}
}
} finally {
if (!isMock()) {
cleanUpVm(vm, clonedVm);
}
}
}
use of com.vmware.vim25.mo.Task in project photon-model by vmware.
the class TestVSphereComputeDiskDay2Service method testDiskOperationOnCompute.
@Test
public /**
* 1. Create a VM
* 2. Create a HDD disk
* 3. Attach HDD disk created in Step 2 to VM.
* 4. Attach a CD-ROM disk
* 5. Attach a Floppy disk
* 6. Detach HDD disk created in step 2
* 7. Delete VM.
* 8. Delete HDD disk
*/
void testDiskOperationOnCompute() throws Throwable {
DiskService.DiskState diskState = null;
try {
// Step 1: Create VM
prepareEnvironment();
if (isMock()) {
createNetwork(networkId);
}
snapshotFactoryState("clone-refresh", NetworkService.class);
ComputeDescriptionService.ComputeDescription vmDescription = createVmDescription();
this.vm = createVmState(vmDescription, true, null, false);
// kick off a provision task to do the actual VM creation
ProvisionComputeTaskService.ProvisionComputeTaskState provisionTask = createProvisionTask(this.vm);
awaitTaskEnd(provisionTask);
this.vm = getComputeState(this.vm);
// put fake moref in the vm
if (isMock()) {
ManagedObjectReference moref = new ManagedObjectReference();
moref.setValue("vm-0");
moref.setType(VimNames.TYPE_VM);
CustomProperties.of(this.vm).put(MOREF, moref);
this.vm = doPost(this.host, this.vm, ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
return;
}
// Step 2: Create Disk
diskState = createDiskWithDatastore("AdditionalDisk1", DiskService.DiskType.HDD, ADDITIONAL_DISK_SIZE, buildCustomProperties(), false);
// start provision task to do the actual disk creation
String documentSelfLink = performDiskRequest(diskState, ProvisionDiskTaskService.ProvisionDiskTaskState.SubStage.CREATING_DISK);
this.host.waitForFinishedTask(ProvisionDiskTaskService.ProvisionDiskTaskState.class, documentSelfLink);
// Step 3: Attach Disk created in step 2
ResourceOperationRequest request = createResourceOperationRequest(diskState, createComputeDiskTaskService(), ResourceOperation.ATTACH_DISK);
sendRequest(request, DiskService.DiskType.HDD, computeAttachWaitHandler());
this.vm = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, this.vm.documentSelfLink));
// Step 4: Attach a CD-ROM disk
// prepare a disk with CD-ROM type
DiskService.DiskState cdDiskState = createCDromWithIso("cdrom-1", DiskService.DiskType.CDROM, 0, null, 1024, null, false, true);
request = createResourceOperationRequest(cdDiskState, createComputeDiskTaskService(), ResourceOperation.ATTACH_DISK);
sendRequest(request, DiskService.DiskType.CDROM, computeAttachWaitHandler());
this.vm = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, this.vm.documentSelfLink));
this.CDDiskState = this.host.getServiceState(null, DiskService.DiskState.class, UriUtils.buildUri(this.host, cdDiskState.documentSelfLink));
// Step 5: Attach a floppy disk
DiskService.DiskState floppyDiskState = createDisk("floppy-1", DiskService.DiskType.FLOPPY, 0, null, 1024, null);
request = createResourceOperationRequest(floppyDiskState, createComputeDiskTaskService(), ResourceOperation.ATTACH_DISK);
sendRequest(request, DiskService.DiskType.FLOPPY, computeAttachWaitHandler());
this.vm = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, this.vm.documentSelfLink));
assertNotNull(this.vm.diskLinks);
assertEquals(6, this.vm.diskLinks.size());
// Get the latest state of the attached disk
diskState = this.host.getServiceState(null, DiskService.DiskState.class, UriUtils.buildUri(this.host, diskState.documentSelfLink));
assertEquals(DiskService.DiskStatus.ATTACHED, diskState.status);
// Step 6: Detach HDD disk create in Step 2 from VM
request = createResourceOperationRequest(diskState, createComputeDiskTaskService(), ResourceOperation.DETACH_DISK);
sendRequest(request, DiskService.DiskType.HDD, computeDetachWaitHandler());
this.vm = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, this.vm.documentSelfLink));
assertNotNull(this.vm.diskLinks);
assertEquals(5, this.vm.diskLinks.size());
// Get the latest state of the detached disk
diskState = this.host.getServiceState(null, DiskService.DiskState.class, UriUtils.buildUri(this.host, diskState.documentSelfLink));
assertEquals(DiskService.DiskStatus.AVAILABLE, diskState.status);
} finally {
if (!isMock()) {
// Step 7: Delete VM
cleanUpVm(this.vm, null);
// Step 8: Delete disk
if (diskState != null) {
String documentSelfLink = performDiskRequest(diskState, ProvisionDiskTaskService.ProvisionDiskTaskState.SubStage.DELETING_DISK);
this.host.waitForFinishedTask(ProvisionDiskTaskService.ProvisionDiskTaskState.class, documentSelfLink);
}
}
}
}
Aggregations