Search in sources :

Example 1 with NovaConnector

use of com.att.cdp.openstack.connectors.NovaConnector in project AJSC by att.

the class TestOpenStackContext method testLoginLogout.

/**
 * Test that we can login and out of the provider, and access the services once logged in (so we dont have to
 * repeatedly login/out)
 *
 * @throws ZoneException
 */
@Test
@Ignore
public void testLoginLogout() throws ZoneException {
    OpenStackContext context = login();
    /*
         * make sure we can retreive all of the services
         */
    ComputeService computeService = context.getComputeService();
    assertNotNull(computeService);
    IdentityService identityService = context.getIdentityService();
    assertNotNull(identityService);
    ImageService imageService = context.getImageService();
    assertNotNull(imageService);
    NetworkService networkService = context.getNetworkService();
    assertNotNull(networkService);
    VolumeService volumeService = context.getVolumeService();
    assertNotNull(volumeService);
    SnapshotService snapshotService = context.getSnapshotService();
    assertNotNull(snapshotService);
    StackService stackService = context.getStackService();
    assertNotNull(stackService);
    /*
         * Services are locally cached by the provider context. If we get them again, we should get the same exact
         * object. Check that too.
         */
    assertTrue(computeService == context.getComputeService());
    assertTrue(identityService == context.getIdentityService());
    assertTrue(imageService == context.getImageService());
    assertTrue(networkService == context.getNetworkService());
    assertTrue(volumeService == context.getVolumeService());
    assertTrue(snapshotService == context.getSnapshotService());
    assertTrue(stackService == context.getStackService());
    /*
         * Test that we can also obtain the connectors
         */
    GlanceConnector glanceConnector = context.getGlanceConnector();
    assertNotNull(glanceConnector);
    NovaConnector novaConnector = context.getNovaConnector();
    assertNotNull(novaConnector);
    QuantumConnector quantumConnector = context.getQuantumConnector();
    assertNotNull(quantumConnector);
    /*
         * Connectors are locally cached, check that
         */
    assertTrue(glanceConnector == context.getGlanceConnector());
    assertTrue(novaConnector == context.getNovaConnector());
    assertTrue(quantumConnector == context.getQuantumConnector());
    /*
         * Now, check that we can obtain the tenant as well
         */
    Tenant tenant = context.getTenant();
    assertNotNull(tenant);
    assertEquals(tenant.getName(), context.getTenantName());
    assertEquals(tenant.getId(), context.getTenantId());
    logout(context);
}
Also used : IdentityService(com.att.cdp.zones.IdentityService) SnapshotService(com.att.cdp.zones.SnapshotService) StackService(com.att.cdp.zones.StackService) Tenant(com.att.cdp.zones.model.Tenant) GlanceConnector(com.att.cdp.openstack.connectors.GlanceConnector) VolumeService(com.att.cdp.zones.VolumeService) QuantumConnector(com.att.cdp.openstack.connectors.QuantumConnector) NetworkService(com.att.cdp.zones.NetworkService) NovaConnector(com.att.cdp.openstack.connectors.NovaConnector) OpenStackComputeService(com.att.cdp.openstack.v2.OpenStackComputeService) ComputeService(com.att.cdp.zones.ComputeService) ImageService(com.att.cdp.zones.ImageService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with NovaConnector

use of com.att.cdp.openstack.connectors.NovaConnector in project AJSC by att.

the class AbstractOpenStackIdentityService method getKeyPair.

/**
 * @see com.att.cdp.zones.IdentityService#getKeyPair(java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public KeyPair getKeyPair(String name) throws ZoneException {
    trackRequest();
    RequestState.put(RequestState.KEYPAIR, name);
    Context context = getContext();
    if (context.isLoggedIn()) {
        NovaConnector connector = ((OpenStackContext) context).getNovaConnector();
        KeyPairs pairs;
        try {
            pairs = connector.getClient().keyPairs().list().execute();
        } catch (OpenStackConnectException e) {
            throw new ContextConnectionException(EELFResourceManager.format(OSMsg.PAL_OS_CONNECTION_FAILED, "Compute", connector.getEndpoint()), e);
        } catch (OpenStackResponseException e) {
            throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_REQUEST_FAILURE, "get key-pair " + name), e);
        }
        if (pairs == null || pairs.getList() == null) {
            return null;
        }
        for (com.woorea.openstack.nova.model.KeyPair pair : pairs.getList()) {
            if (pair.getName().equals(name)) {
                return new OpenStackKeyPair(context, pair);
            }
        }
        return null;
    }
    throw new ZoneException("Unable to retrieve key-pairs when the context has not been logged in and authenticated");
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) KeyPairs(com.woorea.openstack.nova.model.KeyPairs) OpenStackContext(com.att.cdp.openstack.OpenStackContext) ContextConnectionException(com.att.cdp.exceptions.ContextConnectionException) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) OpenStackKeyPair(com.att.cdp.openstack.model.OpenStackKeyPair) NovaConnector(com.att.cdp.openstack.connectors.NovaConnector) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Example 3 with NovaConnector

use of com.att.cdp.openstack.connectors.NovaConnector in project AJSC by att.

the class AbstractOpenStackIdentityService method createKeyPair.

/**
 * @see com.att.cdp.zones.IdentityService#createKeyPair(com.att.cdp.zones.model.KeyPair)
 */
@SuppressWarnings("nls")
@Override
public KeyPair createKeyPair(KeyPair keyPair) throws ZoneException {
    trackRequest();
    RequestState.put(RequestState.KEYPAIR, keyPair.getName());
    Context context = getContext();
    if (context.isLoggedIn()) {
        NovaConnector connector = ((OpenStackContext) context).getNovaConnector();
        com.woorea.openstack.nova.model.KeyPair pair;
        try {
            pair = connector.getClient().keyPairs().create(keyPair.getName()).execute();
        } catch (OpenStackConnectException e) {
            throw new ContextConnectionException(EELFResourceManager.format(OSMsg.PAL_OS_CONNECTION_FAILED, "Compute", connector.getEndpoint()), e);
        } catch (OpenStackResponseException e) {
            String reason = null;
            if (e.getResponse() != null && e.getResponse().getInputStream() != null) {
                try {
                    reason = IOUtils.toString(e.getResponse().getInputStream(), "UTF-8");
                } catch (IOException e1) {
                }
                throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_REQUEST_FAILURE, "create key-pair " + keyPair.getName() + " " + reason), e);
            }
            throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_REQUEST_FAILURE, "create key-pair " + keyPair.getName()), e);
        }
        return new OpenStackKeyPair(context, pair);
    }
    throw new ZoneException("Unable to create key-pairs when the context has not been logged in and authenticated");
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) IOException(java.io.IOException) OpenStackContext(com.att.cdp.openstack.OpenStackContext) ContextConnectionException(com.att.cdp.exceptions.ContextConnectionException) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) OpenStackKeyPair(com.att.cdp.openstack.model.OpenStackKeyPair) NovaConnector(com.att.cdp.openstack.connectors.NovaConnector) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Example 4 with NovaConnector

