Search in sources :

Example 51 with ComputeDescription

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

the class TestVSphereProvisionWithCloudConfigTask method createComputeHostDescription.

private ComputeDescription createComputeHostDescription() throws Throwable {
    ComputeDescription computeDesc = new ComputeDescription();
    computeDesc.id = nextName("host");
    computeDesc.name = computeDesc.id;
    computeDesc.documentSelfLink = computeDesc.id;
    computeDesc.supportedChildren = new ArrayList<>();
    computeDesc.supportedChildren.add(ComputeType.VM_GUEST.name());
    computeDesc.instanceAdapterReference = UriUtils.buildUri(this.host, VSphereUriPaths.INSTANCE_SERVICE);
    computeDesc.authCredentialsLink = this.auth.documentSelfLink;
    computeDesc.enumerationAdapterReference = UriUtils.buildUri(this.host, VSphereUriPaths.ENUMERATION_SERVICE);
    computeDesc.regionId = this.datacenterId;
    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 52 with ComputeDescription

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

the class TestVSphereProvisionWithMissingDatacenter method createCloneDescription.

@SuppressWarnings("unused")
private ComputeDescription createCloneDescription(String templateComputeLink) throws Throwable {
    ComputeDescription computeDesc = new ComputeDescription();
    computeDesc.id = "cloned-" + UUID.randomUUID().toString();
    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;
    CustomProperties.of(computeDesc).put(CustomProperties.TEMPLATE_LINK, templateComputeLink);
    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 53 with ComputeDescription

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

the class TestVSphereProvisionWithMissingDatacenter method createVmDescription.

private ComputeDescription createVmDescription() throws Throwable {
    ComputeDescription computeDesc = new ComputeDescription();
    computeDesc.id = nextName("vm");
    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;
    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 54 with ComputeDescription

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

the class TestVSphereProvisionWithMissingDatacenter method createInstanceFromTemplate.

@Test
public void createInstanceFromTemplate() throws Throwable {
    this.auth = createAuth();
    this.resourcePool = createResourcePool();
    if (isMock()) {
        // this test makes no sense in mock mode as the adapter doesn't process mock requests at all
        return;
    }
    // clear the datacenterId to cause misconfiguration
    this.datacenterId = null;
    this.computeHostDescription = createComputeDescription();
    this.computeHost = createComputeHost(this.computeHostDescription);
    ComputeDescription vmDescription = createVmDescription();
    ComputeState vm = createVmState(vmDescription);
    // kick off a provision task to do the actual VM creation
    ProvisionComputeTaskState provisionTask = createProvisionTask(vm);
    try {
        awaitTaskEnd(provisionTask);
    } catch (AssertionError e) {
        Operation operation = this.host.waitForResponse(Operation.createGet(this.host, provisionTask.documentSelfLink));
        ProvisionComputeTaskState task = operation.getBody(ProvisionComputeTaskState.class);
        assertTrue(task.taskInfo.failure.message.contains("regionId"));
        return;
    }
    fail("Task should have failed");
}
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) Operation(com.vmware.xenon.common.Operation) Test(org.junit.Test)

Example 55 with ComputeDescription

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

the class TestVSphereProvisionWithStaticIpTask method deployByCloningWithCustomization.

@Test
public void deployByCloningWithCustomization() throws Throwable {
    ComputeState vm = null;
    try {
        this.nicDescription = new NetworkInterfaceDescription();
        this.nicDescription.assignment = IpAssignment.STATIC;
        this.nicDescription.address = "10.0.0.2";
        // Create a resource pool where the VM will be housed
        this.resourcePool = createResourcePool();
        this.auth = createAuth();
        this.computeHostDescription = createComputeDescription();
        this.computeHost = createComputeHost();
        // enumerate all resources hoping to find the template
        doRefresh();
        snapshotFactoryState("networks", NetworkService.class);
        snapshotFactoryState("computes", ComputeService.class);
        // find the template by vm name
        // template must have vm-tools and cloud-config installed
        ComputeState template = findTemplate();
        this.subnet = fetchServiceState(SubnetState.class, findPortGroup(networkId));
        this.subnet.dnsSearchDomains = Arrays.asList("local");
        this.subnet.gatewayAddress = "10.0.0.1";
        this.subnet.dnsServerAddresses = Arrays.asList("8.8.8.8");
        this.subnet.domain = "local";
        this.subnet.subnetCIDR = "10.0.0.0/24";
        // modify the subnet
        Operation patch = Operation.createPatch(this.host, this.subnet.documentSelfLink).setBody(this.subnet);
        patch = this.host.waitForResponse(patch);
        this.subnet = patch.getBody(SubnetState.class);
        // 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);
        if (!isMock()) {
            assertEquals(vm.address, this.nicDescription.address);
        }
    } finally {
        if (vm != null) {
            deleteVmAndWait(vm);
        }
    }
}
Also used : NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) 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) Operation(com.vmware.xenon.common.Operation) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) 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