Last active
October 11, 2015 12:58
-
-
Save etoews/3862485 to your computer and use it in GitHub Desktop.
jclouds workshop
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
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