Created
August 29, 2012 13:50
-
-
Save anonymous/3512810 to your computer and use it in GitHub Desktop.
Attempt at connecting to my OpenStack setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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