Skip to content

Instantly share code, notes, and snippets.

@etoews
Created August 15, 2012 15:27
Show Gist options
  • Save etoews/3361018 to your computer and use it in GitHub Desktop.
Save etoews/3361018 to your computer and use it in GitHub Desktop.
Getting started with jclouds
import 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 = "my-username";
String apiKey = "my-api-key";
ComputeServiceContext context = ContextBuilder.newBuilder(provider)
.credentials(identity, apiKey)
.buildView(ComputeServiceContext.class);
compute = context.getComputeService();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment