@Override public void execute(Keystone keystone, CommandLine args) { final Tenants tenants = keystone.tenants().list().execute(); Table t = new Table(new TableModel<Tenant>(tenants.getList()) { @Override public Column[] getHeaders() { return new Column[]{ new Column("id", 32, Column.ALIGN_LEFT), new Column("name", 32, Column.ALIGN_LEFT), new Column("description", 32, Column.ALIGN_LEFT), new Column("enabled", 7, Column.ALIGN_LEFT) }; } @Override public String[] getRow(Tenant tenant) { return new String[]{ tenant.getId(), tenant.getName(), tenant.getDescription(), tenant.getEnabled().toString() }; } }); System.out.println(t.render()); }
if(tenants.getList().size() > 0) { access = keystone.tokens().authenticate(new TokenAuthentication(access.getToken().getId())).withTenantId(tenants.getList().get(0).getId()).execute(); Nova novaClient = new Nova(ExamplesConfiguration.NOVA_ENDPOINT.concat("/").concat(tenants.getList().get(0).getId())); novaClient.token(access.getToken().getId());
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; }
/** * @param args */ public static void main(String[] args) { Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL); // access with unscoped token Access access = keystone.tokens().authenticate( new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)) .execute(); // use the token in the following requests keystone.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId())); Tenants tenants = keystone.tenants().list().execute(); // try to exchange token using the first tenant if (tenants.getList().size() > 0) { // access with tenant access = keystone.tokens().authenticate(new TokenAuthentication(access.getToken().getId())).withTenantId(tenants.getList().get(0).getId()).execute(); Quantum quantum = new Quantum(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "network", null, "public")); quantum.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId())); Networks networks = quantum.networks().list().execute(); for (Network network : networks) { System.out.println(network); } } else { System.out.println("No tenants found!"); } } }
for (com.woorea.openstack.keystone.model.Tenant t : tenantList.getList()) { System.out.println(t);
if (tenants.getList().size() > 0) {