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();
}
}
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);
}
}
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());
}
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;
}
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);
}
}
Aggregations