Created
September 16, 2013 14:40
-
-
Save zack-shoylev/6581584 to your computer and use it in GitHub Desktop.
Ignasi example
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
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