Merge pull request #1368 from jcoste/floatingIPFromPool

Nova : Allocate a floating IP from a specified pool instead of the default one
This commit is contained in:
Adrian Cole 2013-03-01 15:20:15 -08:00
commit d41e6f82e2
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 allocateFromPool(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#allocateFromPool
*/
@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> allocateFromPool(@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().allocateFromPool("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().allocateFromPool("myPool")
.get()
.toString(), new ParseFloatingIPTest().expected().toString());
}
}