Search in sources :

Example 16 with GetMoRef

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

the class TestVSphereLibraryProvisionTaskWithDay2 method deployFromLibraryWithShutdown.

@Test
public void deployFromLibraryWithShutdown() throws Throwable {
    ComputeService.ComputeState vm = provisionVMAndGetState();
    try {
        if (vm == null) {
            return;
        }
        // test shutdown Guest OS resource operation
        shutdownGuestOS(vm);
        // Verify that the disk is resized and is reflected even for a POWERED_OFF 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)

Example 17 with GetMoRef

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

the class TestVSphereLibraryProvisionTaskWithDay2 method deployFromLibraryWithReboot.

@Test
public void deployFromLibraryWithReboot() throws Throwable {
    ComputeService.ComputeState vm = provisionVMAndGetState();
    try {
        if (vm == null) {
            return;
        }
        // test reboot resource operation
        rebootVSphereVMAndWait(vm);
        // Verify that the disk is resized
        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)

Example 18 with GetMoRef

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

the class TestVSphereCloneTaskWithStorage method verifyBootDiskCustomizationWithStoragePolicy.

@Test
public void verifyBootDiskCustomizationWithStoragePolicy() 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);
        doRefresh();
        snapshotFactoryState("clone-refresh", NetworkService.class);
        ComputeDescriptionService.ComputeDescription vmDescription = createVmDescription();
        DiskService.DiskState bootDisk = createDiskWithStoragePolicy("boot", DiskService.DiskType.HDD, 1, getDiskUri(), HDD_DISK_SIZE, buildCustomProperties());
        vm = createVmState(vmDescription, true, bootDisk.documentSelfLink);
        // 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, true, false);
        provisionTask = createProvisionTask(clonedVm);
        awaitTaskEnd(provisionTask);
        clonedVm = getComputeState(clonedVm);
        if (!isMock()) {
            // Verify that the disk is resized
            BasicConnection connection = createConnection();
            GetMoRef get = new GetMoRef(connection);
            verifyDiskSize(vm, get, HDD_DISK_SIZE);
            verifyDiskSize(clonedVm, get, CLONE_HDD_DISK_SIZE);
            verifyDiskProperties(vm, get);
        }
    } finally {
        if (!isMock()) {
            cleanUpVm(vm, clonedVm);
        }
    }
}
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) DiskService(com.vmware.photon.controller.model.resources.DiskService) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) Test(org.junit.Test)

Example 19 with GetMoRef

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

the class StatsClient method createLookup.

/**
 * cache perfCounters per connections. The call is slow as the response can be about 400kb
 * of xml.
 * @param conn
 * @return
 */
private static PerfCounterLookup createLookup(Connection conn) {
    return lookups.computeIfAbsent(conn.getURI(), u -> {
        GetMoRef get = new GetMoRef(conn);
        ArrayOfPerfCounterInfo counters;
        try {
            counters = get.entityProp(PERF_MGR_MOREF, PROP_PERF_COUNTER);
        } catch (Exception e) {
            throw new RuntimeException("cannot create lookup for " + u, e);
        }
        return new PerfCounterLookup(counters.getPerfCounterInfo());
    });
}
Also used : GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) ArrayOfPerfCounterInfo(com.vmware.vim25.ArrayOfPerfCounterInfo)

Example 20 with GetMoRef

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

the class InstanceClient method deployOvf.

