public void start(String id, NodeLauncherConfig cfg) throws Exception {
JcloudsNodeLauncherConfig config = (JcloudsNodeLauncherConfig) cfg;
m_currentConfig = config;
ComputeService computeService = config.getComputeService();
TemplateBuilder template = computeService.templateBuilder()
.imageId(config.getImageId())
.hardwareId(config.getHardwareId())
.locationId(config.getLocation());
int[] extraPorts = parseExtraPorts(config.getExtraPorts());
int[] inboundPorts = mergePorts(DEFAULT_PORTS, extraPorts);
TemplateOptions options = new EC2TemplateOptions()
.as(EC2TemplateOptions.class).inboundPorts(inboundPorts)
.blockOnComplete(false)
.runAsRoot(config.isRunAsRoot());
if (useConfiguredKeyPair(config)) {
options.as(EC2TemplateOptions.class).keyPair(config.getKeyPair());
}
template.options(options);
Set<? extends NodeMetadata> tag = computeService.createNodesInGroup(config.getTagPrefix() + id, 1, template.build());
if (!useConfiguredPrivateKey(config)) {
System.out.println("In case you need it, this is the key to ssh to " + id + ":\n" + tag.iterator().next().getCredentials().credential);
}
LoginCredentials.Builder loginBuilder = LoginCredentials.builder();
if (config.getSshUser() != null && config.getSshUser().length() > 0) {
loginBuilder.user(config.getSshUser());
} else {
loginBuilder.user("ec2-user");
}
if (useConfiguredPrivateKey(config)) {
loginBuilder.privateKey(Files.toString(new File(config.getPrivateKeyFile()), Charset.defaultCharset()));
}
computeService.runScriptOnNodesMatching(runningInGroup(config.getTagPrefix() + id),
Statements.exec(buildStartupScript(id, config)),
RunScriptOptions.Builder.blockOnComplete(false).overrideLoginCredentials(loginBuilder.build()));
}