Skip to content

Instantly share code, notes, and snippets.

@zack-shoylev
Created September 16, 2013 14:40
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 zack-shoylev/6581584 to your computer and use it in GitHub Desktop.
Save zack-shoylev/6581584 to your computer and use it in GitHub Desktop.
Ignasi example
String endpoint = "http://127.0.0.1:5000/v2.0/";
Iterable<Module> modules = ImmutableSet.<Module> of(
new SshjSshClientModule(),
new SLF4JLoggingModule());
ComputeServiceContext context = ContextBuilder.newBuilder(provider)
.credentials(user, password)
.endpoint(endpoint)
.modules(modules)
.apiVersion("2")
.buildView(ComputeServiceContext.class);
compute = context.getComputeService(); // The abstraction layer
try {
Map<String,String> keys = SshKeys.generate();
privateKey = keys.get("private");
Files.write(privateKey, new File("jclouds.pem"), UTF_8);
TemplateOptions options = compute.templateOptions().inboundPorts(22, 80);
options.authorizePublicKey(keys.get("public")).overrideLoginPrivateKey(privateKey);
Template template = compute.templateBuilder()
.minRam(1024)
.smallest()
.imageNameMatches("cirros-0.3.1-x86_64-uec$")
.options(options)
.build();
Set<? extends NodeMetadata> nodesInGroup = compute.createNodesInGroup("jclouds-workshop", 1, template);
node = nodesInGroup.iterator().next();
System.out.println("Node created: " + node.toString());
System.out.println("Node Image: " + node.getImageId());
}
catch (Throwable e) {
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment