Search in sources :

Example 16 with BasicConnection

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

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

the class EnumerationClientTest method test.

@Test
public void test() throws Exception {
    String url = System.getProperty(TestProperties.VC_URL);
    if (url == null) {
        return;
    }
    String username = System.getProperty(TestProperties.VC_USERNAME);
    String password = System.getProperty(TestProperties.VC_PASSWORD);
    String datacenter = System.getProperty(TestProperties.VC_DATECENTER_ID);
    ManagedObjectReference datacenterMoRef = VimUtils.convertStringToMoRef(datacenter);
    BasicConnection conn = new BasicConnection();
    conn.setURI(URI.create(url));
    conn.setUsername(username);
    conn.setPassword(password);
    conn.setIgnoreSslErrors(true);
    conn.setRequestTimeout(30, TimeUnit.SECONDS);
    conn.connect();
    ComputeStateWithDescription parent = new ComputeStateWithDescription();
    ComputeDescription desc = new ComputeDescription();
    parent.description = desc;
    EnumerationClient client = new EnumerationClient(conn, parent);
    PropertyFilterSpec spec = client.createResourcesFilterSpec();
    for (List<ObjectContent> page : client.retrieveObjects(spec)) {
        for (ObjectContent cont : page) {
            this.logger.info(VimUtils.convertMoRefToString(cont.getObj()));
        }
    }
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectContent(com.vmware.vim25.ObjectContent) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) BasicConnection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) Test(org.junit.Test)

Example 18 with BasicConnection

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

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

the class StatsClientTest method test.

@Test
public void test() throws Exception {
    String url = System.getProperty(TestProperties.VC_URL);
    if (url == null) {
        return;
    }
    String username = System.getProperty(TestProperties.VC_USERNAME);
    String password = System.getProperty(TestProperties.VC_PASSWORD);
    BasicConnection conn = new BasicConnection();
    conn.setURI(URI.create(url));
    conn.setUsername(username);
    conn.setPassword(password);
    conn.setIgnoreSslErrors(true);
    conn.setRequestTimeout(30, TimeUnit.SECONDS);
    conn.connect();
    StatsClient client = new StatsClient(conn);
    List<ServiceStat> metrics;
    ManagedObjectReference vm = new ManagedObjectReference();
    vm.setType(VimNames.TYPE_VM);
    vm.setValue("vm-49");
    metrics = client.retrieveMetricsForVm(vm);
    this.logger.info("vm metrics " + metrics);
    ManagedObjectReference host = new ManagedObjectReference();
    host.setType(VimNames.TYPE_HOST);
    host.setValue("host-504");
    metrics = client.retrieveMetricsForHost(host);
    this.logger.info("host metrics " + metrics);
}
Also used : ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) BasicConnection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) Test(org.junit.Test) EnumerationClientTest(com.vmware.photon.controller.model.adapters.vsphere.EnumerationClientTest)

Example 20 with BasicConnection

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

the class VSphereRegionEnumerationAdapterService method handlePost.

@Override
public void handlePost(Operation post) {
    if (!post.hasBody()) {
        post.fail(new IllegalArgumentException("body is required"));
        return;
    }
    EndpointState request = post.getBody(EndpointState.class);
    DeferredResult<AuthCredentialsServiceState> credentialsDr;
    if (request.authCredentialsLink == null) {
        credentialsDr = new DeferredResult<>();
        credentialsDr.complete(new AuthCredentialsServiceState());
    } else {
        Operation getCredentials = Operation.createGet(createInventoryUri(this.getHost(), request.authCredentialsLink));
        credentialsDr = sendWithDeferredResult(getCredentials, AuthCredentialsServiceState.class);
    }
    credentialsDr.whenComplete((AuthCredentialsServiceState creds, Throwable t) -> {
        if (t != null) {
            post.fail(t);
            return;
        }
        VSphereIOThreadPoolAllocator.getPool(this).submit(() -> {
            BasicConnection connection = new BasicConnection();
            try {
                EndpointAdapterUtils.Retriever retriever = EndpointAdapterUtils.Retriever.of(request.endpointProperties);
                VSphereEndpointAdapterService.endpoint().accept(request, retriever);
                VSphereEndpointAdapterService.credentials().accept(creds, retriever);
                connection.setURI(URI.create("https://" + request.endpointProperties.get(HOST_NAME_KEY) + "/sdk"));
                connection.setUsername(creds.privateKeyId);
                connection.setPassword(EncryptionUtils.decrypt(creds.privateKey));
                connection.setIgnoreSslErrors(true);
                connection.connect();
                DatacenterLister lister = new DatacenterLister(connection);
                RegionEnumerationResponse res = new RegionEnumerationResponse();
                res.regions = lister.listAllDatacenters().stream().map(dc -> new RegionEnumerationResponse.RegionInfo(DatacenterLister.prettifyPath(dc.path), VimUtils.convertMoRefToString(dc.object))).collect(Collectors.toList());
                post.setBody(res);
                post.complete();
            } catch (Exception e) {
                post.fail(e);
            } finally {
                connection.closeQuietly();
            }
        });
    });
}
Also used : RegionEnumerationResponse(com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse) Operation(com.vmware.xenon.common.Operation) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) BasicConnection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection) DatacenterLister(com.vmware.photon.controller.model.adapters.vsphere.util.finders.DatacenterLister) EndpointAdapterUtils(com.vmware.photon.controller.model.adapters.util.EndpointAdapterUtils)

Aggregations

BasicConnection (com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection)20 GetMoRef (com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef)11 Test (org.junit.Test)10 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)9 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)6 ComputeDescriptionService (com.vmware.photon.controller.model.resources.ComputeDescriptionService)4 ProvisionComputeTaskService (com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService)4 VirtualDisk (com.vmware.vim25.VirtualDisk)3 Operation (com.vmware.xenon.common.Operation)3 DatacenterLister (com.vmware.photon.controller.model.adapters.vsphere.util.finders.DatacenterLister)2 DiskService (com.vmware.photon.controller.model.resources.DiskService)2 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)2 RegionEnumerationResponse (com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse)1 EndpointAdapterUtils (com.vmware.photon.controller.model.adapters.util.EndpointAdapterUtils)1 PROVIDER_DISK_UNIQUE_ID (com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.PROVIDER_DISK_UNIQUE_ID)1 EnumerationClientTest (com.vmware.photon.controller.model.adapters.vsphere.EnumerationClientTest)1 ImportOvfRequest (com.vmware.photon.controller.model.adapters.vsphere.ovf.ImportOvfRequest)1 ConnectionException (com.vmware.photon.controller.model.adapters.vsphere.util.connection.ConnectionException)1 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)1 ComputeStateWithDescription (com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription)1