issue 202. http://code.google.com/p/jclouds/issues/detail?id=202. added withMetadata to TemplateOptions

This commit is contained in:
Alex Yarmula 2010-04-26 10:03:03 -07:00
parent 950776c0e9
commit a56f2225b7
3 changed files with 30 additions and 1 deletions

View File

@ -374,6 +374,10 @@ public class BaseComputeService implements ComputeService {
// don't override // don't override
checkNotNull(node.getCredentials(), checkNotNull(node.getCredentials(),
"If the default credentials need to be used, they can't be null"); "If the default credentials need to be used, they can't be null");
checkNotNull(node.getCredentials().account, "Account name for ssh authentication must be " +
"specified. Try passing RunScriptOptions with new credentials");
checkNotNull(node.getCredentials().key, "Key or password for ssh authentication must be " +
"specified. Try passing RunScriptOptions with new credentials");
} }
ComputeUtils.SshCallable<?> callable; ComputeUtils.SshCallable<?> callable;

View File

@ -38,6 +38,8 @@ public class TemplateOptions {
private int seconds = -1; private int seconds = -1;
private boolean includeMetadata;
public int getPort() { public int getPort() {
return port; return port;
} }
@ -66,6 +68,10 @@ public class TemplateOptions {
return destroyOnError; return destroyOnError;
} }
public boolean isIncludeMetadata() {
return includeMetadata;
}
/** /**
* When the node is started, wait until the following port is active * When the node is started, wait until the following port is active
*/ */
@ -127,6 +133,11 @@ public class TemplateOptions {
return this; return this;
} }
public TemplateOptions withMetadata() {
this.includeMetadata = true;
return this;
}
public static class Builder { public static class Builder {
/** /**
* @see TemplateOptions#destroyOnError * @see TemplateOptions#destroyOnError
@ -176,6 +187,11 @@ public class TemplateOptions {
return options.authorizePublicKey(rsaKey); return options.authorizePublicKey(rsaKey);
} }
public static TemplateOptions withDetails() {
TemplateOptions options = new TemplateOptions();
return options.withMetadata();
}
} }
@Override @Override
@ -183,6 +199,6 @@ public class TemplateOptions {
return "TemplateOptions [inboundPorts=" + Arrays.toString(inboundPorts) + ", privateKey=" return "TemplateOptions [inboundPorts=" + Arrays.toString(inboundPorts) + ", privateKey="
+ (privateKey != null) + ", publicKey=" + (publicKey != null) + ", runScript=" + (privateKey != null) + ", publicKey=" + (publicKey != null) + ", runScript="
+ (script != null) + ", destroyOnError=" + destroyOnError + ", port:seconds=" + port + (script != null) + ", destroyOnError=" + destroyOnError + ", port:seconds=" + port
+ ":" + seconds + "]"; + ":" + seconds + ", metadata/details: " + includeMetadata + "]";
} }
} }

View File

@ -47,6 +47,7 @@ import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.options.GetNodesOptions; import org.jclouds.compute.options.GetNodesOptions;
import org.jclouds.compute.options.RunScriptOptions; import org.jclouds.compute.options.RunScriptOptions;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpResponseException;
@ -316,6 +317,14 @@ public abstract class BaseComputeServiceLiveTest {
testGet(); testGet();
} }
@Test(enabled = true/*, dependsOnMethods = "testTemplateMatch"*/)
public void testTemplateOptions() throws Exception {
TemplateOptions options = new TemplateOptions().withMetadata();
Template t = client.templateBuilder().smallest().options(options).build();
assert t.getOptions().isIncludeMetadata() : "The metadata option should be 'true' " +
"for the created template";
}
public void testListNodes() throws Exception { public void testListNodes() throws Exception {
for (Entry<String, ? extends ComputeMetadata> node : client.getNodes().entrySet()) { for (Entry<String, ? extends ComputeMetadata> node : client.getNodes().entrySet()) {
assertEquals(node.getKey(), node.getValue().getId()); assertEquals(node.getKey(), node.getValue().getId());