private ManagedObjectReference deployOvf(URI ovfUri) throws Exception {
    OvfDeployer deployer = new OvfDeployer(this.connection);
    CustomProperties cust = CustomProperties.of(this.ctx.child.description);
    URI archiveUri = cust.getUri(OvfParser.PROP_OVF_ARCHIVE_URI);
    if (archiveUri != null) {
        logger.info("Prefer ova {} uri to ovf {}", archiveUri, ovfUri);
        OvfRetriever retriever = deployer.getRetriever();
        ovfUri = retriever.downloadIfOva(archiveUri);
    }
    ManagedObjectReference folder = getVmFolder();
    List<VirtualMachineDefinedProfileSpec> pbmSpec = getPbmProfileSpec(this.bootDisk);
    ManagedObjectReference ds = getDataStoreForDisk(this.bootDisk, pbmSpec);
    ManagedObjectReference resourcePool = getResourcePool();
    String vmName = "pmt-" + deployer.getRetriever().hash(ovfUri);
    GetMoRef get = new GetMoRef(this.connection);
    ManagedObjectReference vm = findTemplateByName(vmName, get);
    if (vm == null) {
        String config = cust.getString(OvfParser.PROP_OVF_CONFIGURATION);
        Lock lock = getLock(vmName);
        lock.lock();
        try {
            vm = findTemplateByName(vmName, get);
            if (vm == null) {
                OvfParser parser = new OvfParser();
                Document ovfDoc = parser.retrieveDescriptor(ovfUri);
                List<OvfNetworkMapping> networks = mapNetworks(parser.extractNetworks(ovfDoc), ovfDoc, this.ctx.nics);
                vm = deployer.deployOvf(ovfUri, getHost(), folder, vmName, networks, ds, Collections.emptyList(), config, resourcePool);
                logger.info("Removing NICs from deployed template: {} ({})", vmName, vm.getValue());
                ArrayOfVirtualDevice devices = get.entityProp(vm, VimPath.vm_config_hardware_device);
                if (devices != null) {
                    VirtualMachineConfigSpec reconfig = new VirtualMachineConfigSpec();
                    for (VirtualDevice device : devices.getVirtualDevice()) {
                        if (device instanceof VirtualEthernetCard) {
                            VirtualDeviceConfigSpec spec = new VirtualDeviceConfigSpec();
                            spec.setDevice(device);
                            spec.setOperation(VirtualDeviceConfigSpecOperation.REMOVE);
                            reconfig.getDeviceChange().add(spec);
                        }
                    }
                    ManagedObjectReference reconfigTask = getVimPort().reconfigVMTask(vm, reconfig);
                    VimUtils.waitTaskEnd(this.connection, reconfigTask);
                }
                ManagedObjectReference snapshotTask = getVimPort().createSnapshotTask(vm, "initial", null, false, false);
                VimUtils.waitTaskEnd(this.connection, snapshotTask);
            }
        } catch (Exception e) {
            logger.warn("Error deploying Ovf for template [" + vmName + "],reason:", e);
            vm = awaitVM(vmName, folder, get);
        } finally {
            lock.unlock();
        }
    }
    if (!isSameDatastore(ds, vm, get)) {
        // make sure the original VM template is ready
        Object snapshot = get.entityProp(vm, VimPath.vm_snapshot);
        if (snapshot == null) {
            vm = awaitVM(vmName, folder, get);
        }
        vm = replicateVMTemplate(resourcePool, ds, pbmSpec, folder, vmName, vm, get);
    }
    return cloneOvfBasedTemplate(vm, ds, folder, resourcePool, pbmSpec);
}
Also used : OvfRetriever(com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfRetriever) OvfNetworkMapping(com.vmware.vim25.OvfNetworkMapping) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) OvfDeployer(com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfDeployer) ClientUtils.findMatchingVirtualDevice(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.findMatchingVirtualDevice) ArrayOfVirtualDevice(com.vmware.vim25.ArrayOfVirtualDevice) VirtualDevice(com.vmware.vim25.VirtualDevice) OvfParser(com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfParser) ArrayOfVirtualDevice(com.vmware.vim25.ArrayOfVirtualDevice) VirtualMachineDefinedProfileSpec(com.vmware.vim25.VirtualMachineDefinedProfileSpec) Document(org.w3c.dom.Document) URI(java.net.URI) FinderException(com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException) Lock(java.util.concurrent.locks.Lock) ReentrantLock(java.util.concurrent.locks.ReentrantLock) GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualEthernetCard(com.vmware.vim25.VirtualEthernetCard) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

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