Search in sources :

Example 26 with NodeMetadata

use of org.jclouds.compute.domain.NodeMetadata in project legacy-jclouds-examples by jclouds.

the class CreateVolumeAndAttach method main.

/**
    * To get a username and API key see http://www.jclouds.org/documentation/quickstart/rackspace/
    * 
    * The first argument (args[0]) must be your username
    * The second argument (args[1]) must be your API key
    */
public static void main(String[] args) {
    CreateVolumeAndAttach createVolumeAndAttach = new CreateVolumeAndAttach();
    try {
        createVolumeAndAttach.init(args);
        NodeMetadata node = createVolumeAndAttach.createServer();
        Volume volume = createVolumeAndAttach.createVolume();
        createVolumeAndAttach.attachVolume(volume, node);
        createVolumeAndAttach.mountVolume(node);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        createVolumeAndAttach.close();
    }
}
Also used : NodeMetadata(org.jclouds.compute.domain.NodeMetadata) Volume(org.jclouds.openstack.cinder.v1.domain.Volume) TimeoutException(java.util.concurrent.TimeoutException) RunNodesException(org.jclouds.compute.RunNodesException)

Example 27 with NodeMetadata

use of org.jclouds.compute.domain.NodeMetadata 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 28 with NodeMetadata

use of org.jclouds.compute.domain.NodeMetadata in project legacy-jclouds-examples by jclouds.

the class CreateServer method createServer.

/**
    * Create a server based on a Template. This method uses Template.fromHardware() and Template.fromImage() to
    * also demonstrate iterating through Hardware and Images. Alternatively you do the same without iterating
    * using the following Template.
    * 
    * Template template = compute.templateBuilder()
    *     .locationId(getLocationId())
    *     .osFamily(OsFamily.UBUNTU)
    *     .osVersionMatches("12.04")
    *     .minRam(512)
    *     .build();
    */
private void createServer() throws RunNodesException, TimeoutException {
    Template template = compute.templateBuilder().locationId(getLocationId()).fromHardware(getHardware()).fromImage(getImage()).build();
    System.out.println("Create Server");
    // This method will continue to poll for the server status and won't return until this server is ACTIVE
    // If you want to know what's happening during the polling, enable logging. See
    // /jclouds-example/rackspace/src/main/java/org/jclouds/examples/rackspace/Logging.java
    Set<? extends NodeMetadata> nodes = compute.createNodesInGroup(Constants.NAME, 1, template);
    NodeMetadata nodeMetadata = nodes.iterator().next();
    String publicAddress = nodeMetadata.getPublicAddresses().iterator().next();
    System.out.println("  " + nodeMetadata);
    System.out.println("  Login: ssh " + nodeMetadata.getCredentials().getUser() + "@" + publicAddress);
    System.out.println("  Password: " + nodeMetadata.getCredentials().getPassword());
}
Also used : NodeMetadata(org.jclouds.compute.domain.NodeMetadata) Template(org.jclouds.compute.domain.Template)

Example 29 with NodeMetadata

use of org.jclouds.compute.domain.NodeMetadata in project legacy-jclouds-examples by jclouds.

the class CreateLoadBalancerWithNewServers method createNodeRequests.

/**
    * AddNodes specify the nodes (Cloud Servers) that requests will be sent to by the Load Balancer.
    */
private Set<AddNode> createNodeRequests(Set<? extends NodeMetadata> nodes) {
    Set<AddNode> addNodes = Sets.newHashSet();
    for (NodeMetadata node : nodes) {
        String privateAddress = node.getPrivateAddresses().iterator().next();
        AddNode addNode = AddNode.builder().address(privateAddress).condition(Node.Condition.ENABLED).port(80).weight(20).build();
        addNodes.add(addNode);
    }
    return addNodes;
}
Also used : NodeMetadata(org.jclouds.compute.domain.NodeMetadata) AddNode(org.jclouds.rackspace.cloudloadbalancers.v1.domain.AddNode)

Example 30 with NodeMetadata

use of org.jclouds.compute.domain.NodeMetadata in project legacy-jclouds-examples by jclouds.

the class ListServersWithFiltering method listServersByParentLocationId.

private void listServersByParentLocationId() {
    System.out.println("List Servers By Parent Location Id");
    Set<? extends NodeMetadata> servers = compute.listNodesDetailsMatching(NodePredicates.parentLocationId(Constants.ZONE));
    for (NodeMetadata nodeMetadata : servers) {
        System.out.println("  " + nodeMetadata);
    }
}
Also used : NodeMetadata(org.jclouds.compute.domain.NodeMetadata)

Aggregations

NodeMetadata (org.jclouds.compute.domain.NodeMetadata)35 RunNodesException (org.jclouds.compute.RunNodesException)11 Template (org.jclouds.compute.domain.Template)9 ComputeService (org.jclouds.compute.ComputeService)7 IOException (java.io.IOException)6 TemplateBuilder (org.jclouds.compute.domain.TemplateBuilder)6 Test (org.junit.Test)5 Exchange (org.apache.camel.Exchange)4 ComputeServiceContext (org.jclouds.compute.ComputeServiceContext)4 RunScriptOnNodesException (org.jclouds.compute.RunScriptOnNodesException)4 Statement (org.jclouds.scriptbuilder.domain.Statement)4 File (java.io.File)3 Set (java.util.Set)3 InstanceTemplate (org.apache.whirr.service.ClusterSpec.InstanceTemplate)3 ComputeMetadata (org.jclouds.compute.domain.ComputeMetadata)3 LoginCredentials (org.jclouds.domain.LoginCredentials)3 Predicate (com.google.common.base.Predicate)2 Properties (java.util.Properties)2 Host (org.apache.hive.ptest.execution.conf.Host)2 RunListBuilder (org.jclouds.chef.util.RunListBuilder)2