Add the possibility to create a floating IP from a pool of floating IPs

This commit is contained in:
Julien Coste 2013-02-26 14:07:27 +01:00
parent ef08f1b8d3
commit 4bbf8380c7
4 changed files with 63 additions and 0 deletions

View File

@ -57,6 +57,15 @@ public interface FloatingIPApi {
*/
FloatingIP create();
/**
* Allocate a Floating IP address from a pool
*
* @param pool
* Pool to allocate IP address from
* @return a newly created FloatingIP
*/
FloatingIP create(String pool);
/**
* Decreate a Floating IP address
*

View File

@ -97,6 +97,20 @@ public interface FloatingIPAsyncApi {
@Payload("{}")
ListenableFuture<? extends FloatingIP> create();
/**
* @see org.jclouds.openstack.nova.v2_0.extensions.FloatingIPApi#create
*/
@Named("floatingip:create")
@POST
@Path("/os-floating-ips")
@SelectJson("floating_ip")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Fallback(NullOnNotFoundOr404.class)
@Payload("%7B\"pool\":\"{pool}\"%7D")
ListenableFuture<? extends FloatingIP> create(@PayloadParam("pool") String pool);
/**
* @see FloatingIPApi#delete
*/

View File

@ -171,4 +171,23 @@ public class FloatingIPApiExpectTest extends BaseNovaApiExpectTest {
assertNull(apiWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().create());
}
public void testAllocateWithPoolNameWhenResponseIs2xx() throws Exception {
HttpRequest createFloatingIP = HttpRequest
.builder()
.method("POST")
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips")
.addHeader("Accept", "application/json")
.addHeader("X-Auth-Token", authToken)
.payload(payloadFromStringWithContentType("{\"pool\":\"myPool\"}", "application/json")).build();
HttpResponse createFloatingIPResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/floatingip_details.json")).build();
NovaApi apiWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, createFloatingIP,
createFloatingIPResponse);
assertEquals(apiWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().create("myPool").toString(),
new ParseFloatingIPTest().expected().toString());
}
}

View File

@ -173,4 +173,25 @@ public class FloatingIPAsyncApiExpectTest extends BaseNovaAsyncApiExpectTest {
assertNull(apiWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().create().get());
}
public void testAllocateWithPoolNameWhenResponseIs2xx() throws Exception {
HttpRequest createFloatingIP = HttpRequest
.builder()
.method("POST")
.endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips")
.addHeader("Accept", "application/json")
.addHeader("X-Auth-Token", authToken)
.payload(payloadFromStringWithContentType("{\"pool\":\"myPool\"}", "application/json")).build();
HttpResponse createFloatingIPResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/floatingip_details.json")).build();
NovaAsyncApi apiWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, createFloatingIP,
createFloatingIPResponse);
assertEquals(apiWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().create("myPool")
.get()
.toString(), new ParseFloatingIPTest().expected().toString());
}
}