Skip to content
Permalink
Browse files
Adds rackspace cloudnetworks-us provider
  • Loading branch information
zack-shoylev committed Nov 15, 2014
1 parent df6a645 commit 3faafe06e91bf6512bc97de0ab420016a6b9ac47
Showing 20 changed files with 916 additions and 236 deletions.
@@ -21,16 +21,15 @@

import javax.ws.rs.Path;

import org.jclouds.Constants;
import org.jclouds.location.Region;
import org.jclouds.location.functions.RegionToEndpoint;
import org.jclouds.openstack.neutron.v2.extensions.FloatingIPApi;
import org.jclouds.openstack.neutron.v2.extensions.RouterApi;
import org.jclouds.openstack.neutron.v2.extensions.SecurityGroupApi;
import org.jclouds.openstack.neutron.v2.extensions.lbaas.v1.LBaaSApi;
import org.jclouds.openstack.neutron.v2.features.NetworkApi;
import org.jclouds.openstack.neutron.v2.features.PortApi;
import org.jclouds.openstack.neutron.v2.features.SubnetApi;
import org.jclouds.openstack.neutron.v2.functions.VersionAwareRegionToEndpoint;
import org.jclouds.openstack.v2_0.features.ExtensionApi;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.EndpointParam;
@@ -40,8 +39,16 @@

/**
* Provides access to the OpenStack Networking (Neutron) v2 API.
*
* The service-side API will always have a v2.0 in the path.
* However, the endpoint will sometimes contain a v2.0 and sometimes it will not.
* The @Path annotation here ensures the path is always added. The VersionAwareRegionToEndpoint ensures that the
* endpoint will always look the same.
*
* Cannot leave labs until fixed:
* TODO: https://issues.apache.org/jira/browse/JCLOUDS-773
*/
@Path("{" + Constants.PROPERTY_API_VERSION + "}")
@Path("v2.0")
public interface NeutronApi extends Closeable {
/**
* @return the Region codes configured
@@ -54,25 +61,25 @@ public interface NeutronApi extends Closeable {
* Provides access to Extension features.
*/
@Delegate
ExtensionApi getExtensionApi(@EndpointParam(parser = RegionToEndpoint.class) String region);
ExtensionApi getExtensionApi(@EndpointParam(parser = VersionAwareRegionToEndpoint.class) String region);

/**
* Provides access to Network features.
*/
@Delegate
NetworkApi getNetworkApi(@EndpointParam(parser = RegionToEndpoint.class) String region);
NetworkApi getNetworkApi(@EndpointParam(parser = VersionAwareRegionToEndpoint.class) String region);

/**
* Provides access to Subnet features.
*/
@Delegate
SubnetApi getSubnetApi(@EndpointParam(parser = RegionToEndpoint.class) String region);
SubnetApi getSubnetApi(@EndpointParam(parser = VersionAwareRegionToEndpoint.class) String region);

/**
* Provides access to Port features.
*/
@Delegate
PortApi getPortApi(@EndpointParam(parser = RegionToEndpoint.class) String region);
PortApi getPortApi(@EndpointParam(parser = VersionAwareRegionToEndpoint.class) String region);

/**
* Provides access to Router features.
@@ -82,7 +89,7 @@ public interface NeutronApi extends Closeable {
* to determine if it is present.
*/
@Delegate
Optional<RouterApi> getRouterApi(@EndpointParam(parser = RegionToEndpoint.class) String region);
Optional<RouterApi> getRouterApi(@EndpointParam(parser = VersionAwareRegionToEndpoint.class) String region);

/**
* Provides access to Floating IP features.
@@ -92,7 +99,7 @@ public interface NeutronApi extends Closeable {
* to determine if it is present.
*/
@Delegate
Optional<FloatingIPApi> getFloatingIPApi(@EndpointParam(parser = RegionToEndpoint.class) String region);
Optional<FloatingIPApi> getFloatingIPApi(@EndpointParam(parser = VersionAwareRegionToEndpoint.class) String region);

/**
* Provides access to SecurityGroup features.
@@ -102,7 +109,7 @@ public interface NeutronApi extends Closeable {
* to determine if it is present.
*/
@Delegate
Optional<SecurityGroupApi> getSecurityGroupApi(@EndpointParam(parser = RegionToEndpoint.class) String region);
Optional<SecurityGroupApi> getSecurityGroupApi(@EndpointParam(parser = VersionAwareRegionToEndpoint.class) String region);

/**
* Provides access to LBaaS features.
@@ -112,5 +119,5 @@ public interface NeutronApi extends Closeable {
* to determine if it is present.
*/
@Delegate
Optional<LBaaSApi> getLBaaSApi(@EndpointParam(parser = RegionToEndpoint.class) String region);
Optional<LBaaSApi> getLBaaSApi(@EndpointParam(parser = VersionAwareRegionToEndpoint.class) String region);
}
@@ -0,0 +1,67 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.openstack.neutron.v2.functions;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;

