mirror of https://github.com/apache/jclouds.git
Issue 129: added detail listing
git-svn-id: http://jclouds.googlecode.com/svn/trunk@2463 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
ce1b6dea27
commit
59bfcdb80f
|
@ -39,23 +39,27 @@
|
|||
<property name="jclouds.compute.url" value="compute://${jclouds.compute.account}:${jclouds.compute.key}@${jclouds.compute.provider}" />
|
||||
<property name="jclouds.compute.servername" value="testforjcloud2" />
|
||||
|
||||
<target name="list">
|
||||
<target name="list" description="list the identity of all servers" >
|
||||
<compute action="list" provider="${jclouds.compute.url}" />
|
||||
</target>
|
||||
|
||||
<target name="clean">
|
||||
<target name="list-details" description="list the details of all servers" >
|
||||
<compute action="list-details" provider="${jclouds.compute.url}" />
|
||||
</target>
|
||||
|
||||
<target name="destroy" description="destroy the server ${jclouds.compute.servername}" >
|
||||
<compute action="destroy" provider="${jclouds.compute.url}">
|
||||
<server name="${jclouds.compute.servername}" />
|
||||
</compute>
|
||||
</target>
|
||||
|
||||
<target name="get">
|
||||
<target name="get" description="get the server ${jclouds.compute.servername}" >
|
||||
<compute action="get" provider="${jclouds.compute.url}">
|
||||
<server name="${jclouds.compute.servername}" />
|
||||
</compute>
|
||||
</target>
|
||||
|
||||
<target name="create">
|
||||
<target name="create" description="create the server ${jclouds.compute.servername}" >
|
||||
<compute action="create" provider="${jclouds.compute.url}">
|
||||
<server name="${jclouds.compute.servername}" image="CENTOS_53" profile="SMALLEST" />
|
||||
</compute>
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
package org.jclouds.tools.ant;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
@ -38,13 +39,14 @@ import org.jclouds.compute.domain.CreateServerResponse;
|
|||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.Profile;
|
||||
import org.jclouds.compute.domain.ServerIdentity;
|
||||
import org.jclouds.compute.domain.ServerMetadata;
|
||||
import org.jclouds.http.HttpUtils;
|
||||
import org.jclouds.tools.ant.logging.config.AntLoggingModule;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.MapMaker;
|
||||
import com.google.common.io.Resources;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
|
@ -67,6 +69,10 @@ public class ComputeTask extends Task {
|
|||
|
||||
};
|
||||
|
||||
public ComputeTask(Map<URI, ComputeService> computeMap) {
|
||||
this.computeMap = computeMap;
|
||||
}
|
||||
|
||||
public ComputeTask() throws IOException {
|
||||
this(buildComputeMap(loadDefaultProperties()));
|
||||
}
|
||||
|
@ -90,12 +96,8 @@ public class ComputeTask extends Task {
|
|||
|
||||
}
|
||||
|
||||
public ComputeTask(Map<URI, ComputeService> computeMap) {
|
||||
this.computeMap = computeMap;
|
||||
}
|
||||
|
||||
public static enum Action {
|
||||
CREATE, GET, LIST, DESTROY
|
||||
CREATE, GET, LIST, LIST_DETAILS, DESTROY
|
||||
}
|
||||
|
||||
private String provider;
|
||||
|
@ -119,7 +121,8 @@ public class ComputeTask extends Task {
|
|||
|
||||
public void execute() throws BuildException {
|
||||
ComputeTask.project = getProject();
|
||||
Action action = Action.valueOf(this.action.toUpperCase());
|
||||
Action action = Action.valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE,
|
||||
this.action));
|
||||
ComputeService computeService = computeMap.get(HttpUtils.createUri(provider));
|
||||
switch (action) {
|
||||
case CREATE:
|
||||
|
@ -147,6 +150,12 @@ public class ComputeTask extends Task {
|
|||
log(String.format(" id=%s, name=%s", server.getId(), server.getName()));
|
||||
}
|
||||
break;
|
||||
case LIST_DETAILS:
|
||||
log("list details");
|
||||
for (ServerIdentity server : computeService.listServers()) {// TODO parallel
|
||||
logDetails(computeService, server);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
this.log("bad action: " + action, Project.MSG_ERR);
|
||||
}
|
||||
|
@ -183,13 +192,26 @@ public class ComputeTask extends Task {
|
|||
.getName());
|
||||
if (serversThatMatch.size() > 0) {
|
||||
for (ServerIdentity server : serversThatMatch) {
|
||||
log(String.format(" server id=%s, name=%s, value=%s", server.getId(), server
|
||||
.getName(), new Gson()
|
||||
.toJson(computeService.getServerMetadata(server.getId()))));
|
||||
logDetails(computeService, server);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void logDetails(ComputeService computeService, ServerIdentity server) {
|
||||
ServerMetadata metadata = computeService.getServerMetadata(server.getId());
|
||||
log(String.format(" server id=%s, name=%s, state=%s, publicIp=%s, privateIp=%s", metadata
|
||||
.getId(), server.getName(), metadata.getState(), ipOrEmptyString(metadata
|
||||
.getPublicAddresses()), ipOrEmptyString(metadata.getPrivateAddresses())));
|
||||
}
|
||||
|
||||
public static String ipOrEmptyString(SortedSet<InetAddress> set) {
|
||||
if (set.size() > 0) {
|
||||
return set.last().getHostAddress();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public String getAction() {
|
||||
return action;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue