Merge pull request #331 from chamerling/master

One should be able to define adminPass when creating server
This commit is contained in:
Andrei Savu 2012-01-23 06:34:04 -08:00
commit ecfe1287e9
3 changed files with 46 additions and 0 deletions

View File

@ -78,6 +78,7 @@ public class CreateServerOptions implements MapBinder {
final String name;
final String imageRef;
final String flavorRef;
String adminPass;
Map<String, String> metadata;
List<File> personality;
String key_name;
@ -96,6 +97,7 @@ public class CreateServerOptions implements MapBinder {
private List<File> files = Lists.newArrayList();
private Set<String> securityGroups = Sets.newHashSet();
private String keyName;
private String adminPass;
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> 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));
}
@ -141,6 +146,12 @@ public class CreateServerOptions implements MapBinder {
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
* the API system where it is retrievable by querying the API for server status. The maximum size
@ -198,6 +209,11 @@ public class CreateServerOptions implements MapBinder {
return options.withFile(path, contents);
}
public static CreateServerOptions withAdminPass(String adminPass) {
CreateServerOptions options = new CreateServerOptions();
return options.withAdminPass(adminPass);
}
/**
* @see CreateServerOptions#withMetadata(Map<String, String>)
*/

View File

@ -156,6 +156,26 @@ public class NovaAsyncClientTest extends RestClientTest<NovaAsyncClient> {
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);

View File

@ -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;
/**
@ -89,6 +90,15 @@ public class CreateServerOptionsTest {
"{\"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(),
"{\"server\":{\"name\":\"foo\",\"imageRef\":\"1\",\"flavorRef\":\"2\",\"personality\":[{\"path\":\"/tmp/rhubarb\",\"contents\":\"Zm9v\"}]}}");