Search in sources :

Example 1 with ImportOvfRequest

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;
}
Also used : ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) VirtualDiskType(com.vmware.vim25.VirtualDiskType) ProvisionComputeTaskService(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService) Operation(com.vmware.xenon.common.Operation) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) VirtualDisk(com.vmware.vim25.VirtualDisk) GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) BasicConnection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection) ImportOvfRequest(com.vmware.photon.controller.model.adapters.vsphere.ovf.ImportOvfRequest)

Example 2 with ImportOvfRequest

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);
        }
    }
}
Also used : ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) ImportOvfRequest(com.vmware.photon.controller.model.adapters.vsphere.ovf.ImportOvfRequest) ProvisionComputeTaskService(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService) Operation(com.vmware.xenon.common.Operation) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) Test(org.junit.Test)

Example 3 with ImportOvfRequest

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);
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) Query(com.vmware.xenon.services.common.QueryTask.Query) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) ImportOvfRequest(com.vmware.photon.controller.model.adapters.vsphere.ovf.ImportOvfRequest) Operation(com.vmware.xenon.common.Operation) File(java.io.File) Test(org.junit.Test)

Aggregations

ImportOvfRequest (com.vmware.photon.controller.model.adapters.vsphere.ovf.ImportOvfRequest)3 Operation (com.vmware.xenon.common.Operation)3 ComputeDescriptionService (com.vmware.photon.controller.model.resources.ComputeDescriptionService)2 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)2 ProvisionComputeTaskService (com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService)2 Test (org.junit.Test)2 BasicConnection (com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection)1 GetMoRef (com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef)1 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)1 VirtualDisk (com.vmware.vim25.VirtualDisk)1 VirtualDiskFlatVer2BackingInfo (com.vmware.vim25.VirtualDiskFlatVer2BackingInfo)1 VirtualDiskType (com.vmware.vim25.VirtualDiskType)1 QueryTask (com.vmware.xenon.services.common.QueryTask)1 Query (com.vmware.xenon.services.common.QueryTask.Query)1 File (java.io.File)1