mirror of https://github.com/apache/jclouds.git
Floating IP support
This commit is contained in:
parent
ed7b8895e6
commit
bfe5f45ee2
|
@ -24,6 +24,7 @@ import org.jclouds.javax.annotation.Nullable;
|
|||
import org.jclouds.location.Region;
|
||||
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
|
||||
import org.jclouds.openstack.nova.v1_1.features.FlavorClient;
|
||||
import org.jclouds.openstack.nova.v1_1.features.FloatingIPClient;
|
||||
import org.jclouds.openstack.nova.v1_1.features.ServerAsyncClient;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
import org.jclouds.rest.annotations.EndpointParam;
|
||||
|
@ -62,4 +63,10 @@ public interface NovaAsyncClient {
|
|||
FlavorClient getFlavorClientForRegion(
|
||||
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Floating IP features.
|
||||
*/
|
||||
@Delegate
|
||||
FloatingIPClient getFloatingIPClientForRegion(
|
||||
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.jclouds.javax.annotation.Nullable;
|
|||
import org.jclouds.location.Region;
|
||||
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
|
||||
import org.jclouds.openstack.nova.v1_1.features.FlavorClient;
|
||||
import org.jclouds.openstack.nova.v1_1.features.FloatingIPClient;
|
||||
import org.jclouds.openstack.nova.v1_1.features.ServerClient;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
import org.jclouds.rest.annotations.EndpointParam;
|
||||
|
@ -64,4 +65,10 @@ public interface NovaClient {
|
|||
FlavorClient getFlavorClientForRegion(
|
||||
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Floating IP features.
|
||||
*/
|
||||
@Delegate
|
||||
FloatingIPClient getFloatingIPClientForRegion(
|
||||
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,161 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.nova.v1_1.domain;
|
||||
|
||||
import static com.google.common.base.Objects.toStringHelper;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* A Floating IP is an IP address that can be created and associated with a Server instance.
|
||||
* Floating IPs can also be disassociated and deleted from a Server instance.
|
||||
*
|
||||
* @author Jeremy Daggett
|
||||
* @author chamerling
|
||||
*/
|
||||
public class FloatingIP {
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return builder().fromFloatingIp(this);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private String id;
|
||||
private String ip;
|
||||
private String fixedIp;
|
||||
private String instanceId;
|
||||
|
||||
public Builder id(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder ip(String ip) {
|
||||
this.ip = ip;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder fixedIp(String fixedIp) {
|
||||
this.fixedIp = fixedIp;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder instanceId(String instanceId) {
|
||||
this.instanceId = instanceId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FloatingIP build() {
|
||||
return new FloatingIP(id, ip, fixedIp, instanceId);
|
||||
}
|
||||
|
||||
public Builder fromFloatingIp(FloatingIP in) {
|
||||
return id(in.getId()).ip(in.getIp()).fixedIp(in.getFixedIp())
|
||||
.instanceId(in.getInstanceId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String id;
|
||||
private String ip;
|
||||
@SerializedName("fixed_ip")
|
||||
private String fixedIp;
|
||||
@SerializedName("instance_id")
|
||||
private String instanceId;
|
||||
|
||||
protected FloatingIP(String id, String ip, @Nullable String fixedIp,
|
||||
@Nullable String instanceId) {
|
||||
this.id = id;
|
||||
this.ip = ip;
|
||||
this.fixedIp = fixedIp;
|
||||
this.instanceId = instanceId;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return this.ip;
|
||||
}
|
||||
|
||||
public String getFixedIp() {
|
||||
return this.fixedIp;
|
||||
}
|
||||
|
||||
public String getInstanceId() {
|
||||
return this.fixedIp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((fixedIp == null) ? 0 : fixedIp.hashCode());
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
result = prime * result
|
||||
+ ((instanceId == null) ? 0 : instanceId.hashCode());
|
||||
result = prime * result + ((ip == null) ? 0 : ip.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
FloatingIP other = (FloatingIP) obj;
|
||||
if (fixedIp == null) {
|
||||
if (other.fixedIp != null)
|
||||
return false;
|
||||
} else if (!fixedIp.equals(other.fixedIp))
|
||||
return false;
|
||||
if (id == null) {
|
||||
if (other.id != null)
|
||||
return false;
|
||||
} else if (!id.equals(other.id))
|
||||
return false;
|
||||
if (instanceId == null) {
|
||||
if (other.instanceId != null)
|
||||
return false;
|
||||
} else if (!instanceId.equals(other.instanceId))
|
||||
return false;
|
||||
if (ip == null) {
|
||||
if (other.ip != null)
|
||||
return false;
|
||||
} else if (!ip.equals(other.ip))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toStringHelper("").add("id", id).add("ip", ip)
|
||||
.add("fixedIp", fixedIp).add("instanceId", instanceId).toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.nova.v1_1.features;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.openstack.filters.AuthenticateRequest;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.FloatingIP;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.jclouds.rest.annotations.SkipEncoding;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Floating IPs via the REST API.
|
||||
* <p/>
|
||||
*
|
||||
* @see FloatingIPClient
|
||||
* @author Jeremy Daggett
|
||||
*/
|
||||
@SkipEncoding({ '/', '=' })
|
||||
@RequestFilters(AuthenticateRequest.class)
|
||||
public interface FloatingIPAsyncClient {
|
||||
|
||||
/**
|
||||
* @see FloatingIPClient#listFloatingIPs
|
||||
*/
|
||||
@GET
|
||||
@SelectJson("floating_ips")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Path("/os-floating-ips")
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<FloatingIP>> listFloatingIPs();
|
||||
|
||||
/**
|
||||
* @see FloatingIPClient#getFloatingIP
|
||||
*/
|
||||
@GET
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@Path("/os-floating-ips/{id}")
|
||||
ListenableFuture<FloatingIP> getFloatingIP(@PathParam("id") String id);
|
||||
|
||||
/** SHOULD THIS GO IN ServerAsyncClient???
|
||||
*
|
||||
@POST
|
||||
@Path("/servers/{server}/action")
|
||||
@Consumes
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Payload("%7B\"addFloatingIp\":%7B\"server\":\"{server}\",\"address\":\"{address}\"%7D%7D")
|
||||
ListenableFuture<Void> addFloatingIP(@PayloadParam("server") String server, @PayloadParam("address") String address);
|
||||
|
||||
@POST
|
||||
@Path("/servers/{server}/action")
|
||||
@Consumes
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Payload("%7B\"removeFloatingIp\":%7B\"server\":\"{server}\",\"address\":\"{address}\"%7D%7D")
|
||||
ListenableFuture<Void> removeFloatingIP(@PayloadParam("server") String serverId, @PayloadParam("address") String address);
|
||||
|
||||
*
|
||||
*/
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.nova.v1_1.features;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.FloatingIP;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Flavors via their REST API.
|
||||
* <p/>
|
||||
*
|
||||
* @see FlavorClient
|
||||
* @see <a href="http://docs.openstack.org/api/openstack-compute/1.1/content/Flavors-d1e4180.html"
|
||||
* />
|
||||
* @author Jeremy Daggett
|
||||
*/
|
||||
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
||||
public interface FloatingIPClient {
|
||||
|
||||
/**
|
||||
* List all Floating IP addresses
|
||||
*
|
||||
* @return all Floating IPs
|
||||
*/
|
||||
Set<FloatingIP> listFloatingIPs();
|
||||
|
||||
/**
|
||||
* Get a specific Floating IP address
|
||||
*
|
||||
* @return all Floating IPs
|
||||
*/
|
||||
FloatingIP getFloatingIP(String id);
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"floating_ip" :
|
||||
{
|
||||
"id" : 1,
|
||||
"ip" : "10.0.0.3",
|
||||
"fixed_ip" : "10.0.0.2",
|
||||
"instance_id" : 123
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"floating_ips" : [
|
||||
{
|
||||
"instance_id": 12,
|
||||
"ip" : "10.0.0.3",
|
||||
"fixed_ip": "11.0.0.1",
|
||||
"id" : 1
|
||||
},
|
||||
{
|
||||
"instance_id": null,
|
||||
"ip": "10.0.0.5",
|
||||
"fixed_ip": null,
|
||||
"id": 2
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue