I got a comment on my jclouds and OpenStack post about how to get the Tenant ID via jclouds. The first solution that popped to my mind was to get the Tenant ID out of the access data structure that gets returned upon authentication. This turned out to be a bit trickier than expected as jclouds automatically authenticates on your first actual interaction with a cloud (i.e. the very first time you call a method that needs to talk to the cloud). To get the access data structure I needed to manually authenticate. Here's how to do it.
First off, get the jclouds JAR files.
- Ensure you are using the Java Development Kit (JDK) version 6 or later.
- Ensure you are using Maven version 3 or later.
- Create a directory to try out jclouds.
- Make a local copy of this pom.xml file in the jclouds directory.
mvn dependency:copy-dependencies "-DoutputDirectory=./lib"
- You should now have a directory with the following structure:
Put this code in your jclouds directory to do manual authentication. An explanation follows.
javac -cp ".:lib/*" JCloudsManualAuthentication.java
- Run on OpenStack.
java -cp ".:lib/*" JCloudsManualAuthentication openstack-nova demo:demo devstack http://22.214.171.124:5000/v2.0/
- Run on Rackspace as this code works equally well with any OpenStack powered provider.
java -cp ".:lib/*" JCloudsManualAuthentication rackspace-cloudservers-us myRackspaceUsername myRackspaceAPIKey
The key to the example is lines 93 & 94. Because jclouds normally handles the authentication manually we have to use a bit of Guice-fu on line 93 to get a hold of the Function that can manually authenticate by taking our Credentials and returning the Access data structure. On line 94 we execute that Function and the authentication happens. After that we can run through the Access object and get the information we need.
It's rare that you would need to authenticate manually in jclouds. Most of the time letting jclouds automatically handle the auth for you suffices. However, if you do need to authenticate manually, this method will give you a lot of information about your OpenStack environment.