import java.net.URI;
import java.util.Map;

import javax.inject.Inject;

import org.jclouds.location.Region;

import com.google.common.base.Function;
import com.google.common.base.Supplier;

public class VersionAwareRegionToEndpoint implements Function<Object, URI> {

private final Supplier<Map<String, Supplier<URI>>> regionToEndpointSupplier;

@Inject
public VersionAwareRegionToEndpoint(@Region Supplier<Map<String, Supplier<URI>>> regionToEndpointSupplier) {
this.regionToEndpointSupplier = checkNotNull(regionToEndpointSupplier, "regionToEndpointSupplier");
}

/**
* A quick fix to ensure Neutron works with endpoint definitions that are not version-agnostic.
* The service-side API will always have a v2.0 in the path.
* However, the endpoint will sometimes contain a v2.0 and sometimes it will not.
* The VersionAwareRegionToEndpoint ensures that the endpoint will always look the same
* before /v2.0 is added to it.
*
* Cannot leave labs until fixed:
* TODO: https://issues.apache.org/jira/browse/JCLOUDS-773
* This code will be unnecessary once this is supported.
*/
@Override
public URI apply(Object from) {
Map<String, Supplier<URI>> regionToEndpoint = regionToEndpointSupplier.get();
checkState(!regionToEndpoint.isEmpty(), "no region name to endpoint mappings configured!");
checkArgument(regionToEndpoint.containsKey(from),
"requested location %s, which is not in the configured locations: %s", from, regionToEndpoint);
String uri = regionToEndpoint.get(from).get().toString();

if (uri.endsWith("/v2.0")) {
return URI.create(uri.substring(0, uri.length() - 5));
}

return regionToEndpoint.get(from).get();
}
}
@@ -66,8 +66,8 @@ public void testCreateFloatingIP() throws IOException, InterruptedException, URI
*/
assertEquals(server.getRequestCount(), 3);
assertAuthentication(server);
assertExtensions(server, "/v2.0");
assertRequest(server.takeRequest(), "POST", "/v2.0/floatingips", "/floatingip_create_request.json");
assertExtensions(server, uriApiVersion + "");
assertRequest(server.takeRequest(), "POST", uriApiVersion + "/floatingips", "/floatingip_create_request.json");

/*
* Check response
@@ -125,8 +125,8 @@ public void testListSpecificPageFloatingIP() throws IOException, InterruptedExce
*/
assertEquals(server.getRequestCount(), 3);
assertAuthentication(server);
assertExtensions(server, "/v2.0");
assertRequest(server.takeRequest(), "GET", "/v2.0/floatingips?limit=2&marker=abcdefg");
assertExtensions(server, uriApiVersion + "");
assertRequest(server.takeRequest(), "GET", uriApiVersion + "/floatingips?limit=2&marker=abcdefg");

/*
* Check response
@@ -157,8 +157,8 @@ public void testListSpecificPageFloatingIPFail() throws IOException, Interrupted
*/
assertEquals(server.getRequestCount(), 3);
assertAuthentication(server);
assertExtensions(server, "/v2.0");
assertRequest(server.takeRequest(), "GET", "/v2.0/floatingips?limit=2&marker=abcdefg");
assertExtensions(server, uriApiVersion + "");
assertRequest(server.takeRequest(), "GET", uriApiVersion + "/floatingips?limit=2&marker=abcdefg");

/*
* Check response
@@ -189,9 +189,9 @@ public void testListPagedFloatingIP() throws IOException, InterruptedException,
*/
assertEquals(server.getRequestCount(), 4);
assertAuthentication(server);
assertExtensions(server, "/v2.0");
assertRequest(server.takeRequest(), "GET", "/v2.0/floatingips");
assertRequest(server.takeRequest(), "GET", "/v2.0/floatingips?marker=71c1e68c-171a-4aa2-aca5-50ea153a3718");
assertExtensions(server, uriApiVersion + "");
assertRequest(server.takeRequest(), "GET", uriApiVersion + "/floatingips");
assertRequest(server.takeRequest(), "GET", uriApiVersion + "/floatingips?marker=71c1e68c-171a-4aa2-aca5-50ea153a3718");