use of com.att.cdp.openstack.connectors.NovaConnector in project AJSC by att.

the class AbstractOpenStackIdentityService method deleteKeyPair.

/**
 * @see com.att.cdp.zones.IdentityService#deleteKeyPair(com.att.cdp.zones.model.KeyPair)
 */
@SuppressWarnings("nls")
@Override
public void deleteKeyPair(KeyPair keyPair) throws ZoneException {
    trackRequest();
    RequestState.put(RequestState.KEYPAIR, keyPair.getName());
    Context context = getContext();
    if (context.isLoggedIn()) {
        NovaConnector connector = ((OpenStackContext) context).getNovaConnector();
        try {
            connector.getClient().keyPairs().delete(keyPair.getName()).execute();
        } catch (OpenStackConnectException e) {
            throw new ContextConnectionException(EELFResourceManager.format(OSMsg.PAL_OS_CONNECTION_FAILED, "Compute", connector.getEndpoint()), e);
        } catch (OpenStackResponseException e) {
            throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_REQUEST_FAILURE, "delete key-pair " + keyPair.getName()), e);
        }
        return;
    }
    throw new ZoneException("Unable to delete key-pairs when the context has not been logged in and authenticated");
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext) ContextConnectionException(com.att.cdp.exceptions.ContextConnectionException) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) NovaConnector(com.att.cdp.openstack.connectors.NovaConnector) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Example 5 with NovaConnector

