Skip to content

Instantly share code, notes, and snippets.

@etoews
Last active October 11, 2015 12:58
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 etoews/3862485 to your computer and use it in GitHub Desktop.
Save etoews/3862485 to your computer and use it in GitHub Desktop.
jclouds workshop
private void configureAndStartWebservers() {
for (ComputeService computeService: nodes.keySet()) {
try {
NodeMetadata node = nodes.get(computeService);
String publicAddress = node.getPublicAddresses().iterator().next();
awaitSsh(publicAddress);
String message = new StringBuilder()
.append("Hello from ")
.append(node.getHostname())
.append(" @ ")
.append(publicAddress)
.append(" in ")
.append(node.getLocation().getParent().getId())
.toString();
String script = new ScriptBuilder()
.addStatement(exec("yum -y install httpd"))
.addStatement(exec("/usr/sbin/apachectl start"))
.addStatement(exec("iptables -I INPUT -p tcp --dport 80 -j ACCEPT"))
.addStatement(exec("echo '" + message + "' > /var/www/html/index.html"))
.render(OsFamily.UNIX);
RunScriptOptions options = RunScriptOptions.Builder
.blockOnComplete(true);
computeService.runScriptOnNode(node.getId(), script, options);
}
catch (Throwable e) {
e.printStackTrace();
}
}
}
private void awaitSsh(String ip) throws TimeoutException {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment