Search in sources :

Example 11 with BasicConnection

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

the class VSphereIOThreadPool method execute.

private void execute(URI adapterReference, AuthCredentialsServiceState auth, ConnectionCallback callback) {
    BasicConnection connection = new BasicConnection();
    // ignores the certificate for testing purposes
    if (VSPHERE_IGNORE_CERTIFICATE_WARNINGS) {
        connection.setIgnoreSslErrors(true);
    } else {
        connection.setTrustManager(ServerX509TrustManager.getInstance());
    }
    if (UriPaths.IAAS_API_ENABLED && !StringUtils.equalsIgnoreCase(auth.type, "Username")) {
        connection.setToken(EncryptionUtils.decrypt(auth.privateKey));
    } else {
        connection.setUsername(auth.privateKeyId);
        connection.setPassword(EncryptionUtils.decrypt(auth.privateKey));
    }
    connection.setURI(adapterReference);
    // don't connect now, but as late as possible as the session can expire
    executeCallback(connection, callback);
}
Also used : BasicConnection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection)

Example 12 with BasicConnection

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

the class BaseVSphereAdapterTest method createConnection.

public BasicConnection createConnection() {
    if (isMock()) {
        throw new IllegalStateException("Cannot create connection in while mock is true");
    }
    BasicConnection connection = new BasicConnection();
    connection.setIgnoreSslErrors(true);
    connection.setUsername(this.vcUsername);
    connection.setPassword(this.vcPassword);
    connection.setURI(URI.create(this.vcUrl));
    connection.connect();
    return connection;
}
Also used : BasicConnection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection)

Example 13 with BasicConnection

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

the class VapiConnection method createFromVimConnection.

public static VapiConnection createFromVimConnection(Connection connection) {
    VapiConnection vapiConnection = new VapiConnection(getVapiUri(connection.getURI()));
    vapiConnection.setUsername(connection.getUsername());
    vapiConnection.setPassword(connection.getPassword());
    if (connection instanceof BasicConnection) {
        BasicConnection basicConn = (BasicConnection) connection;
        if (basicConn.isIgnoreSslErrors()) {
            vapiConnection.setClient(VapiConnection.newUnsecureHttpClient());
        } else if (basicConn.getTrustManager() != null) {
            vapiConnection.setClient(VapiConnection.newDefaultHttpClient(basicConn.getTrustManager()));
        } else {
            vapiConnection.setClient(VapiConnection.newDefaultHttpClient());
        }
    }
    return vapiConnection;
}
Also used : BasicConnection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection)

Example 14 with BasicConnection

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

the class TestVSphereLibraryProvisionTaskWithStorage method deployFromLibraryWithAdditionalDisks.

@Test
public void deployFromLibraryWithAdditionalDisks() throws Throwable {
    ComputeService.ComputeState vm = provisionVMAndGetState(true, true);
    try {
        if (vm == null) {
            return;
        }
        // Verify that the disk is resized
        BasicConnection connection = createConnection();
        GetMoRef get = new GetMoRef(connection);
        List<VirtualDisk> virtualDisks = fetchAllVirtualDisks(vm, get);
        assertEquals(3, virtualDisks.size());
        assertEquals(3, vm.diskLinks.size());
        List<DeferredResult<DiskService.DiskState>> disks = vm.diskLinks.stream().map(link -> {
            Operation getOp = Operation.createGet(this.host, link).setReferer(this.host.getReferer());
            return this.host.sendWithDeferredResult(getOp, DiskService.DiskState.class);
        }).collect(Collectors.toList());
        DeferredResult.allOf(disks).thenAccept(diskStates -> diskStates.stream().forEach(ds -> {
            assertNotNull(ds.customProperties);
            assertNotNull(ds.sourceImageReference);
            assertNotNull(ds.customProperties.get(PROVIDER_DISK_UNIQUE_ID));
        }));
    } finally {
        if (vm != null) {
            deleteVmAndWait(vm);
        }
    }
}
Also used : GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) Assert.assertNotNull(org.junit.Assert.assertNotNull) Operation(com.vmware.xenon.common.Operation) Test(org.junit.Test) GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) PROVIDER_DISK_UNIQUE_ID(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.PROVIDER_DISK_UNIQUE_ID) Collectors(java.util.stream.Collectors) List(java.util.List) VirtualDisk(com.vmware.vim25.VirtualDisk) DeferredResult(com.vmware.xenon.common.DeferredResult) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) BasicConnection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection) DiskService(com.vmware.photon.controller.model.resources.DiskService) Assert.assertEquals(org.junit.Assert.assertEquals) BasicConnection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection) Operation(com.vmware.xenon.common.Operation) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) VirtualDisk(com.vmware.vim25.VirtualDisk) DiskService(com.vmware.photon.controller.model.resources.DiskService) DeferredResult(com.vmware.xenon.common.DeferredResult) Test(org.junit.Test)

Example 15 with BasicConnection

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

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