Search in sources :

Example 26 with OpenStackContext

use of com.att.cdp.openstack.OpenStackContext in project AJSC by att.

the class AbstractTestCase method connect.

/**
 * Obtains the provider identity url, tenant name, region (if any), userid, and password from the test case
 * properties and uses them to connect to the specified provider. Returns the connected context object.
 *
 * @return The context object
 * @throws ZoneException
 *             If anything fails
 */
public Context connect() throws ZoneException {
    Properties properties = new Properties();
    properties.put(ContextFactory.PROPERTY_IDENTITY_URL, testConfig.getProperty("provider.url"));
    properties.put(ContextFactory.PROPERTY_TENANT, testConfig.getProperty("provider.tenant"));
    if (testConfig.getProperty("provider.region") != null) {
        properties.put(ContextFactory.PROPERTY_REGION, testConfig.getProperty("provider.region"));
    }
    OpenStackContext context = (OpenStackContext) ContextFactory.getContext(testConfig.getProperty("provider.name"), properties);
    context.login(testConfig.getProperty("provider.user"), testConfig.getProperty("provider.password"));
    return context;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Properties(java.util.Properties)

Example 27 with OpenStackContext

use of com.att.cdp.openstack.OpenStackContext in project AJSC by att.

the class AbstractOpenStackIdentityService method getTenant.

/**
 * All services must be able to return the tenant object that the user has connected to.
 *
 * @return The tenant object
 * @throws ZoneException
 *             If the user has not logged in
 * @see com.att.cdp.zones.Service#getTenant()
 */
@Override
public Tenant getTenant() throws ZoneException {
    checkLoggedIn();
    Context context = getContext();
    trackRequest();
    Keystone keystone = getKeystone();
    keystoneUrl = context.getProperties().getProperty(ContextFactory.PROPERTY_IDENTITY_URL);
    if (tenant == null) {
        com.woorea.openstack.keystone.model.Tenants tenants;
        try {
            tenants = keystone.tenants().list().execute();
        } catch (OpenStackConnectException e) {
            throw new ContextConnectionException(EELFResourceManager.format(OSMsg.PAL_OS_CONNECTION_FAILED, "Identity", keystoneUrl), e);
        } catch (OpenStackResponseException e) {
            throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_REQUEST_FAILURE, "get tenant " + tenantName), e);
        }
        for (com.woorea.openstack.keystone.model.Tenant t : tenants) {
            if (t.getName().equals(tenantName)) {
                tenant = new OpenStackTenant((OpenStackContext) context, t);
                break;
            }
        }
    }
    return tenant;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackTenant(com.att.cdp.openstack.model.OpenStackTenant) OpenStackContext(com.att.cdp.openstack.OpenStackContext) ContextConnectionException(com.att.cdp.exceptions.ContextConnectionException) Keystone(com.woorea.openstack.keystone.Keystone) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) Tenants(com.woorea.openstack.keystone.model.Tenants) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Example 28 with OpenStackContext

use of com.att.cdp.openstack.OpenStackContext 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

OpenStackContext (com.att.cdp.openstack.OpenStackContext)28 Context (com.att.cdp.zones.Context)17 ContextConnectionException (com.att.cdp.exceptions.ContextConnectionException)7 ZoneException (com.att.cdp.exceptions.ZoneException)7 OpenStackConnectException (com.woorea.openstack.base.client.OpenStackConnectException)7 OpenStackResponseException (com.woorea.openstack.base.client.OpenStackResponseException)7 Ignore (org.junit.Ignore)7 Test (org.junit.Test)7 Access (com.woorea.openstack.keystone.model.Access)5 NovaConnector (com.att.cdp.openstack.connectors.NovaConnector)4 OpenStackKeyPair (com.att.cdp.openstack.model.OpenStackKeyPair)3 OpenStackTenant (com.att.cdp.openstack.model.OpenStackTenant)3 Keystone (com.woorea.openstack.keystone.Keystone)3 Tenants (com.woorea.openstack.keystone.model.Tenants)3 ComputeService (com.att.cdp.zones.ComputeService)2 Nova (com.woorea.openstack.nova.Nova)2 KeyPairs (com.woorea.openstack.nova.model.KeyPairs)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Properties (java.util.Properties)2