Search in sources :

Example 1 with ScriptBuilder

use of org.jclouds.scriptbuilder.ScriptBuilder in project whirr by apache.

the class RunUrlBuilder method runUrls.

// Need to be able to specify base URL
// Perhaps make these scripts parameterizable?
// e.g. just java/install then base url is .../openjdk or .../sun or
// .../apache or .../cloudera
public static byte[] runUrls(String... urls) throws MalformedURLException {
    ScriptBuilder scriptBuilder = new ScriptBuilder().addStatement(exec("wget -qO/usr/bin/runurl run.alestic.com/runurl")).addStatement(exec("chmod 755 /usr/bin/runurl"));
    // Note that the runurl scripts should be checked in to whirr/scripts/
    String runUrlBase = System.getProperty("whirr.runurl.base", "http://whirr.s3.amazonaws.com/");
    for (String url : urls) {
        scriptBuilder.addStatement(exec("runurl " + new URL(new URL(runUrlBase), url)));
    }
    return scriptBuilder.build(org.jclouds.scriptbuilder.domain.OsFamily.UNIX).getBytes();
}
Also used : ScriptBuilder(org.jclouds.scriptbuilder.ScriptBuilder) URL(java.net.URL)

Example 2 with ScriptBuilder

use of org.jclouds.scriptbuilder.ScriptBuilder 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 3 with ScriptBuilder

use of org.jclouds.scriptbuilder.ScriptBuilder 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)

Example 4 with ScriptBuilder

use of org.jclouds.scriptbuilder.ScriptBuilder 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)

Aggregations

ScriptBuilder (org.jclouds.scriptbuilder.ScriptBuilder)4 RunScriptOptions (org.jclouds.compute.options.RunScriptOptions)3 ExecResponse (org.jclouds.compute.domain.ExecResponse)2 URL (java.net.URL)1 NodeMetadata (org.jclouds.compute.domain.NodeMetadata)1 ZoneAndId (org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndId)1