// X-Auth-Token (no tenant selected)
OpenstackSession session = new OpenstackSession().with(Feature.VERBOSE);
OpenstackCredentials credentials = new OpenstackCredentials("admin", "woorea");
session.authenticate("http://192.168.1.49:5000/v2.0", credentials);
// Let' show our available tenants
IdentityResource identity = session.getAuthenticationClient().root();
Iterable<Tenant> tenants = identity.tenants().list();
for (Tenant tenant : tenants) {
System.out.println(tenant);
}
// Ok, I will choose the first available tenant (
for (Tenant tenant : tenants) {
credentials.setTenant(tenant.getName());
session.authenticate("http://192.168.1.49:5000/v2.0", credentials);
break;
}
UsersResource usersResource = identity.users();
UsersRepresentation usersRepresentation = usersResource.list();
List<User> users = usersRepresentation.getList();
for(User user : users) {
System.out.println(user);
}
UserResource userResource = usersResource.user(users.get(0).getId());
System.out.println(userResource.show());
RolesResource rolesResource = identity.roles();
RolesRepresentation rolesRepresentation = rolesResource.list();
List<Role> roles = rolesRepresentation.getList();
for(Role role : roles) {
System.out.println(role);
}
RoleResource roleResource = rolesResource.role(roles.get(0).getId());
System.out.println(roleResource.show());
ServicesResource servicesResource = identity.services();
ServicesRepresentation servicesRepresentation = servicesResource.list();
List<Service> services = servicesRepresentation.getList();
for(Service service : services) {
System.out.println(service);
}
ServiceResource serviceResource = servicesResource.service(services.get(0).getId());
System.out.println(serviceResource.show());
EndpointTemplatesResource endpointTemplatesResource = identity.endpointTemplates();
EndpointTemplatesRepresentation endpointTemplatesRepresentation = identity.endpointTemplates().list();
List<EndpointTemplate> endpointTemplates = endpointTemplatesRepresentation.getList();
for(EndpointTemplate endEndpointTemplate : endpointTemplates) {
System.out.println(endEndpointTemplate);
}
EndpointTemplateResource endpointTemplateResource = endpointTemplatesResource.endpointTemplate(services.get(0).getId());
System.out.println(endpointTemplateResource.show());
// Give me access to compute API on the selected tenant
TenantResource compute = session.getComputeClient().root();
for (Server s : compute.servers().list()) {
System.out.println(s);
}
// List the available images
Iterable<Image> images = compute.images().list();
Image image = null;
for (Image i : images) {
System.out.println(i);
//If it's the devstack default image, then i go to select it
if (i.getName().equals("cirros-0.3.0-x86_64-blank")) {
image = i;
break;
}
}
// Show me the image details
System.out.println(image);
// List the available flavors
Iterable<Flavor> flavors = compute.flavors().list();
for (Flavor f : flavors) {
System.out.println(f);
}
// List the servers
Iterable<Server> servers = compute.servers().list();
for (Server s : servers) {
ServerResource sr = new ServerResource(session, s);
System.out.println(sr.get(true).show());
}
System.out.println(compute.servers().server(servers.get(0).getId()).getConsoleOutput(20));
System.out.println(compute.servers().server(servers.get(0).getId()).getVncConsole("novnc"));
We use maven to build the project. Some helpful maven commands:
mvn eclipse:eclipse Create the eclipse projects
mvn install Builds everything, runs unit & integration tests, installs into your maven repo
mvn install -Dmaven.test.skip=true As above, but without running tests
mvn test Runs unit tests
mvn verify Runs integration tests
The integration tests run against an OpenStack installation.
It takes its configuration from the system properties.
Useful properties:
| Property | Default | Explanation |
| openstack.debug | false | Set to true for lots of debug output |
| openstack.auth.url | http://127.0.0.1:5000/v2.0 | Location of Keystone service |
| openstack.auth.user | demo | Authentication info: username |
| openstack.auth.secret | supersecret | Authentication info: password |
| openstack.auth.tenant | demo | Authentication info: tenant |
The defaults should work with a local devstack installation. Otherwise do something like this:
mvn verify -Dopenstack.auth.url=http://192.168.71.1:5000/v2.0
This software is licensed under the Apache 2 license, quoted below.
Copyright 2012 Luis Gervaso and OpenStack Java SDK
Copyright 2012 Justin Santa Barbara
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.