Search in sources :

Example 1 with BasicConnection

use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection 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 BasicConnection

use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection 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);
        }
    }
}
Also used : ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) BasicConnection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection) ProvisionComputeTaskService(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) Test(org.junit.Test)

Example 3 with BasicConnection

use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection 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);
        }
    }
}
Also used : ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) ProvisionComputeTaskService(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) VirtualDisk(com.vmware.vim25.VirtualDisk) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) BasicConnection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 4 with BasicConnection

use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection in project photon-model by vmware.

the class TestVSphereLibraryProvisionTaskWithStorage method deployFromLibraryWithStoragePolicy.

@Test
public void deployFromLibraryWithStoragePolicy() throws Throwable {
    ComputeService.ComputeState vm = provisionVMAndGetState(true, false);
    try {
        if (vm == null) {
            return;
        }
        // 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 (vm != null) {
            deleteVmAndWait(vm);
        }
    }
}
Also used : GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) BasicConnection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) Test(org.junit.Test)

Example 5 with BasicConnection

use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection in project photon-model by vmware.

the class TestVSphereLibraryProvisionTaskWithDay2 method deployFromLibraryAndResetVM.

@Test
public void deployFromLibraryAndResetVM() throws Throwable {
    ComputeService.ComputeState vm = provisionVMAndGetState();
    try {
        if (vm == null) {
            return;
        }
        // test reset VM operation
        resetVSphereVM(vm);
        BasicConnection connection = createConnection();
        GetMoRef get = new GetMoRef(connection);
        verifyDiskSize(vm, get, HDD_DISK_SIZE);
    } finally {
        if (vm != null) {
            deleteVmAndWait(vm);
        }
    }
}
Also used : GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) BasicConnection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) Test(org.junit.Test)

Aggregations

BasicConnection (com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection)20 GetMoRef (com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef)11 Test (org.junit.Test)10 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)9 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)6 ComputeDescriptionService (com.vmware.photon.controller.model.resources.ComputeDescriptionService)4 ProvisionComputeTaskService (com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService)4 VirtualDisk (com.vmware.vim25.VirtualDisk)3 Operation (com.vmware.xenon.common.Operation)3 DatacenterLister (com.vmware.photon.controller.model.adapters.vsphere.util.finders.DatacenterLister)2 DiskService (com.vmware.photon.controller.model.resources.DiskService)2 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)2 RegionEnumerationResponse (com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse)1 EndpointAdapterUtils (com.vmware.photon.controller.model.adapters.util.EndpointAdapterUtils)1 PROVIDER_DISK_UNIQUE_ID (com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.PROVIDER_DISK_UNIQUE_ID)1 EnumerationClientTest (com.vmware.photon.controller.model.adapters.vsphere.EnumerationClientTest)1 ImportOvfRequest (com.vmware.photon.controller.model.adapters.vsphere.ovf.ImportOvfRequest)1 ConnectionException (com.vmware.photon.controller.model.adapters.vsphere.util.connection.ConnectionException)1 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)1 ComputeStateWithDescription (com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription)1