use of com.vmware.photon.controller.model.adapters.vsphere.ovf.ImportOvfRequest in project photon-model by vmware.
the class TestVSphereOvfProvisionTaskBase method deployOvfAndReturnComputeState.
private ComputeService.ComputeState deployOvfAndReturnComputeState(boolean isStoragePolicyBased, boolean withAdditionalDisks, Map<String, String> customProperties, boolean isSnapshotLimitCase) throws Throwable {
ComputeService.ComputeState vm = null;
// Create a resource pool where the VM will be housed
this.resourcePool = createResourcePool();
this.auth = createAuth();
this.computeHostDescription = createComputeDescription();
this.computeHost = createComputeHost(this.computeHostDescription);
ComputeDescriptionService.ComputeDescription computeDesc = createTemplate();
ImportOvfRequest req = new ImportOvfRequest();
req.ovfUri = this.ovfUri;
req.template = computeDesc;
Operation op = Operation.createPatch(this.host, OvfImporterService.SELF_LINK).setBody(req).setReferer(this.host.getPublicUri());
CompletableFuture<Operation> f = this.host.sendWithFuture(op);
// depending on OVF location you may want to increase the timeout
f.get(360, TimeUnit.SECONDS);
snapshotFactoryState("ovf", ComputeDescriptionService.class);
enumerateComputes(this.computeHost);
String descriptionLink = findFirstOvfDescriptionLink();
this.bootDisk = createBootDiskWithCustomProperties(CLOUD_CONFIG_DATA, isStoragePolicyBased, customProperties);
vm = createVmState(descriptionLink, withAdditionalDisks, customProperties, isSnapshotLimitCase);
// set timeout for the next step, vmdk upload may take some time
host.setTimeoutSeconds(60 * 5);
// provision
ProvisionComputeTaskService.ProvisionComputeTaskState outTask = createProvisionTask(vm);
awaitTaskEnd(outTask);
vm = getComputeState(vm);
snapshotFactoryState("ovf", ComputeService.class);
if (!isMock() && withAdditionalDisks || customProperties.get(PROVISION_TYPE) != null) {
BasicConnection connection = createConnection();
GetMoRef get = new GetMoRef(connection);
List<VirtualDisk> virtualDisks = fetchAllVirtualDisks(vm, get);
if (customProperties.get(PROVISION_TYPE) != null) {
VirtualDiskType diskProvisionType = VirtualDiskType.fromValue(customProperties.get(PROVISION_TYPE));
VirtualDisk bootDisk = virtualDisks.stream().filter(vd -> vd.getUnitNumber() == 0).findFirst().orElse(null);
VirtualDiskFlatVer2BackingInfo backing = (VirtualDiskFlatVer2BackingInfo) bootDisk.getBacking();
if (VirtualDiskType.THIN == diskProvisionType) {
assertTrue(backing.isThinProvisioned());
} else if (VirtualDiskType.THICK == diskProvisionType) {
assertFalse(backing.isThinProvisioned());
} else if (VirtualDiskType.EAGER_ZEROED_THICK == diskProvisionType) {
assertFalse(backing.isThinProvisioned());
assertTrue(backing.isEagerlyScrub());
}
}
if (withAdditionalDisks) {
assertEquals(3, virtualDisks.size());
}
}
return vm;
}
use of com.vmware.photon.controller.model.adapters.vsphere.ovf.ImportOvfRequest in project photon-model by vmware.
the class TestVSphereOvfProvisionTaskWithStorage method deployOvfWithoutDatastore.
@Test
public void deployOvfWithoutDatastore() throws Throwable {
if (this.ovfUri == null) {
return;
}
// Re-init the datastore Id to null;
this.dataStoreId = null;
ComputeService.ComputeState vm = null;
try {
// Create a resource pool where the VM will be housed
this.resourcePool = createResourcePool();
this.auth = createAuth();
this.computeHostDescription = createComputeDescription();
this.computeHost = createComputeHost(this.computeHostDescription);
ComputeDescriptionService.ComputeDescription computeDesc = createTemplate();
ImportOvfRequest req = new ImportOvfRequest();
req.ovfUri = this.ovfUri;
req.template = computeDesc;
Operation op = Operation.createPatch(this.host, OvfImporterService.SELF_LINK).setBody(req).setReferer(this.host.getPublicUri());
CompletableFuture<Operation> f = this.host.sendWithFuture(op);
// depending on OVF location you may want to increase the timeout
f.get(300, TimeUnit.SECONDS);
snapshotFactoryState("ovf", ComputeDescriptionService.class);
enumerateComputes(this.computeHost);
String descriptionLink = findFirstOvfDescriptionLink();
this.bootDisk = createBootDisk(CLOUD_CONFIG_DATA);
vm = createVmState(descriptionLink);
// set timeout for the next step, vmdk upload may take some time
host.setTimeoutSeconds(60 * 5);
// provision
ProvisionComputeTaskService.ProvisionComputeTaskState outTask = createProvisionTask(vm);
awaitTaskEnd(outTask);
snapshotFactoryState("ovf", ComputeService.class);
} finally {
if (vm != null) {
deleteVmAndWait(vm);
}
}
}
use of com.vmware.photon.controller.model.adapters.vsphere.ovf.ImportOvfRequest in project photon-model by vmware.
the class TestVSphereOvfImport method importOvfAsDescriptions.
@Test
public void importOvfAsDescriptions() throws Throwable {
this.resourcePool = createResourcePool();
this.auth = createAuth();
this.computeHostDescription = createComputeDescription();
createComputeHost();
ComputeDescription computeDesc = new ComputeDescription();
computeDesc.supportedChildren = new ArrayList<>();
computeDesc.instanceAdapterReference = UriUtils.buildUri(this.host, VSphereUriPaths.INSTANCE_SERVICE);
computeDesc.authCredentialsLink = this.auth.documentSelfLink;
computeDesc.name = computeDesc.id;
computeDesc.dataStoreId = this.dataStoreId;
ImportOvfRequest req = new ImportOvfRequest();
req.ovfUri = new File("src/test/resources/vcenter.ovf").toURI();
req.template = computeDesc;
Operation op = Operation.createPatch(this.host, OvfImporterService.SELF_LINK).setBody(req).setReferer(this.host.getPublicUri());
op = this.host.waitForResponse(op);
assertEquals(Operation.STATUS_CODE_OK, op.getStatusCode());
Query q = Query.Builder.create().addFieldClause(ComputeState.FIELD_NAME_ID, "ovf-", MatchType.PREFIX).build();
QueryTask task = QueryTask.Builder.createDirectTask().setQuery(q).build();
QueryUtils.createQueryTaskOperation(this.host, task, ServiceTypeCluster.INVENTORY_SERVICE);
task = this.host.waitForResponse(op).getBody(QueryTask.class);
assertTrue(task.results.documentLinks.size() > 5);
snapshotFactoryState("ovf", ComputeDescriptionService.class);
}
Aggregations