use of com.att.cdp.openstack.OpenStackContext in project AJSC by att.
the class OpenStackSnapshotService method connect.
/**
* This is a helper method used to construct the Nova service object and setup the environment to access the
* OpenStack compute service (Nova).
*
* @throws NotLoggedInException
* If the user is not logged in
* @throws ContextClosedException
* If the user attempts an operation after the context is closed
*/
private void connect() throws NotLoggedInException, ContextClosedException {
checkLogin();
checkOpen();
Context context = getContext();
OpenStackContext osContext = (OpenStackContext) context;
nova = osContext.getNovaConnector();
((OpenStackContext) context).refreshIfStale(nova);
}
use of com.att.cdp.openstack.OpenStackContext in project AJSC by att.
the class OpenStackVolumeService method connect.
/**
* This is a helper method used to construct the Nova service object and setup the environment to access the
* OpenStack compute service (Nova).
*
* @throws NotLoggedInException
* If the user is not logged in
* @throws ContextClosedException
* If the user attempts an operation after the context is closed
*/
private void connect() throws NotLoggedInException, ContextClosedException {
checkLogin();
checkOpen();
Context context = getContext();
OpenStackContext osContext = (OpenStackContext) context;
cinder = osContext.getCinderConnector();
((OpenStackContext) context).refreshIfStale(cinder);
}
use of com.att.cdp.openstack.OpenStackContext 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");
}
use of com.att.cdp.openstack.OpenStackContext in project AJSC by att.
the class AbstractOpenStackIdentityService method getTenants.
public Set<Tenant> getTenants() throws ZoneException {
checkLoggedIn();
Context context = getContext();
trackRequest();
Set<Tenant> tenants = new HashSet<Tenant>();
Keystone keystone = getKeystone();
keystoneUrl = context.getProperties().getProperty(ContextFactory.PROPERTY_IDENTITY_URL);
try {
Tenants tenantList = keystone.tenants().list().execute();
for (com.woorea.openstack.keystone.model.Tenant t : tenantList.getList()) {
tenants.add(new OpenStackTenant((OpenStackContext) context, t));
}
} 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);
}
return tenants;
}
use of com.att.cdp.openstack.OpenStackContext in project AJSC by att.
the class AbstractOpenStackIdentityService method authenticate.
/**
* @see com.att.cdp.zones.IdentityService#authenticate(java.lang.String, java.lang.String)
*/
@SuppressWarnings("nls")
@Override
public void authenticate(String principal, String credential) throws IllegalArgumentException, ZoneException {
OpenStackContext context = (OpenStackContext) getContext();
checkPrincipal(principal);
checkCredential(credential);
if (!context.isLoggedIn()) {
try {
keystoneUrl = context.getProperties().getProperty(ContextFactory.PROPERTY_IDENTITY_URL);
tenantName = context.getProperties().getProperty(ContextFactory.PROPERTY_TENANT);
/*
* DH868g: Allow the specification of a client connector to override the default mechanism of the
* service loader. This is needed to support use within an OSGi container.
*/
keystone = new Keystone(keystoneUrl, context.getClientConnector());
/*
* dh868g: configure the client object to set any defined proxy and trusted host list
*/
String proxyHost = context.getProperties().getProperty(ContextFactory.PROPERTY_PROXY_HOST);
String proxyPort = context.getProperties().getProperty(ContextFactory.PROPERTY_PROXY_PORT);
String trustedHosts = context.getProperties().getProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS, "");
if (proxyHost != null && proxyHost.length() > 0) {
getKeystone().getProperties().setProperty(com.woorea.openstack.common.client.Constants.PROXY_HOST, proxyHost);
getKeystone().getProperties().setProperty(com.woorea.openstack.common.client.Constants.PROXY_PORT, proxyPort);
}
if (trustedHosts != null) {
getKeystone().getProperties().setProperty(com.woorea.openstack.common.client.Constants.TRUST_HOST_LIST, trustedHosts);
}
// access with unscoped token
Authentication authentication = new UsernamePassword(principal, credential);
TokensResource tokens = getKeystone().tokens();
TokensResource.Authenticate authenticate = tokens.authenticate(authentication);
authenticate = authenticate.withTenantName(tenantName);
access = authenticate.execute();
expiresLocal = getLocalExpiration(access);
tenant = new OpenStackTenant(context, access.getToken().getTenant());
context.setTenant(tenant);
tokenProvider = new OpenStackSimpleTokenProvider(access.getToken().getId());
getKeystone().setTokenProvider(tokenProvider);
List<Access.Service> services = access.getServiceCatalog();
OpenStackContext osContext = context;
osContext.registerServices(services);
// Testing that we can access tenants already
Tenants tenantList = getKeystone().tenants().list().execute();
for (com.woorea.openstack.keystone.model.Tenant t : tenantList.getList()) {
System.out.println(t);
}
} catch (OpenStackResponseException e) {
throw new AuthenticationException(EELFResourceManager.format(OSMsg.PAL_OS_FAILED_PROVIDER_AUTHENTICATION, e, principal, tenantName));
} catch (OpenStackConnectException e) {
throw new ContextConnectionException(EELFResourceManager.format(OSMsg.PAL_OS_CONNECTION_FAILED, "Identity", keystoneUrl), e);
}
}
}
Aggregations