diff --git a/apis/nova/src/main/java/org/jclouds/openstack/nova/options/CreateServerOptions.java b/apis/nova/src/main/java/org/jclouds/openstack/nova/options/CreateServerOptions.java index a750af38ac..03f5e5cedf 100644 --- a/apis/nova/src/main/java/org/jclouds/openstack/nova/options/CreateServerOptions.java +++ b/apis/nova/src/main/java/org/jclouds/openstack/nova/options/CreateServerOptions.java @@ -78,6 +78,7 @@ public class CreateServerOptions implements MapBinder { final String name; final String imageRef; final String flavorRef; + String adminPass; Map metadata; List personality; String key_name; @@ -96,6 +97,7 @@ public class CreateServerOptions implements MapBinder { private List files = Lists.newArrayList(); private Set securityGroups = Sets.newHashSet(); private String keyName; + private String adminPass; @Override public R bindToRequest(R request, Map postParams) { @@ -116,6 +118,9 @@ public class CreateServerOptions implements MapBinder { server.securityGroups.add(group); } } + if (adminPass != null) { + server.adminPass = adminPass; + } return bindToRequest(request, ImmutableMap.of("server", server)); } @@ -140,6 +145,12 @@ public class CreateServerOptions implements MapBinder { files.add(new File(path, contents)); return this; } + + public CreateServerOptions withAdminPass(String adminPass) { + checkNotNull(adminPass, "adminPass"); + this.adminPass = adminPass; + return this; + } /** * Custom cloud server metadata can also be supplied at launch time. This metadata is stored in @@ -197,6 +208,11 @@ public class CreateServerOptions implements MapBinder { CreateServerOptions options = new CreateServerOptions(); return options.withFile(path, contents); } + + public static CreateServerOptions withAdminPass(String adminPass) { + CreateServerOptions options = new CreateServerOptions(); + return options.withAdminPass(adminPass); + } /** * @see CreateServerOptions#withMetadata(Map) diff --git a/apis/nova/src/test/java/org/jclouds/openstack/nova/NovaAsyncClientTest.java b/apis/nova/src/test/java/org/jclouds/openstack/nova/NovaAsyncClientTest.java index 657c0c9abe..e382409fc5 100644 --- a/apis/nova/src/test/java/org/jclouds/openstack/nova/NovaAsyncClientTest.java +++ b/apis/nova/src/test/java/org/jclouds/openstack/nova/NovaAsyncClientTest.java @@ -156,6 +156,26 @@ public class NovaAsyncClientTest extends RestClientTest { checkFilters(request); } + @Test + public void testCreateServerWithAdminPass() throws Exception { + Method method = NovaAsyncClient.class.getMethod("createServer", String.class, String.class, String.class, + createServerOptionsVarargsClass); + HttpRequest request = processor.createRequest(method, "ralphie", 2, 1, + withMetadata(ImmutableMap.of("foo", "bar")).withAdminPass("mypass")); + + assertRequestLineEquals(request, "POST http://endpoint/vapi-version/servers?format=json HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/json\n"); + assertPayloadEquals(request, + "{\"server\":{\"name\":\"ralphie\",\"imageRef\":\"2\",\"flavorRef\":\"1\",\"adminPass\":\"mypass\",\"metadata\":{\"foo\":\"bar\"}}}", + "application/json", false); + + assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + public void testDeleteImage() throws IOException, SecurityException, NoSuchMethodException { Method method = NovaAsyncClient.class.getMethod("deleteImage", int.class); HttpRequest request = processor.createRequest(method, 2); diff --git a/apis/nova/src/test/java/org/jclouds/openstack/nova/options/CreateServerOptionsTest.java b/apis/nova/src/test/java/org/jclouds/openstack/nova/options/CreateServerOptionsTest.java index 760c3cad84..62f10f2b07 100644 --- a/apis/nova/src/test/java/org/jclouds/openstack/nova/options/CreateServerOptionsTest.java +++ b/apis/nova/src/test/java/org/jclouds/openstack/nova/options/CreateServerOptionsTest.java @@ -30,6 +30,7 @@ import java.net.URI; import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withFile; import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withSecurityGroup; +import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withAdminPass; import static org.testng.Assert.assertEquals; /** @@ -88,6 +89,15 @@ public class CreateServerOptionsTest { request.getPayload().getRawContent(), "{\"server\":{\"name\":\"foo\",\"imageRef\":\"1\",\"flavorRef\":\"2\",\"security_groups\":[{\"id\":0,\"name\":\"myothergroup\"},{\"id\":0,\"name\":\"mygroup\"}]}}"); } + + @Test + public void testWithAdminPass() { + CreateServerOptions options = withAdminPass("mypassword"); + HttpRequest request = buildRequest(options); + assertEquals( + request.getPayload().getRawContent(), + "{\"server\":{\"name\":\"foo\",\"imageRef\":\"1\",\"flavorRef\":\"2\",\"adminPass\":\"mypassword\"}}"); + } private void assertFile(HttpRequest request) { assertEquals(request.getPayload().getRawContent(),