use of com.att.cdp.openstack.connectors.NovaConnector in project AJSC by att.

the class AbstractOpenStackIdentityService method getKeyPairs.

/**
 * @see com.att.cdp.zones.IdentityService#getKeyPairs()
 */
@SuppressWarnings("nls")
@Override
public List<KeyPair> getKeyPairs() throws ZoneException {
    trackRequest();
    Context context = getContext();
    if (context.isLoggedIn()) {
        NovaConnector connector = ((OpenStackContext) context).getNovaConnector();
        KeyPairs pairs = null;
        try {
            pairs = connector.getClient().keyPairs().list().execute();
        } catch (OpenStackConnectException e) {
            throw new ContextConnectionException(EELFResourceManager.format(OSMsg.PAL_OS_CONNECTION_FAILED, "Compute", connector.getEndpoint()), e);
        } catch (OpenStackResponseException e) {
            throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_REQUEST_FAILURE, "get key-pair list"), e);
        }
        ArrayList<KeyPair> list = new ArrayList<>();
        for (com.woorea.openstack.nova.model.KeyPair pair : pairs.getList()) {
            OpenStackKeyPair kp = new OpenStackKeyPair(context, pair);
            list.add(kp);
        }
        return list;
    }
    throw new ZoneException("Unable to retrieve key-pairs when the context has not been logged in and authenticated");
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) KeyPair(com.att.cdp.zones.model.KeyPair) OpenStackKeyPair(com.att.cdp.openstack.model.OpenStackKeyPair) KeyPairs(com.woorea.openstack.nova.model.KeyPairs) ArrayList(java.util.ArrayList) OpenStackContext(com.att.cdp.openstack.OpenStackContext) ContextConnectionException(com.att.cdp.exceptions.ContextConnectionException) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) OpenStackKeyPair(com.att.cdp.openstack.model.OpenStackKeyPair) NovaConnector(com.att.cdp.openstack.connectors.NovaConnector) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Aggregations

NovaConnector (com.att.cdp.openstack.connectors.NovaConnector)5 ContextConnectionException (com.att.cdp.exceptions.ContextConnectionException)4 ZoneException (com.att.cdp.exceptions.ZoneException)4 OpenStackContext (com.att.cdp.openstack.OpenStackContext)4 Context (com.att.cdp.zones.Context)4 OpenStackConnectException (com.woorea.openstack.base.client.OpenStackConnectException)4 OpenStackResponseException (com.woorea.openstack.base.client.OpenStackResponseException)4 OpenStackKeyPair (com.att.cdp.openstack.model.OpenStackKeyPair)3 KeyPairs (com.woorea.openstack.nova.model.KeyPairs)2 GlanceConnector (com.att.cdp.openstack.connectors.GlanceConnector)1 QuantumConnector (com.att.cdp.openstack.connectors.QuantumConnector)1 OpenStackComputeService (com.att.cdp.openstack.v2.OpenStackComputeService)1 ComputeService (com.att.cdp.zones.ComputeService)1 IdentityService (com.att.cdp.zones.IdentityService)1 ImageService (com.att.cdp.zones.ImageService)1 NetworkService (com.att.cdp.zones.NetworkService)1 SnapshotService (com.att.cdp.zones.SnapshotService)1 StackService (com.att.cdp.zones.StackService)1 VolumeService (com.att.cdp.zones.VolumeService)1 KeyPair (com.att.cdp.zones.model.KeyPair)1