Skip to content
Permalink
Browse files
Adds support for Floating IP
  • Loading branch information
zack-shoylev committed Aug 30, 2014
1 parent 67b9f47 commit e7a52c1aecef2f989f9bde57c1b83e97a81538f9
Showing 26 changed files with 1,385 additions and 53 deletions.
@@ -22,8 +22,10 @@
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.features.NetworkApi;
@@ -80,15 +82,17 @@ public interface NeutronApi extends Closeable {
* to determine if it is present.
*/
@Delegate
Optional<? extends RouterApi> getRouterApi(@EndpointParam(parser = RegionToEndpoint.class) String region);
Optional<RouterApi> getRouterApi(@EndpointParam(parser = RegionToEndpoint.class) String region);

/**
* Provides access to Router features.
* @deprecated Please use {@link #getRouterApi(String)} as this method will be removed in jclouds 3.0.
* Provides access to Floating IP features.
*
* <h3>NOTE</h3>
* This API is an extension that may or may not be present in your OpenStack cloud. Use the Optional return type
* to determine if it is present.
*/
@Deprecated
@Delegate
Optional<? extends RouterApi> getRouterExtensionApi(@EndpointParam(parser = RegionToEndpoint.class) String region);
Optional<FloatingIPApi> getFloatingIPApi(@EndpointParam(parser = RegionToEndpoint.class) String region);

/**
* Provides access to SecurityGroup features.
@@ -0,0 +1,316 @@
/*
* 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.domain;

import java.beans.ConstructorProperties;
import javax.inject.Named;

import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;

/**
* A Neutron Floating IP
*
*/
public class FloatingIP {

private String id;
@Named("router_id")
private String routerId;
@Named("tenant_id")
private String tenantId;
// Only mandatory attribute when creating
@Named("floating_network_id")
private String floatingNetworkId;
@Named("fixed_ip_address")
private String fixedIpAddress;
@Named("floating_ip_address")
private String floatingIpAddress;
@Named("port_id")
private String portId;

/**
* Deserialization constructor
*/
@ConstructorProperties({"id", "router_id", "tenant_id", "floating_network_id", "fixed_ip_address",
"floating_ip_address", "port_id"})
private FloatingIP(String id, String routerId, String tenantId, String floatingNetworkId, String fixedIpAddress,
String floatingIpAddress, String portId) {
this.id = id;
this.routerId = routerId;
this.tenantId = tenantId;
this.floatingNetworkId = floatingNetworkId;
this.fixedIpAddress = fixedIpAddress;
this.floatingIpAddress = floatingIpAddress;
this.portId = portId;
}

private FloatingIP() {}

/**
* @param floatingIP The floating IP to copy from
*/
private FloatingIP(FloatingIP floatingIP) {
this(floatingIP.id, floatingIP.routerId, floatingIP.tenantId, floatingIP.floatingNetworkId,
floatingIP.fixedIpAddress, floatingIP.floatingIpAddress, floatingIP.portId);
}

/**
* @return the id of the floating IP
*/
@Nullable
public String getId() {
return id;
}

/**
* @return the router id of this floating IP
*/
@Nullable
public String getRouterId() {
return routerId;
}

/**
* @return the tenant id of the Floating IP
*/
@Nullable
public String getTenantId() {
return tenantId;
}

/**
* @return the floating network id for this floating IP
*/
@Nullable
public String getFloatingNetworkId() {
return floatingNetworkId;
}

/**
* @return the fixed IP address for this floating IP
*/
@Nullable
public String getFixedIpAddress() {
return fixedIpAddress;
}

/**
* @return the floating IP address for this floating IP
*/
@Nullable
public String getFloatingIpAddress() {
return floatingIpAddress;
}

/**
* @return the port id for this floating IP
*/
@Nullable
public String getPortId() {
return portId;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;

FloatingIP that = (FloatingIP) o;

return Objects.equal(this.id, that.id) &&
Objects.equal(this.routerId, that.routerId) &&
Objects.equal(this.tenantId, that.tenantId) &&
Objects.equal(this.floatingNetworkId, that.floatingNetworkId) &&
Objects.equal(this.fixedIpAddress, that.fixedIpAddress) &&
Objects.equal(this.floatingIpAddress, that.floatingIpAddress) &&
Objects.equal(this.portId, that.portId);
}

@Override
public int hashCode() {
return Objects.hashCode(id, routerId, tenantId, floatingNetworkId, fixedIpAddress, floatingIpAddress,
portId);
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("id", id)
.add("routerId", routerId)
.add("tenantId", tenantId)
.add("floatingNetworkId", floatingNetworkId)
.add("fixedIpAddress", fixedIpAddress)
.add("floatingIpAddress", floatingIpAddress)
.add("portId", portId)
.toString();
}

/**
* @return the Builder for creating a new floating IP
*/
public static CreateBuilder createOptions(String floatingNetworkId) {
return new CreateBuilder(floatingNetworkId);
}

/**
* @return the Builder for updating a floating IP
*/
public static UpdateBuilder updateOptions() {
return new UpdateBuilder();
}

private abstract static class Builder<ParameterizedBuilderType> {
protected FloatingIP floatingIP;

/**
* No-parameters constructor.
* */
private Builder() {
floatingIP = new FloatingIP();
}

protected abstract ParameterizedBuilderType self();

/**
* Provide the tenantId for this Floating IP. Admin-only.
* When keystone is enabled, it is not mandatory to specify tenant_id for resources in create requests, as the
* tenant identifier will be derived from the Authentication token. Please note that the default authorization
* settings only allow administrative users to create resources on behalf of a different tenant.
*
* @return the Builder.
* @see FloatingIP#getTenantId()
*/
public ParameterizedBuilderType tenantId(String tenantId) {
floatingIP.tenantId = tenantId;
return self();
}

/**
* Provides the floating network id for this Floating IP.
* Mandatory when creating a floating IP.
* Floating IPs can only be created on external networks. If the network specified by floating_network_id is not
* external (for example, router:external=false), a 400 error is returned.
*
* @return the Builder.
* @see FloatingIP#getFloatingNetworkId() ()
*/
public ParameterizedBuilderType floatingNetworkId(String floatingNetworkId) {
floatingIP.floatingNetworkId = floatingNetworkId;
return self();
}

/**
* Provides the fixed ip address for this Floating IP.
* As an OpenStack Networking port might be associated with multiple IP addresses, the particular IP address to
* associate with the floating IP can be specified using the fixed_ip_address request body parameter. The default
* logic of this operation is to associate the floating IP with a single IP address configured on a port; hence,
* if a port has multiple IP addresses, it is mandatory to specify the fixed_ip_address attribute. If an invalid
* IP address is specified in fixed_ip_address a 400 error will be returned.
*
* @return the Builder.
* @see FloatingIP#getFixedIpAddress()
*/
public ParameterizedBuilderType fixedIpAddress(String fixedIpAddress) {
floatingIP.fixedIpAddress = fixedIpAddress;
return self();
}

/**
* Provides the port id for this Floating IP.
* Users can associate the floating IP with an internal port using the port_id attribute in the request body.
* If an invalid port identifier is specified, a 404 error will be returned. The internal OpenStack Networking
* port associated with the Floating IP must have at least an IP address configured, otherwise a 400 error will
* be returned.
*
* @return the Builder.
* @see FloatingIP#getPortId()
*/
public ParameterizedBuilderType portId(String portId) {
floatingIP.portId = portId;
return self();
}
}

public static class CreateBuilder extends Builder<CreateBuilder> {
/**
* Supply required properties for creating a Builder
*/
private CreateBuilder(String floatingNetworkId) {
floatingIP.floatingNetworkId = floatingNetworkId;
}

/**
* @return a CreateOptions constructed with this Builder.
*/
public CreateOptions build() {
return new CreateOptions(floatingIP);
}

protected CreateBuilder self() {
return this;
}
}

public static class UpdateBuilder extends Builder<UpdateBuilder> {
/**
* Supply required properties for updating a Builder
*/
private UpdateBuilder() {
}

/**
* Provide the floating ip address for this Floating IP.
* An address for the floating ip will be automatically allocated, unless the floating_ip_address attribute is
* specified in the request body. If the requested floating IP address does not fall in the external network's
* subnet range, a 400 error will be returned. If the requested floating IP address is already in use, a 409
* error code will be returned.
*
* @return the Builder.
* @see FloatingIP#getFloatingIpAddress()
*/
public UpdateBuilder floatingIpAddress(String floatingIpAddress) {
floatingIP.floatingIpAddress = floatingIpAddress;
return this;
}

/**
* @return a UpdateOptions constructed with this Builder.
*/
public UpdateOptions build() {
return new UpdateOptions(floatingIP);
}

protected UpdateBuilder self() {
return this;
}
}

public static class CreateOptions extends FloatingIP {
private CreateOptions(FloatingIP floatingIP) {
super(floatingIP);
}
}
public static class UpdateOptions extends FloatingIP {
private UpdateOptions(FloatingIP floatingIP) {
super(floatingIP);
}
}
}
@@ -0,0 +1,36 @@
/*
* 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.domain;

import java.beans.ConstructorProperties;

import org.jclouds.openstack.v2_0.domain.Link;
import org.jclouds.openstack.v2_0.domain.PaginatedCollection;

import com.google.common.collect.ImmutableSet;

/**
* A collection of Floating IPs
*/
public class FloatingIPs extends PaginatedCollection<FloatingIP> {
public static final FloatingIPs EMPTY = new FloatingIPs(ImmutableSet.<FloatingIP> of(), ImmutableSet.<Link> of());

@ConstructorProperties({"floatingips", "floatingips_links"})
protected FloatingIPs(Iterable<FloatingIP> floatingIPs, Iterable<Link> floatingIPsLinks) {
super(floatingIPs, floatingIPsLinks);
}
}

0 comments on commit e7a52c1

Please sign in to comment.