/*
* Check response
@@ -223,8 +223,8 @@ public void testListPagedFloatingIPFail() throws IOException, InterruptedExcepti
*/
assertEquals(server.getRequestCount(), 3);
assertAuthentication(server);
assertExtensions(server, "/v2.0");
assertRequest(server.takeRequest(), "GET", "/v2.0/floatingips");
assertExtensions(server, uriApiVersion + "");
assertRequest(server.takeRequest(), "GET", uriApiVersion + "/floatingips");

/*
* Check response
@@ -254,8 +254,8 @@ public void testGetFloatingIP() throws IOException, InterruptedException, URISyn
*/
assertEquals(server.getRequestCount(), 3);
assertAuthentication(server);
assertExtensions(server, "/v2.0");
assertRequest(server.takeRequest(), "GET", "/v2.0/floatingips/12345");
assertExtensions(server, uriApiVersion + "");
assertRequest(server.takeRequest(), "GET", uriApiVersion + "/floatingips/12345");

/*
* Check response
@@ -292,8 +292,8 @@ public void testGetFloatingIPFail() throws IOException, InterruptedException, UR
*/
assertEquals(server.getRequestCount(), 3);
assertAuthentication(server);
assertExtensions(server, "/v2.0");
assertRequest(server.takeRequest(), "GET", "/v2.0/floatingips/12345");
assertExtensions(server, uriApiVersion + "");
assertRequest(server.takeRequest(), "GET", uriApiVersion + "/floatingips/12345");

/*
* Check response
@@ -327,8 +327,8 @@ public void testUpdateFloatingIP() throws IOException, InterruptedException, URI
*/
assertEquals(server.getRequestCount(), 3);
assertAuthentication(server);
assertExtensions(server, "/v2.0");
assertRequest(server.takeRequest(), "PUT", "/v2.0/floatingips/12345", "/floatingip_update_request.json");
assertExtensions(server, uriApiVersion + "");
assertRequest(server.takeRequest(), "PUT", uriApiVersion + "/floatingips/12345", "/floatingip_update_request.json");

/*
* Check response
@@ -361,8 +361,8 @@ public void testUpdateFloatingIPDissociate() throws IOException, InterruptedExce
*/
assertEquals(server.getRequestCount(), 3);
assertAuthentication(server);
assertExtensions(server, "/v2.0");
assertRequest(server.takeRequest(), "PUT", "/v2.0/floatingips/12345", "/floatingip_update_dissociate_request.json");
assertExtensions(server, uriApiVersion + "");
assertRequest(server.takeRequest(), "PUT", uriApiVersion + "/floatingips/12345", "/floatingip_update_dissociate_request.json");

/*
* Check response
@@ -397,8 +397,8 @@ public void testUpdateFloatingIPFail() throws IOException, InterruptedException,
*/
assertEquals(server.getRequestCount(), 3);
assertAuthentication(server);
assertExtensions(server, "/v2.0");
assertRequest(server.takeRequest(), "PUT", "/v2.0/floatingips/12345", "/floatingip_update_request.json");
assertExtensions(server, uriApiVersion + "");
assertRequest(server.takeRequest(), "PUT", uriApiVersion + "/floatingips/12345", "/floatingip_update_request.json");

/*
* Check response
@@ -427,8 +427,8 @@ public void testDeleteFloatingIP() throws IOException, InterruptedException, URI
*/
assertEquals(server.getRequestCount(), 3);
assertAuthentication(server);
assertExtensions(server, "/v2.0");
assertRequest(server.takeRequest(), "DELETE", "/v2.0/floatingips/12345");
assertExtensions(server, uriApiVersion + "");
assertRequest(server.takeRequest(), "DELETE", uriApiVersion + "/floatingips/12345");

/*
* Check response
@@ -457,8 +457,8 @@ public void testDeleteFloatingIPFail() throws IOException, InterruptedException,
*/
assertEquals(server.getRequestCount(), 3);
assertAuthentication(server);
assertExtensions(server, "/v2.0");
assertRequest(server.takeRequest(), "DELETE", "/v2.0/floatingips/12345");
assertExtensions(server, uriApiVersion + "");
assertRequest(server.takeRequest(), "DELETE", uriApiVersion + "/floatingips/12345");

/*
* Check response

0 comments on commit 3faafe0

Please sign in to comment.