From c6de9196a19c794630fd9b1ba50facfbe98afff4 Mon Sep 17 00:00:00 2001 From: "adrian.f.cole" Date: Fri, 22 Jan 2010 21:45:06 +0000 Subject: [PATCH] Issue 130: added image to ant task git-svn-id: http://jclouds.googlecode.com/svn/trunk@2726 3d8758e0-26b5-11de-8745-db77d3ebf521 --- .../jclouds/compute/util/ComputeUtils.java | 1 + .../taskdefs/compute/ComputeTaskUtils.java | 23 ++++++++++++++++++- .../ant/taskdefs/compute/NodeElement.java | 9 ++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/compute/src/main/java/org/jclouds/compute/util/ComputeUtils.java b/compute/src/main/java/org/jclouds/compute/util/ComputeUtils.java index 10ae7e51d2..e740871364 100644 --- a/compute/src/main/java/org/jclouds/compute/util/ComputeUtils.java +++ b/compute/src/main/java/org/jclouds/compute/util/ComputeUtils.java @@ -77,6 +77,7 @@ public class ComputeUtils { try { ssh.connect(); runScriptOnNodeWithClient(ssh, node, script); + break; } catch (RuntimeException from) { if (Iterables.size(Iterables.filter(Throwables.getCausalChain(from), ConnectException.class)) >= 1) { diff --git a/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java b/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java index 6c5aa42295..1f830182e7 100644 --- a/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java +++ b/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java @@ -27,6 +27,7 @@ import java.io.IOException; import java.net.InetAddress; import java.net.URI; import java.util.Map; +import java.util.NoSuchElementException; import java.util.Properties; import java.util.SortedSet; @@ -35,6 +36,7 @@ import org.apache.tools.ant.Project; import org.jclouds.compute.ComputeService; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.TemplateBuilder; @@ -44,6 +46,7 @@ import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.jclouds.tools.ant.logging.config.AntLoggingModule; import com.google.common.base.Function; +import com.google.common.base.Predicate; import com.google.common.base.Splitter; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; @@ -94,7 +97,25 @@ public class ComputeTaskUtils { TemplateBuilder templateBuilder = computeService.templateBuilder(); if (nodeElement.getLocation() != null && !"".equals(nodeElement.getLocation())) templateBuilder.location(nodeElement.getLocation()); - templateBuilder.osFamily(OsFamily.valueOf(nodeElement.getOs())); + if (nodeElement.getImage() != null && !"".equals(nodeElement.getImage())) { + final String imageId = nodeElement.getImage(); + try { + Image image = Iterables.getOnlyElement(Iterables.filter(computeService.listImages(), + new Predicate() { + + @Override + public boolean apply(Image input) { + return input.getId().equals(imageId); + } + + })); + templateBuilder.fromImage(image); + } catch (NoSuchElementException e) { + throw new BuildException("image not found " + nodeElement.getImage()); + } + } else { + templateBuilder.osFamily(OsFamily.valueOf(nodeElement.getOs())); + } addSizeFromElementToTemplate(nodeElement, templateBuilder); return templateBuilder.build(); } diff --git a/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/NodeElement.java b/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/NodeElement.java index eb4702db85..d422624565 100644 --- a/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/NodeElement.java +++ b/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/NodeElement.java @@ -28,6 +28,7 @@ public class NodeElement { private String name; private String size; private String os; + private String image; private String openports = "22"; private String passwordproperty; private String keyfile; @@ -144,4 +145,12 @@ public class NodeElement { return openports; } + public void setImage(String image) { + this.image = image; + } + + public String getImage() { + return image; + } + }