From 4bbf8380c778ecca81171f6aa6144a62afd43728 Mon Sep 17 00:00:00 2001 From: Julien Coste Date: Tue, 26 Feb 2013 14:07:27 +0100 Subject: [PATCH] Add the possibility to create a floating IP from a pool of floating IPs --- .../nova/v2_0/extensions/FloatingIPApi.java | 9 ++++++++ .../v2_0/extensions/FloatingIPAsyncApi.java | 14 +++++++++++++ .../extensions/FloatingIPApiExpectTest.java | 19 +++++++++++++++++ .../FloatingIPAsyncApiExpectTest.java | 21 +++++++++++++++++++ 4 files changed, 63 insertions(+) diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApi.java index d0a26334a5..2f8a64af6c 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApi.java @@ -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 * diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPAsyncApi.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPAsyncApi.java index 3ef2ff39a3..a123a1db13 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPAsyncApi.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPAsyncApi.java @@ -97,6 +97,20 @@ public interface FloatingIPAsyncApi { @Payload("{}") ListenableFuture 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 create(@PayloadParam("pool") String pool); + + /** * @see FloatingIPApi#delete */ diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiExpectTest.java index 9f3369fd84..e2fc71dfc8 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiExpectTest.java @@ -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()); + } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPAsyncApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPAsyncApiExpectTest.java index 4e14b20c1b..998839854c 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPAsyncApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPAsyncApiExpectTest.java @@ -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()); + } + }