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 name;
final String imageRef; final String imageRef;
final String flavorRef; final String flavorRef;
String adminPass;
Map<String, String> metadata; Map<String, String> metadata;
List<File> personality; List<File> personality;
String key_name; String key_name;
@ -96,6 +97,7 @@ public class CreateServerOptions implements MapBinder {
private List<File> files = Lists.newArrayList(); private List<File> files = Lists.newArrayList();
private Set<String> securityGroups = Sets.newHashSet(); private Set<String> securityGroups = Sets.newHashSet();
private String keyName; private String keyName;
private String adminPass;
@Override @Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) { 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); server.securityGroups.add(group);
} }
} }
if (adminPass != null) {
server.adminPass = adminPass;
}
return bindToRequest(request, ImmutableMap.of("server", server)); return bindToRequest(request, ImmutableMap.of("server", server));
} }
@ -140,6 +145,12 @@ public class CreateServerOptions implements MapBinder {
files.add(new File(path, contents)); files.add(new File(path, contents));
return this; 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 * 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(); CreateServerOptions options = new CreateServerOptions();
return options.withFile(path, contents); 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>) * @see CreateServerOptions#withMetadata(Map<String, String>)

View File

@ -156,6 +156,26 @@ public class NovaAsyncClientTest extends RestClientTest<NovaAsyncClient> {
checkFilters(request); 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 { public void testDeleteImage() throws IOException, SecurityException, NoSuchMethodException {
Method method = NovaAsyncClient.class.getMethod("deleteImage", int.class); Method method = NovaAsyncClient.class.getMethod("deleteImage", int.class);
HttpRequest request = processor.createRequest(method, 2); 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.withFile;
import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withSecurityGroup; 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; import static org.testng.Assert.assertEquals;
/** /**
@ -88,6 +89,15 @@ public class CreateServerOptionsTest {
request.getPayload().getRawContent(), request.getPayload().getRawContent(),
"{\"server\":{\"name\":\"foo\",\"imageRef\":\"1\",\"flavorRef\":\"2\",\"security_groups\":[{\"id\":0,\"name\":\"myothergroup\"},{\"id\":0,\"name\":\"mygroup\"}]}}"); "{\"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) { private void assertFile(HttpRequest request) {
assertEquals(request.getPayload().getRawContent(), assertEquals(request.getPayload().getRawContent(),