@Override public String[] getRow(Tenant tenant) { return new String[]{ tenant.getId(), tenant.getName(), tenant.getDescription(), tenant.getEnabled().toString() }; } });
@Override public void execute(Keystone keystone, CommandLine cmd) { Tenant tenant = new Tenant(); tenant.setName(cmd.getOptionValue("name")); tenant.setDescription(cmd.getOptionValue("description")); if(cmd.getOptionValue("enabled") != null) { tenant.setEnabled(Boolean.TRUE);
/** * 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(); }
public static void main(String[] args) { Keystone client = new Keystone(KEYSTONE_ENDPOINT); client.setTokenProvider(new OpenStackSimpleTokenProvider("secret0")); client.tenants().delete("36c481aec1d54fc49190c92c3ef6840a").execute(); Tenant tenant = client.tenants().create(new Tenant("new_api")).execute(); System.out.println(tenant); System.out.println(client.tenants().list().execute()); client.tenants().delete(tenant.getId()).execute(); }
if (t.getName().equals(tenantName)) { tenant = new OpenStackTenant((OpenStackContext) context, t); break;
@Override public String[] getRow(Tenant tenant) { return new String[]{ tenant.getId(), tenant.getName(), tenant.getDescription(), tenant.getEnabled().toString() }; } });
/** * @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(); access = keystone.tokens().authenticate(new TokenAuthentication(access.getToken().getId())).withTenantName("admin").execute(); Tenant tenant = new Tenant(); tenant.setName("benn.cs"); tenant.setDescription("benn.cs"); tenant.setEnabled(true); //Get the adminURL client and use the token got above keystone = new Keystone("http://keystone.x.org/v2.0"); keystone.token(access.getToken().getId()); tenant = keystone.tenants().create(tenant).execute(); System.out.println(tenant); keystone.tenants().delete(tenant.getId()); } }
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());
/** * Create the Tenant object implementation for the OpenStack provider * * @param context * The OpenStack context we are servicing * @param tenant * The OpenStack tenant definition */ public OpenStackTenant(OpenStackContext context, com.woorea.openstack.keystone.model.Tenant tenant) { super(context); setId(tenant.getId()); setName(tenant.getName()); setDescription(tenant.getDescription()); setEnabled(tenant.getEnabled()); Properties properties = context.getProperties(); setName(properties.getProperty(ContextFactory.PROPERTY_TENANT)); } }
/** * @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); } }
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(); } } }
/** * @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!"); } } }
access = keystone.tokens().authenticate(new TokenAuthentication(access.getToken().getId())).withTenantId(tenants.getList().get(0).getId()).execute();
access = keystone.tokens().authenticate(new TokenAuthentication(access.getToken().getId())).withTenantId(tenants.getList().get(0).getId()).execute();