Search in sources :

Example 26 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.

the class TestVSphereProvisionWithCloudConfigTask method deployFromTemplateUsingCloudConfig.

@Test
public void deployFromTemplateUsingCloudConfig() throws Throwable {
    ComputeState vm = null;
    try {
        // Create a resource pool where the VM will be housed
        this.resourcePool = createResourcePool();
        this.auth = createAuth();
        this.computeHostDescription = createComputeHostDescription();
        this.computeHost = createComputeHost();
        // enumerate all resources hoping to find the template
        doRefresh();
        // find the template by vm name
        // template must have vm-tools and cloud-config installed
        ComputeState template = findTemplate();
        // create instance by cloning
        ComputeDescription vmDescription = createVmDescription();
        vm = createVmState(vmDescription, template.documentSelfLink);
        // kick off a provision task to do the actual VM creation
        ProvisionComputeTaskState outTask = createProvisionTask(vm);
        awaitTaskEnd(outTask);
        vm = getComputeState(vm);
    } finally {
        if (vm != null) {
            deleteVmAndWait(vm);
        }
    }
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ProvisionComputeTaskState(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService.ProvisionComputeTaskState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) Test(org.junit.Test)

Example 27 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.

the class TestVSphereProvisionWithMissingDatacenter method createPlacementHost.

private ComputeState createPlacementHost() throws Throwable {
    ComputeState computeState = new ComputeState();
    computeState.id = "place here";
    computeState.documentSelfLink = computeState.id;
    computeState.descriptionLink = this.computeHostDescription.documentSelfLink;
    computeState.resourcePoolLink = this.resourcePool.documentSelfLink;
    computeState.adapterManagementReference = getAdapterManagementReference();
    computeState.name = "placement host";
    computeState.powerState = PowerState.ON;
    computeState.parentLink = this.computeHost.documentSelfLink;
    CustomProperties.of(computeState).put(ComputeProperties.RESOURCE_GROUP_NAME, this.vcFolder).put(CustomProperties.MOREF, VimNames.TYPE_CLUSTER_COMPUTE_RESOURCE + ":c123");
    CustomProperties.of(computeState).put(ComputeProperties.RESOURCE_GROUP_NAME, this.vcFolder);
    ComputeState returnState = TestUtils.doPost(this.host, computeState, ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
    return returnState;
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState)

Example 28 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.

the class TestVSphereProvisionWithStaticIpTask method createComputeHost.

/**
 * Create a compute host representing a vcenter server
 */
private ComputeState createComputeHost() throws Throwable {
    ComputeState computeState = new ComputeState();
    computeState.id = UUID.randomUUID().toString();
    computeState.name = this.computeHostDescription.name;
    computeState.documentSelfLink = computeState.id;
    computeState.descriptionLink = this.computeHostDescription.documentSelfLink;
    computeState.resourcePoolLink = this.resourcePool.documentSelfLink;
    computeState.adapterManagementReference = getAdapterManagementReference();
    ComputeState returnState = TestUtils.doPost(this.host, computeState, ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
    return returnState;
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState)

Example 29 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState 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);
}
Also used : PowerState(com.vmware.photon.controller.model.resources.ComputeService.PowerState) Arrays(java.util.Arrays) ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) IpAssignment(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.IpAssignment) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) QueryTask(com.vmware.xenon.services.common.QueryTask) TimeoutException(java.util.concurrent.TimeoutException) ServiceDocument(com.vmware.xenon.common.ServiceDocument) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) ProvisionComputeTaskState(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService.ProvisionComputeTaskState) DiskType(com.vmware.photon.controller.model.resources.DiskService.DiskType) ArrayList(java.util.ArrayList) Utils(com.vmware.xenon.common.Utils) Query(com.vmware.xenon.services.common.QueryTask.Query) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) URI(java.net.URI) VirtualMachineGuestOsIdentifier(com.vmware.vim25.VirtualMachineGuestOsIdentifier) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) NetworkInterfaceDescriptionService(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) TestUtils(com.vmware.photon.controller.model.tasks.TestUtils) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Test(org.junit.Test) UUID(java.util.UUID) File(java.io.File) NetworkService(com.vmware.photon.controller.model.resources.NetworkService) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) IOUtils(org.apache.commons.io.IOUtils) BootConfig(com.vmware.photon.controller.model.resources.DiskService.DiskState.BootConfig) NetworkInterfaceService(com.vmware.photon.controller.model.resources.NetworkInterfaceService) Ignore(org.junit.Ignore) FileEntry(com.vmware.photon.controller.model.resources.DiskService.DiskState.BootConfig.FileEntry) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) Assert(org.junit.Assert) DiskService(com.vmware.photon.controller.model.resources.DiskService) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) Assert.assertEquals(org.junit.Assert.assertEquals) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) QueryTask(com.vmware.xenon.services.common.QueryTask) Operation(com.vmware.xenon.common.Operation)

Example 30 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.

the class TestVSphereStatsTask method createComputeHost.

/**
 * Create a compute host representing a vcenter server
 */
private ComputeState createComputeHost() throws Throwable {
    ComputeState computeState = new ComputeState();
    computeState.id = nextName("host");
    computeState.name = this.computeHostDescription.name;
    computeState.documentSelfLink = computeState.id;
    computeState.descriptionLink = this.computeHostDescription.documentSelfLink;
    // computeState.resourcePoolLink = this.resourcePool.documentSelfLink;
    computeState.adapterManagementReference = getAdapterManagementReference();
    ComputeState returnState = TestUtils.doPost(this.host, computeState, ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
    return returnState;
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState)

Aggregations

ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)214 Operation (com.vmware.xenon.common.Operation)93 ArrayList (java.util.ArrayList)63 QueryTask (com.vmware.xenon.services.common.QueryTask)58 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)57 HashMap (java.util.HashMap)54 List (java.util.List)51 Map (java.util.Map)50 Utils (com.vmware.xenon.common.Utils)45 Test (org.junit.Test)45 UriUtils (com.vmware.xenon.common.UriUtils)44 URI (java.net.URI)42 Collectors (java.util.stream.Collectors)42 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)40 DiskState (com.vmware.photon.controller.model.resources.DiskService.DiskState)40 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)40 StatelessService (com.vmware.xenon.common.StatelessService)40 Query (com.vmware.xenon.services.common.QueryTask.Query)40 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)38 ComputeType (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType)36