use of org.jclouds.compute.options.RunScriptOptions in project legacy-jclouds-examples by jclouds.
the class CreateVolumeAndAttach method mountVolume.
private void mountVolume(NodeMetadata node) {
System.out.println("Mount Volume and Create Filesystem");
String script = new ScriptBuilder().addStatement(exec("mkfs -t ext4 /dev/xvdd")).addStatement(exec("mount /dev/xvdd /mnt")).render(OsFamily.UNIX);
RunScriptOptions options = RunScriptOptions.Builder.blockOnComplete(true).overrideLoginPassword(Constants.PASSWORD);
ExecResponse response = compute.runScriptOnNode(node.getId(), script, options);
if (response.getExitStatus() == 0) {
System.out.println(" Exit Status: " + response.getExitStatus());
} else {
System.out.println(" Error: " + response.getOutput());
}
}
use of org.jclouds.compute.options.RunScriptOptions in project legacy-jclouds-examples by jclouds.
the class CloudServersPublish method configureAndStartWebserver.
private void configureAndStartWebserver(Set<? extends NodeMetadata> nodes) throws TimeoutException {
for (NodeMetadata nodeMetadata : nodes) {
String publicAddress = nodeMetadata.getPublicAddresses().iterator().next();
String privateAddress = nodeMetadata.getPrivateAddresses().iterator().next();
System.out.println("Configure And Start Webserver");
awaitSsh(publicAddress);
String message = new StringBuilder().append("Hello from ").append(nodeMetadata.getHostname()).append(" @ ").append(publicAddress).append("/").append(privateAddress).append(" in ").append(nodeMetadata.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);
compute.runScriptOnNode(nodeMetadata.getId(), script, options);
System.out.println(" Login: ssh " + nodeMetadata.getCredentials().getUser() + "@" + publicAddress);
System.out.println(" Password: " + nodeMetadata.getCredentials().getPassword());
System.out.println(" Go to http://" + publicAddress);
}
}
use of org.jclouds.compute.options.RunScriptOptions in project legacy-jclouds-examples by jclouds.
the class DetachVolume method unmountVolume.
/**
* Make sure you've unmounted the volume first. Failure to do so could result in failure or data loss.
*/
private void unmountVolume(VolumeAttachment volumeAttachment) {
System.out.println("Unmount Volume");
String script = new ScriptBuilder().addStatement(exec("umount /mnt")).render(OsFamily.UNIX);
RunScriptOptions options = RunScriptOptions.Builder.overrideLoginUser(Constants.ROOT).overrideLoginPassword(Constants.PASSWORD).blockOnComplete(true);
ZoneAndId zoneAndId = ZoneAndId.fromZoneAndId(Constants.ZONE, volumeAttachment.getServerId());
ExecResponse response = compute.runScriptOnNode(zoneAndId.slashEncode(), script, options);
if (response.getExitStatus() == 0) {
System.out.println(" Exit Status: " + response.getExitStatus());
} else {
System.out.println(" Error: " + response.getOutput());
}
}
Aggregations