use of com.vmware.xenon.common.Operation 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.xenon.common.Operation in project photon-model by vmware.
the class TestVSphereOvfProvisionTaskBase method findFirstOvfDescriptionLink.
protected String findFirstOvfDescriptionLink() throws Exception {
QueryTask.Query q = QueryTask.Query.Builder.create().addFieldClause(ComputeService.ComputeState.FIELD_NAME_ID, "ovf-", QueryTask.QueryTerm.MatchType.PREFIX).build();
QueryTask qt = QueryTask.Builder.createDirectTask().setQuery(q).build();
Operation op = QueryUtils.createQueryTaskOperation(this.host, qt, ServiceTypeCluster.INVENTORY_SERVICE);
QueryTask result = this.host.waitForResponse(op).getBody(QueryTask.class);
return result.results.documentLinks.get(0);
}
use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class TestVSphereProvisionWithStaticIpTask method findTemplate.
private ComputeState findTemplate() throws InterruptedException, ExecutionException, TimeoutException {
String templateVmName = System.getProperty("vc.templateVmName");
QuerySpecification qs = new QuerySpecification();
qs.options.add(QueryOption.EXPAND_CONTENT);
qs.query.addBooleanClause(Query.Builder.create().addFieldClause(ComputeState.FIELD_NAME_NAME, templateVmName).addFieldClause(ServiceDocument.FIELD_NAME_KIND, Utils.buildKind(ComputeState.class)).build());
QueryTask qt = QueryTask.create(qs).setDirect(true);
Operation op = QueryUtils.createQueryTaskOperation(this.host, qt, ServiceTypeCluster.INVENTORY_SERVICE);
QueryTask result = this.host.sendWithFuture(op).thenApply(o -> o.getBody(QueryTask.class)).get(10, TimeUnit.SECONDS);
return Utils.fromJson(result.results.documents.values().iterator().next(), ComputeState.class);
}
use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class TestVSphereProvisionWithStaticIpTask method fetchServiceState.
private <T extends ServiceDocument> T fetchServiceState(Class<T> bodyType, String networkLink) {
Operation op = Operation.createGet(this.host, networkLink);
op = this.host.waitForResponse(op);
return op.getBody(bodyType);
}
use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class TestDatacenterListerService method listDatacenters.
@Test
public void listDatacenters() {
EnumerateDatacentersRequest req = new EnumerateDatacentersRequest();
req.host = URI.create(vcUrl).getHost();
req.username = vcUsername;
req.password = vcPassword;
req.isMock = isMock();
Operation op = Operation.createPatch(this.host, VSphereUriPaths.DC_ENUMERATOR_SERVICE).setBody(req);
op = this.host.waitForResponse(op);
assertEquals(Operation.STATUS_CODE_OK, op.getStatusCode());
assertNotNull(op.getBodyRaw());
if (!isMock()) {
EnumerateDatacentersResponse resp = op.getBody(EnumerateDatacentersResponse.class);
assertTrue(resp.datacenters.contains(datacenterId));
}
}
Aggregations