h1. OpenStack Java SDK

h2. Example

h3. Identity API (keystone)

h4. Access

<pre>
// 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);
</pre>

h4. Tenants

<pre>
// 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;
}
</pre>

h4. Users (this is from previous revision)

<pre>
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());
</pre>

h4. Roles (this is from previous revision)

<pre>
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());
</pre>

h4. Services (this is from previous revision)

<pre>
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());
</pre>

h4. EndpointTemplates (this is from previous revision)

<pre>
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());
</pre>

h3. Compute API (nova)

h4. Select a Tenant

<pre>
// 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);
}
</pre>

h4. Images

<pre>
// 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);
</pre>

h4. Flavors

<pre>
// List the available flavors
Iterable<Flavor> flavors = compute.flavors().list();
for (Flavor f : flavors) {
	System.out.println(f);
}
</pre>

h4. Servers

<pre>
// 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());
}
</pre>

h4. Server Actions

<pre>
System.out.println(compute.servers().server(servers.get(0).getId()).getConsoleOutput(20));
System.out.println(compute.servers().server(servers.get(0).getId()).getVncConsole("novnc"));
</pre>

h1. Maven

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_

h2. 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@


h1. License

<pre>
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.
</pre>
