@Override public String getToken() { return keystoneTokenProvider.getAccessByTenant(tenantName) .getToken().getId(); } @Override
/** * @param args */ public static void main(String[] args) { Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL); Access access = keystone.tokens().authenticate(new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)) .withTenantName("demo") .execute(); //use the token in the following requests keystone.token(access.getToken().getId()); //NovaClient novaClient = new NovaClient(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "compute", null, "public"), access.getToken().getId()); Nova novaClient = new Nova(ExamplesConfiguration.NOVA_ENDPOINT.concat("/").concat(access.getToken().getTenant().getId())); novaClient.token(access.getToken().getId()); //novaClient.enableLogging(Logger.getLogger("nova"), 100 * 1024); Servers servers = novaClient.servers().list(true).execute(); for(Server server : servers) { System.out.println(server); } }
/** * This method determines the local time that the current token (held in the Access object) will expire. * * @param accessKey * The access to be checked * @return The local time the token expires */ private static long getLocalExpiration(Access accessKey) { Date now = Time.getCurrentUTCDate(); if (accessKey != null && accessKey.getToken() != null) { Calendar issued = accessKey.getToken().getIssued_at(); Calendar expires = accessKey.getToken().getExpires(); if (issued != null && expires != null) { long tokenLife = expires.getTimeInMillis() - issued.getTimeInMillis(); return now.getTime() + tokenLife; } } return now.getTime(); }
/** * Creates the super class from the specified context object. This is then used to obtain the Access object. * * @param context * The OpenStackCOntext object to obtain the Access object */ public Connector(OpenStackContext context) { /* * 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. */ clientConnector = context.getClientConnector(); configuration = ConfigurationFactory.getConfiguration(); logger = configuration.getApplicationLogger(); identity = (CommonIdentityService) context.getIdentityService(); access = identity.getAccess(); access.getToken().getTenant().getId(); }
@Override public String getToken() { return keystoneTokenProvider.getAccessByTenant(tenantName) .getToken().getId(); } @Override
public static void main(String[] args) throws InterruptedException { Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL); Access access = keystone.tokens().authenticate(new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)) .withTenantName(ExamplesConfiguration.TENANT_NAME) .execute(); //use the token in the following requests keystone.token(access.getToken().getId()); Nova novaClient = new Nova(ExamplesConfiguration.NOVA_ENDPOINT.concat("/").concat(access.getToken().getTenant().getId())); novaClient.token(access.getToken().getId()); Servers servers = novaClient.servers().list(true).execute(); if(servers.getList().size() > 0) { // Server has to be in activated state. ServersResource.StopServer stopServer = novaClient.servers().stop(servers.getList().get(0).getId()); stopServer.endpoint(ExamplesConfiguration.NOVA_ENDPOINT); stopServer.execute(); // Wait until server shutdown. Or 400 error occurs. Thread.sleep(5000); ServersResource.StartServer startServer = novaClient.servers().start(servers.getList().get(0).getId()); startServer.endpoint(ExamplesConfiguration.NOVA_ENDPOINT); startServer.execute(); } } }
/** * @see com.woorea.openstack.base.client.OpenStackTokenProvider#getToken() */ @Override public String getToken() throws OpenStackConnectException, OpenStackResponseException { return keystoneTokenProvider.getAccessByTenant(tenantName).getToken().getId(); }
/** * @param connector * The connector to be updated with the new token */ public synchronized void refreshIfStale(Connector connector) { String logId = "PAL-5558"; Logger appLogger = getLogger(); appLogger.info(new Date().toString()+ " " + logId+":OpenStackContext.refreshIfStale - in"); if (isStale()) { appLogger.info(new Date().toString()+ " " +logId+":OpenStackContext.refreshIfStale - Connection is stale"); try { logout(); relogin(); } catch (IllegalStateException | IllegalArgumentException | ZoneException e) { e.printStackTrace(); } } appLogger.info(new Date().toString()+ " " +logId+":OpenStackContext.refreshIfStale - old token -"+connector.getAccess().getToken().getId()); connector.updateToken(); appLogger.info(new Date().toString()+ " " +logId+":OpenStackContext.refreshIfStale - new token -"+connector.getAccess().getToken().getId()); }
/** * Updates the expired token by re-authenticating, getting a new unexpired token (in the access object), and then * updating the token held by this client wrapped by this connector to use the new token. * * @see com.att.cdp.openstack.connectors.Connector#updateToken() */ @Override public void updateToken() { super.updateToken(); keystone.token(getAccess().getToken().getId()); } }
/** * Updates the expired token by re-authenticating, getting a new unexpired token (in the access object), and then * updating the token held by this client wrapped by this connector to use the new token. * * @see com.att.cdp.openstack.connectors.Connector#updateToken() */ @Override public void updateToken() { super.updateToken(); glance.token(getAccess().getToken().getId()); } }
/** * Updates the expired token by re-authenticating, getting a new unexpired token (in the access object), and then * updating the token held by this client wrapped by this connector to use the new token. * * @see com.att.cdp.openstack.connectors.Connector#updateToken() */ @Override public void updateToken() { super.updateToken(); heat.token(getAccess().getToken().getId()); }
/** * Updates the expired token by re-authenticating, getting a new unexpired token (in the access object), and then * updating the token held by this client wrapped by this connector to use the new token. * * @see com.att.cdp.openstack.connectors.Connector#updateToken() */ @Override public void updateToken() { super.updateToken(); quantum.token(getAccess().getToken().getId()); } }
/** * Updates the expired token by re-authenticating, getting a new unexpired token (in the access object), and then * updating the token held by this client wrapped by this connector to use the new token. * * @see com.att.cdp.openstack.connectors.Connector#updateToken() */ @Override public void updateToken() { super.updateToken(); cinder.token(getAccess().getToken().getId()); } }
/** * Updates the expired token by re-authenticating, getting a new unexpired token (in the access object), and then * updating the token held by this client wrapped by this connector to use the new token. * * @see com.att.cdp.openstack.connectors.Connector#updateToken() */ @Override public void updateToken() { super.updateToken(); nova.token(getAccess().getToken().getId()); } }
this.token = access.getToken().getId(); keystone.token(this.token);
glance.token(getAccess().getToken().getId());
quantum.token(getAccess().getToken().getId());