Search in sources :

Example 1 with GetMoRef

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

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

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

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

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

GetMoRef (com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef)20 BasicConnection (com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection)13 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)13 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)12 Test (org.junit.Test)8 VirtualDisk (com.vmware.vim25.VirtualDisk)7 Operation (com.vmware.xenon.common.Operation)7 ComputeDescriptionService (com.vmware.photon.controller.model.resources.ComputeDescriptionService)6 ProvisionComputeTaskService (com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService)6 VimPath (com.vmware.photon.controller.model.adapters.vsphere.util.VimPath)5 ComputeProperties (com.vmware.photon.controller.model.ComputeProperties)4 DiskService (com.vmware.photon.controller.model.resources.DiskService)4 InvalidPropertyFaultMsg (com.vmware.vim25.InvalidPropertyFaultMsg)4 RuntimeFaultFaultMsg (com.vmware.vim25.RuntimeFaultFaultMsg)4 SubnetState (com.vmware.photon.controller.model.resources.SubnetService.SubnetState)3 PhotonModelUriUtils (com.vmware.photon.controller.model.util.PhotonModelUriUtils)3 ArrayOfVirtualDevice (com.vmware.vim25.ArrayOfVirtualDevice)3 TaskInfo (com.vmware.vim25.TaskInfo)3 TaskInfoState (com.vmware.vim25.TaskInfoState)3 DeferredResult (com.vmware.xenon.common.DeferredResult)3