Search in sources :

Example 11 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.

the class TestVSphereProvisionFromImageLink method provisionVMAndGetState.

private ComputeState provisionVMAndGetState() throws Throwable {
    if (isMock()) {
        return 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);
    EndpointState ep = createEndpointState(this.computeHost, this.computeHostDescription);
    this.endpoint = TestUtils.doPost(this.host, ep, EndpointState.class, UriUtils.buildUri(this.host, EndpointService.FACTORY_LINK));
    enumerateComputes(this.computeHost, this.endpoint);
    doRefresh();
    snapshotFactoryState("images", ImageService.class);
    String imageLink = findImage();
    ComputeDescription desc = createVmDescription();
    ComputeState vm = createVmState(desc, imageLink);
    // kick off a provision task to do the actual VM creation
    ProvisionComputeTaskState outTask = createProvisionTask(vm);
    awaitTaskEnd(outTask);
    return getComputeState(vm);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) 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)

Example 12 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.

the class TestVSphereProvisionWithCloudConfigTask method createVmDescription.

private ComputeDescription createVmDescription() throws Throwable {
    ComputeDescription computeDesc = new ComputeDescription();
    computeDesc.id = nextName("vm");
    computeDesc.regionId = this.datacenterId;
    computeDesc.documentSelfLink = computeDesc.id;
    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;
    computeDesc.cpuCount = 2L;
    computeDesc.totalMemoryBytes = 1L * 1024 * 1024 * 1024;
    return TestUtils.doPost(this.host, computeDesc, ComputeDescription.class, UriUtils.buildUri(this.host, ComputeDescriptionService.FACTORY_LINK));
}
Also used : ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)

Example 13 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription 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 14 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.

the class TestVSphereProvisionWithStaticIpTask method createVmDescription.

private ComputeDescription createVmDescription() throws Throwable {
    ComputeDescription computeDesc = new ComputeDescription();
    computeDesc.id = nextName("vm");
    computeDesc.regionId = this.datacenterId;
    computeDesc.documentSelfLink = computeDesc.id;
    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;
    computeDesc.cpuCount = 2;
    // 1G
    computeDesc.totalMemoryBytes = 1024 * 1024 * 1024;
    return TestUtils.doPost(this.host, computeDesc, ComputeDescription.class, UriUtils.buildUri(this.host, ComputeDescriptionService.FACTORY_LINK));
}
Also used : ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)

Example 15 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.

the class OvfParserTest method test.

@Test
public void test() throws IOException, SAXException {
    OvfParser parser = new OvfParser();
    Document ovfDoc = parser.retrieveDescriptor(new File("src/test/resources/vcenter.ovf").toURI());
    ComputeDescription template = new ComputeDescription();
    template.instanceAdapterReference = URI.create("http://test");
    List<ComputeDescription> results = parser.parse(ovfDoc, template);
    System.out.println(Utils.toJsonHtml(results));
    // all hw configurations are converted
    assertEquals(9, results.size());
    // template properties are copied
    for (ComputeDescription description : results) {
        assertEquals(description.instanceAdapterReference, template.instanceAdapterReference);
    }
    // network, properties and hardware config translated
    for (ComputeDescription description : results) {
        assertTrue(description.customProperties.containsKey("ovf.prop:guestinfo.cis.appliance.net.addr.family"));
        assertTrue(description.customProperties.containsKey("ovf.prop:guestinfo.cis.appliance.root.passwd"));
        assertTrue(description.cpuCount > 0);
        assertTrue(description.totalMemoryBytes > 0);
    }
    List<String> nets = parser.extractNetworks(ovfDoc);
    assertEquals(1, nets.size());
    assertEquals("Network 1", nets.get(0));
}
Also used : ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) Document(org.w3c.dom.Document) File(java.io.File) Test(org.junit.Test)

Aggregations

ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)78 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)39 Operation (com.vmware.xenon.common.Operation)21 ArrayList (java.util.ArrayList)21 QueryTask (com.vmware.xenon.services.common.QueryTask)17 Test (org.junit.Test)17 ComputeDescriptionService (com.vmware.photon.controller.model.resources.ComputeDescriptionService)15 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)15 HashMap (java.util.HashMap)15 HashSet (java.util.HashSet)15 List (java.util.List)15 Utils (com.vmware.xenon.common.Utils)14 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)14 URI (java.net.URI)14 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)13 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)12 ServiceDocumentQueryResult (com.vmware.xenon.common.ServiceDocumentQueryResult)12 UriUtils (com.vmware.xenon.common.UriUtils)12 ComputeType (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType)11 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)11