Skip to content

Instantly share code, notes, and snippets.

Created August 29, 2012 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3512810 to your computer and use it in GitHub Desktop.
Save anonymous/3512810 to your computer and use it in GitHub Desktop.
Attempt at connecting to my OpenStack setup
mport java.util.Set;
import java.lang.Thread.UncaughtExceptionHandler;
import org.jclouds.ContextBuilder;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.domain.ComputeMetadata;
public class JCloudsTest {
private ComputeService compute;
public static void main(String[] args) {
JCloudsTest jCloudsTest = new JCloudsTest();
jCloudsTest.init();
jCloudsTest.listServers();
System.exit(0);
}
private void listServers() {
System.out.println("Calling listNodes...");
Set<? extends ComputeMetadata> nodes = compute.listNodes();
System.out.println("Total Number of Nodes = " + nodes.size());
for (ComputeMetadata node: nodes) {
System.out.println("\t" + node);
}
}
private void init() {
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
public void uncaughtException(Thread t, Throwable e) {
e.printStackTrace();
System.exit(1);
}
});
String provider = "rackspace-cloudservers-us";
String identity = "admin";
String apiKey = "nova";
ComputeServiceContext context = ContextBuilder.newBuilder(provider)
.credentials(identity, apiKey)
.endpoint("http://192.168.111.220:35357/v2.0/")
.buildView(ComputeServiceContext.class);
compute = context.getComputeService();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment