RSS

jclouds Manual Authentication with OpenStack

17 Jun

LockI 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.

Get jclouds

First off, get the jclouds JAR files.

  1. Ensure you are using the Java Development Kit (JDK) version 6 or later.
    • javac -version
  2. Ensure you are using Maven version 3 or later.
    • mvn -version
  3. Create a directory to try out jclouds.
    • mkdir jclouds
    • cd jclouds
  4. Make a local copy of this pom.xml file in the jclouds directory.
    • mvn dependency:copy-dependencies "-DoutputDirectory=./lib"
  5. You should now have a directory with the following structure:
    • jclouds/
      • pom.xml
      • lib/
        • *.jar

Manual Authentication

Put this code in your jclouds directory to do manual authentication. An explanation follows.

  1. Compile.
    1. javac -cp ".:lib/*" JCloudsManualAuthentication.java
  2. Run on OpenStack.
    1. java -cp ".:lib/*" JCloudsManualAuthentication openstack-nova demo:demo devstack http://123.123.123.123:5000/v2.0/
  3. Run on Rackspace as this code works equally well with any OpenStack powered provider.
    1. 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.

Coda

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.

 
2 Comments

Posted by on June 17, 2013 in jclouds, openstack, rackspace

 

2 responses to “jclouds Manual Authentication with OpenStack

  1. Dmitry Mishin

    November 8, 2013 at 8:59 am

    Hello Everett,
    Thanks for your post. Is it possible to manually recreate the context with cached token? If I don’t want to keep the context object, but I can store the previous token for the user and use it when needed?

     
    • Everett Toews

      November 12, 2013 at 5:48 pm

      There’s no way to do this that I’m aware of. Also note that tokens are (typically) only good for 24 hours so storing them for later use doesn’t buy you much.

       

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: