Search in sources :

Example 6 with RunScriptOptions

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());
    }
}
Also used : RunScriptOptions(org.jclouds.compute.options.RunScriptOptions) ExecResponse(org.jclouds.compute.domain.ExecResponse) ScriptBuilder(org.jclouds.scriptbuilder.ScriptBuilder)

Example 7 with RunScriptOptions

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);
    }
}
Also used : NodeMetadata(org.jclouds.compute.domain.NodeMetadata) RunScriptOptions(org.jclouds.compute.options.RunScriptOptions) ScriptBuilder(org.jclouds.scriptbuilder.ScriptBuilder)

Example 8 with RunScriptOptions

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());
    }
}
Also used : RunScriptOptions(org.jclouds.compute.options.RunScriptOptions) ExecResponse(org.jclouds.compute.domain.ExecResponse) ZoneAndId(org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndId) ScriptBuilder(org.jclouds.scriptbuilder.ScriptBuilder)

Aggregations

RunScriptOptions (org.jclouds.compute.options.RunScriptOptions)8 ExecResponse (org.jclouds.compute.domain.ExecResponse)6 ComputeService (org.jclouds.compute.ComputeService)4 ScriptBuilder (org.jclouds.scriptbuilder.ScriptBuilder)3 CreateContainerMetadata (io.fabric8.api.CreateContainerMetadata)2 ToRunScriptOptions (io.fabric8.service.jclouds.functions.ToRunScriptOptions)2 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 ExecutionException (java.util.concurrent.ExecutionException)2 Future (java.util.concurrent.Future)2 Cluster (org.apache.whirr.Cluster)2 Instance (org.apache.whirr.Cluster.Instance)2 ClusterSpec (org.apache.whirr.ClusterSpec)2 InstanceTemplate (org.apache.whirr.InstanceTemplate)2 ClusterActionEvent (org.apache.whirr.service.ClusterActionEvent)2 StatementBuilder (org.apache.whirr.service.jclouds.StatementBuilder)2 ComputeServiceContext (org.jclouds.compute.ComputeServiceContext)2 RunNodesException (org.jclouds.compute.RunNodesException)2 NodeMetadata (org.jclouds.compute.domain.NodeMetadata)2