Neutron Refactoring v2_0 -> v2 No options (redesign) More features (extension-related) Live tests Redesigned domain objects for create/update options.
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/commit/9c4bd944 Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/tree/9c4bd944 Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/diff/9c4bd944 Branch: refs/heads/master Commit: 9c4bd94485730d0037a79b3c697f0819efa388f8 Parents: 1f4a3c0 Author: Zack Shoylev <[email protected]> Authored: Mon Apr 14 18:48:42 2014 -0500 Committer: Zack Shoylev <[email protected]> Committed: Fri Jul 25 16:12:53 2014 -0500 ---------------------------------------------------------------------- openstack-neutron/pom.xml | 5 + .../openstack/neutron/v2/NeutronApi.java | 81 ++ .../neutron/v2/NeutronApiMetadata.java | 101 +++ .../neutron/v2/config/NeutronHttpApiModule.java | 84 ++ .../neutron/v2/domain/AddressPair.java | 182 +++++ .../neutron/v2/domain/AllocationPool.java | 133 ++++ .../neutron/v2/domain/ExternalGatewayInfo.java | 128 ++++ .../neutron/v2/domain/ExtraDhcpOption.java | 161 ++++ .../openstack/neutron/v2/domain/HostRoute.java | 118 +++ .../jclouds/openstack/neutron/v2/domain/IP.java | 132 ++++ .../neutron/v2/domain/IPv6DHCPMode.java | 57 ++ .../openstack/neutron/v2/domain/Network.java | 647 ++++++++++++++++ .../neutron/v2/domain/NetworkSegment.java | 163 ++++ .../neutron/v2/domain/NetworkStatus.java | 57 ++ .../neutron/v2/domain/NetworkType.java | 69 ++ .../openstack/neutron/v2/domain/Networks.java | 35 + .../openstack/neutron/v2/domain/Port.java | 765 +++++++++++++++++++ .../openstack/neutron/v2/domain/Ports.java | 35 + .../openstack/neutron/v2/domain/Router.java | 285 +++++++ .../neutron/v2/domain/RouterInterface.java | 136 ++++ .../openstack/neutron/v2/domain/Routers.java | 35 + .../openstack/neutron/v2/domain/Subnet.java | 467 +++++++++++ .../openstack/neutron/v2/domain/Subnets.java | 35 + .../openstack/neutron/v2/domain/VIFType.java | 62 ++ .../openstack/neutron/v2/domain/VNICType.java | 56 ++ .../neutron/v2/extensions/RouterApi.java | 197 +++++ .../v2/fallbacks/EmptyNetworksFallback.java | 45 ++ .../v2/fallbacks/EmptyPortsFallback.java | 45 ++ .../v2/fallbacks/EmptyRoutersFallback.java | 45 ++ .../v2/fallbacks/EmptySubnetsFallback.java | 45 ++ .../neutron/v2/features/NetworkApi.java | 152 ++++ .../openstack/neutron/v2/features/PortApi.java | 150 ++++ .../neutron/v2/features/SubnetApi.java | 146 ++++ .../v2/functions/NetworksToPagedIterable.java | 64 ++ .../neutron/v2/functions/ParseNetworks.java | 38 + .../neutron/v2/functions/ParsePorts.java | 37 + .../neutron/v2/functions/ParseRouters.java | 37 + .../neutron/v2/functions/ParseSubnets.java | 37 + .../v2/functions/PortsToPagedIterable.java | 64 ++ .../v2/functions/RouterToPagedIterable.java | 66 ++ .../v2/functions/SubnetsToPagedIterable.java | 64 ++ .../v2/handlers/NeutronErrorHandler.java | 62 ++ .../neutron/v2/options/EmptyOptions.java | 47 ++ .../openstack/neutron/v2_0/NeutronApi.java | 2 + .../neutron/v2_0/NeutronApiMetadata.java | 3 +- .../v2_0/config/NeutronHttpApiModule.java | 30 +- .../neutron/v2_0/extensions/RouterApi.java | 2 + .../neutron/v2_0/features/NetworkApi.java | 2 + .../neutron/v2_0/features/PortApi.java | 2 + .../neutron/v2_0/features/SubnetApi.java | 2 + .../services/org.jclouds.apis.ApiMetadata | 1 + .../neutron/v2/NeutronApiMetadataTest.java | 35 + .../neutron/v2/features/NetworkApiLiveTest.java | 100 +++ .../neutron/v2/features/NetworkApiMockTest.java | 464 +++++++++++ .../neutron/v2/features/PortApiLiveTest.java | 149 ++++ .../neutron/v2/features/PortApiMockTest.java | 492 ++++++++++++ .../neutron/v2/features/RouterApiLiveTest.java | 171 +++++ .../neutron/v2/features/RouterApiMockTest.java | 631 +++++++++++++++ .../neutron/v2/features/SubnetApiLiveTest.java | 118 +++ .../neutron/v2/features/SubnetApiMockTest.java | 472 ++++++++++++ .../v2/internal/BaseNeutronApiLiveTest.java | 46 ++ .../v2/internal/BaseNeutronApiMockTest.java | 41 + .../openstack/neutron/v2/util/ClassUtil.java | 39 + .../neutron/v2/util/PredicateUtil.java | 47 ++ .../v2_0/internal/BaseNeutronApiLiveTest.java | 2 +- .../v2_0/internal/BaseNeutronExpectTest.java | 2 +- .../src/test/resources/access.json | 228 ++++++ .../src/test/resources/list_networks.json | 124 +-- .../src/test/resources/list_ports.json | 172 ++--- .../src/test/resources/list_routers.json | 100 +-- .../src/test/resources/list_subnets.json | 196 ++--- .../src/test/resources/network.json | 14 +- .../resources/network_bulk_create_request.json | 12 + .../resources/network_bulk_create_response.json | 18 + .../test/resources/network_create_request.json | 4 + .../test/resources/network_create_response.json | 7 + .../test/resources/network_get_response.json | 7 + .../test/resources/network_list_response.json | 62 ++ .../resources/network_list_response_paged1.json | 40 + .../resources/network_list_response_paged2.json | 36 + .../test/resources/network_update_request.json | 4 + .../test/resources/network_update_response.json | 11 + openstack-neutron/src/test/resources/port.json | 14 +- .../resources/port_create_bulk_request.json | 22 + .../resources/port_create_bulk_response.json | 47 ++ .../src/test/resources/port_create_request.json | 14 + .../test/resources/port_create_response.json | 29 + .../src/test/resources/port_get_response.json | 10 + .../src/test/resources/port_list_response.json | 86 +++ .../resources/port_list_response_paged1.json | 48 ++ .../resources/port_list_response_paged2.json | 44 ++ .../src/test/resources/port_update_request.json | 8 + .../test/resources/port_update_response.json | 23 + .../src/test/resources/router.json | 16 +- .../router_add_interface_port_request.json | 3 + .../resources/router_add_interface_request.json | 3 + .../router_add_interface_response.json | 4 + .../test/resources/router_create_request.json | 9 + .../test/resources/router_create_response.json | 12 + .../src/test/resources/router_get_response.json | 12 + .../test/resources/router_list_response.json | 74 ++ .../resources/router_list_response_paged1.json | 34 + .../resources/router_list_response_paged2.json | 30 + .../router_remove_interface_port_request.json | 3 + .../router_remove_interface_subnet_request.json | 3 + .../test/resources/router_update_request.json | 7 + .../test/resources/router_update_response.json | 12 + .../src/test/resources/subnet.json | 16 +- .../resources/subnet_bulk_create_request.json | 14 + .../resources/subnet_bulk_create_response.json | 48 ++ .../test/resources/subnet_create_request.json | 6 + .../test/resources/subnet_create_response.json | 8 + .../src/test/resources/subnet_get_response.json | 9 + .../test/resources/subnet_list_response.json | 98 +++ .../resources/subnet_list_response_pages1.json | 30 + .../resources/subnet_list_response_pages2.json | 26 + .../test/resources/subnet_update_request.json | 6 + .../test/resources/subnet_update_response.json | 18 + 118 files changed, 9762 insertions(+), 342 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/9c4bd944/openstack-neutron/pom.xml ---------------------------------------------------------------------- diff --git a/openstack-neutron/pom.xml b/openstack-neutron/pom.xml index bb62eba..20d0d47 100644 --- a/openstack-neutron/pom.xml +++ b/openstack-neutron/pom.xml @@ -100,6 +100,11 @@ <artifactId>logback-classic</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>com.squareup.okhttp</groupId> + <artifactId>mockwebserver</artifactId> + <scope>test</scope> + </dependency> </dependencies> <profiles> http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/9c4bd944/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/NeutronApi.java ---------------------------------------------------------------------- diff --git a/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/NeutronApi.java b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/NeutronApi.java new file mode 100644 index 0000000..1f78ba9 --- /dev/null +++ b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/NeutronApi.java @@ -0,0 +1,81 @@ +/** + * 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.neutron.v2; + +import com.google.common.base.Optional; +import com.google.inject.Provides; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.location.Zone; +import org.jclouds.location.functions.ZoneToEndpoint; +import org.jclouds.openstack.neutron.v2.extensions.RouterApi; +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.v2_0.features.ExtensionApi; +import org.jclouds.rest.annotations.Delegate; +import org.jclouds.rest.annotations.EndpointParam; + +import java.io.Closeable; +import java.util.Set; + +/** + * Provides synchronous access to Neutron. + * <p/> + * + * @see <a href="http://docs.openstack.org/api/openstack-network/2.0/content/">api doc</a> + */ +public interface NeutronApi extends Closeable { + /** + * @return the Zone codes configured + */ + @Provides + @Zone + Set<String> getConfiguredRegions(); + + /** + * Provides synchronous access to Extension features. + */ + @Delegate + ExtensionApi getExtensionApiForZone( + @EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone); + + /** + * Provides synchronous access to Network features. + */ + @Delegate + NetworkApi getNetworkApiForZone(@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone); + + /** + * Provides synchronous access to Subnet features + */ + @Delegate + SubnetApi getSubnetApiForZone(@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone); + + /** + * Provides synchronous access to Port features. + */ + @Delegate + PortApi getPortApiForZone(@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone); + + /** + * Provides synchronous access to Router features. + */ + @Delegate + Optional<? extends RouterApi> getRouterExtensionForZone(@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone); +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/9c4bd944/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/NeutronApiMetadata.java ---------------------------------------------------------------------- diff --git a/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/NeutronApiMetadata.java b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/NeutronApiMetadata.java new file mode 100644 index 0000000..9e6aa94 --- /dev/null +++ b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/NeutronApiMetadata.java @@ -0,0 +1,101 @@ +/** + * 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.neutron.v2; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; +import org.jclouds.apis.ApiMetadata; +import org.jclouds.openstack.keystone.v2_0.config.AuthenticationApiModule; +import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes; +import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule; +import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.ZoneModule; +import org.jclouds.openstack.neutron.v2.config.NeutronHttpApiModule; +import org.jclouds.openstack.v2_0.ServiceType; +import org.jclouds.rest.internal.BaseHttpApiMetadata; + +import java.net.URI; +import java.util.Properties; + +import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE; +import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.SERVICE_TYPE; + +/** + * Implementation of {@link org.jclouds.apis.ApiMetadata} for Neutron 2.0 API + * + */ +public class NeutronApiMetadata extends BaseHttpApiMetadata<NeutronApi> { + + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); + } + + public NeutronApiMetadata() { + this(new Builder()); + } + + protected NeutronApiMetadata(Builder builder) { + super(builder); + } + + public static Properties defaultProperties() { + Properties properties = BaseHttpApiMetadata.defaultProperties(); + properties.setProperty(SERVICE_TYPE, ServiceType.NETWORK); + properties.setProperty(CREDENTIAL_TYPE, CredentialTypes.PASSWORD_CREDENTIALS); + return properties; + } + + public static class Builder extends BaseHttpApiMetadata.Builder<NeutronApi, Builder> { + + protected Builder() { + super(NeutronApi.class); + id("openstack-neutron") + .name("OpenStack Neutron API") + .identityName("${tenantName}:${userName} or ${userName}, if your keystone supports a default tenant") + .credentialName("${password}") + .endpointName("Neutron base url ending in /v2.0/") + .documentation(URI.create("http://docs.openstack.org/api/openstack-network/2.0/content/")) + .version("2.0") + .defaultEndpoint("http://localhost:5000/v2.0/") + .defaultProperties(NeutronApiMetadata.defaultProperties()) + .defaultModules(ImmutableSet.<Class<? extends Module>>builder() + .add(AuthenticationApiModule.class) + .add(KeystoneAuthenticationModule.class) + .add(ZoneModule.class) + .add(NeutronHttpApiModule.class).build()); + } + + @Override + public NeutronApiMetadata build() { + return new NeutronApiMetadata(this); + } + + @Override + public Builder fromApiMetadata(ApiMetadata in) { + super.fromApiMetadata(in); + return this; + } + + @Override + protected Builder self() { + return this; + } + } + +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/9c4bd944/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/config/NeutronHttpApiModule.java ---------------------------------------------------------------------- diff --git a/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/config/NeutronHttpApiModule.java b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/config/NeutronHttpApiModule.java new file mode 100644 index 0000000..9274813 --- /dev/null +++ b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/config/NeutronHttpApiModule.java @@ -0,0 +1,84 @@ +/* + * 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.config; + +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.Multimap; +import com.google.inject.Provides; +import org.jclouds.http.HttpErrorHandler; +import org.jclouds.http.annotation.ClientError; +import org.jclouds.http.annotation.Redirection; +import org.jclouds.http.annotation.ServerError; +import org.jclouds.json.config.GsonModule.DateAdapter; +import org.jclouds.json.config.GsonModule.Iso8601DateAdapter; +import org.jclouds.openstack.neutron.v2.NeutronApi; +import org.jclouds.openstack.neutron.v2.handlers.NeutronErrorHandler; +import org.jclouds.openstack.v2_0.domain.Extension; +import org.jclouds.openstack.v2_0.functions.PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet; +import org.jclouds.rest.ConfiguresHttpApi; +import org.jclouds.rest.config.HttpApiModule; +import org.jclouds.rest.functions.ImplicitOptionalConverter; + +import javax.inject.Provider; +import javax.inject.Singleton; +import java.net.URI; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +/** + * Configures the Neutron connection. + * + */ +@ConfiguresHttpApi +public class NeutronHttpApiModule extends HttpApiModule<NeutronApi> { + + @Override + protected void configure() { + bind(DateAdapter.class).to(Iso8601DateAdapter.class); + bind(ImplicitOptionalConverter.class).to(PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet.class); + super.configure(); + } + + @Provides + @Singleton + public Multimap<URI, URI> aliases() { + return ImmutableMultimap.<URI, URI>builder() + .build(); + } + + @Provides + @Singleton + public LoadingCache<String, Set<? extends Extension>> provideExtensionsByZone(final Provider<NeutronApi> quantumApi) { + return CacheBuilder.newBuilder().expireAfterWrite(23, TimeUnit.HOURS) + .build(new CacheLoader<String, Set<? extends Extension>>() { + @Override + public Set<? extends Extension> load(String key) throws Exception { + return quantumApi.get().getExtensionApiForZone(key).list(); + } + }); + } + + @Override + protected void bindErrorHandlers() { + bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(NeutronErrorHandler.class); + bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(NeutronErrorHandler.class); + bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(NeutronErrorHandler.class); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/9c4bd944/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/AddressPair.java ---------------------------------------------------------------------- diff --git a/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/AddressPair.java b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/AddressPair.java new file mode 100644 index 0000000..4e222af --- /dev/null +++ b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/AddressPair.java @@ -0,0 +1,182 @@ +/* + * 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.neutron.v2.domain; + +import com.google.common.base.Objects; + +import javax.inject.Named; +import java.beans.ConstructorProperties; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Contains a mapping between a MAC address and an IP address. + */ +public class AddressPair { + + @Named("mac_address") + private String macAddress; + @Named("ip_address") + private String ipAddress; + + @ConstructorProperties({"mac_address", "ip_address"}) + protected AddressPair(String macAddress, String ipAddress) { + checkNotNull(macAddress, "mac address should not be null"); + checkNotNull(ipAddress, "ip should not be null"); + this.macAddress = macAddress; + this.ipAddress = ipAddress; + } + + /** + * Copy constructor + * @param addressPair + */ + private AddressPair(AddressPair addressPair) { + this(addressPair.getMacAddress(), addressPair.getIpAddress()); + } + + /** + * Default constructor + */ + private AddressPair() {} + + /** + * @return the macAddress of the AddressPair + */ + public String getMacAddress() { + return macAddress; + } + + /** + * @return the ipAddress of the AddressPair + */ + public String getIpAddress() { + return ipAddress; + } + + @Override + public int hashCode() { + return Objects.hashCode(macAddress, ipAddress); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + AddressPair that = AddressPair.class.cast(obj); + return Objects.equal(this.macAddress, that.macAddress) && Objects.equal(this.ipAddress, that.ipAddress); + } + + protected Objects.ToStringHelper string() { + return Objects.toStringHelper(this).add("macAddress", macAddress).add("ipAddress", ipAddress); + } + + @Override + public String toString() { + return string().toString(); + } + + /** + * Returns a builder, but requires the user to specify any parameters required when creating a resource. + * In this case, both parameters are required. + * @return the Builder for AddressPair + */ + public static Builder createOptions(String macAddress, String ipAddress) { + return new Builder(macAddress, ipAddress); + } + + /** + * Returns a builder, but requires the user to specify any parameters required when updating a resource. + * In this case, there are none. + * @return the Builder for AddressPair + */ + public static Builder updateOptions() { + return new Builder(); + } + + /** + * Gets a Builder configured as this object. + */ + public Builder toBuilder() { + return new Builder().fromAddressPair(this); + } + + public static class Builder { + // Keep track of the builder's state. + private AddressPair addressPair; + + /** + * No-parameters constructor used when updating. + * */ + private Builder() { + addressPair = new AddressPair(); + } + + /** + * Required parameters constructor used when creating. + * @param macAddress + * @param ipAddress + */ + private Builder(String macAddress, String ipAddress) { + addressPair = new AddressPair(); + addressPair.macAddress = macAddress; + addressPair.ipAddress = ipAddress; + } + + /** + * Provide the macAddress to the AddressPair's Builder. + * + * @return the Builder. + * @see AddressPair#getMacAddress() + */ + public Builder macAddress(String macAddress) { + addressPair.macAddress = macAddress; + return this; + } + + /** + * Provide the ipAddress to the AddressPair's Builder. + * + * @return the Builder. + * @see AddressPair#getIpAddress() + */ + public Builder ipAddress(String ipAddress) { + addressPair.ipAddress = ipAddress; + return this; + } + + /** + * @return a AddressPair constructed with this Builder. + */ + public AddressPair build() { + // Use the copy constructor to copy the builder's state (config) object and pass back to the user. + // Immutability is preserved, and fields are defined only once. + return new AddressPair(addressPair); + } + + /** + * @return a Builder from another AddressPair. + */ + public Builder fromAddressPair(AddressPair in) { + return this.macAddress(in.getMacAddress()).ipAddress(in.getIpAddress()); + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/9c4bd944/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/AllocationPool.java ---------------------------------------------------------------------- diff --git a/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/AllocationPool.java b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/AllocationPool.java new file mode 100644 index 0000000..6df93cd --- /dev/null +++ b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/AllocationPool.java @@ -0,0 +1,133 @@ +/* + * 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.neutron.v2.domain; + +import com.google.common.base.Objects; + +/** + * A Neutron Subnet Allocation Pool + * Contains a start and an end IP address describing the pool. + * + * @see <a + * href="http://docs.openstack.org/api/openstack-network/2.0/content/Subnets.html">api + * doc</a> + */ +public class AllocationPool { + + protected final String start; + protected final String end; + + protected AllocationPool(String start, String end) { + this.start = start; + this.end = end; + } + + /** + * @return the start of the AllocationPool + */ + public String getStart() { + return start; + } + + /** + * @return the end of the AllocationPool + */ + public String getEnd() { + return end; + } + + @Override + public int hashCode() { + return Objects.hashCode(start, end); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + AllocationPool that = AllocationPool.class.cast(obj); + return Objects.equal(this.start, that.start) && Objects.equal(this.end, that.end); + } + + protected Objects.ToStringHelper string() { + return Objects.toStringHelper(this).add("start", start).add("end", end); + } + + @Override + public String toString() { + return string().toString(); + } + + /** + * @return the Builder for AllocationPool + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Gets a Builder configured as this object. + */ + public Builder toBuilder() { + return new Builder().fromAllocationPool(this); + } + + public static class Builder { + protected String start; + protected String end; + + /** + * Provide the start to the AllocationPool's Builder. + * + * @return the Builder. + * @see AllocationPool#getStart() + */ + public Builder start(String start) { + this.start = start; + return this; + } + + /** + * Provide the end to the AllocationPool's Builder. + * + * @return the Builder. + * @see AllocationPool#getEnd() + */ + public Builder end(String end) { + this.end = end; + return this; + } + + /** + * @return a AllocationPool constructed with this Builder. + */ + public AllocationPool build() { + return new AllocationPool(start, end); + } + + /** + * @return a Builder from another AllocationPool. + */ + public Builder fromAllocationPool(AllocationPool in) { + return this.start(in.getStart()).end(in.getEnd()); + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/9c4bd944/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/ExternalGatewayInfo.java ---------------------------------------------------------------------- diff --git a/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/ExternalGatewayInfo.java b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/ExternalGatewayInfo.java new file mode 100644 index 0000000..d66bc04 --- /dev/null +++ b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/ExternalGatewayInfo.java @@ -0,0 +1,128 @@ +/** + * 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.neutron.v2.domain; + +import com.google.common.base.Objects; + +import javax.inject.Named; + +/** + * Information on the external gateway for the router + */ +public class ExternalGatewayInfo { + + @Named("network_id") + protected final String networkId; + @Named("enable_snat") + protected final Boolean enableSnat; + + protected ExternalGatewayInfo(String networkId, Boolean enableSnat) { + this.networkId = networkId; + this.enableSnat = enableSnat; + } + + /** + * @return the networkId of the ExternalGatewayInfo + */ + public String getNetworkId() { + return networkId; + } + + /** + * @return the enableSnat status of the ExternalGatewayInfo + */ + public Boolean getEnableSnat() { + return enableSnat; + } + + @Override + public int hashCode() { + return Objects.hashCode(networkId, enableSnat); + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + ExternalGatewayInfo that = (ExternalGatewayInfo) o; + + return Objects.equal(this.networkId, that.networkId) && + Objects.equal(this.enableSnat, that.enableSnat); + } + + /** + * @return the Builder for ExternalGatewayInfo + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Gets a Builder configured as this object. + */ + public Builder toBuilder() { + return new Builder().fromExternalGatewayInfo(this); + } + + @Override + public String toString() { + return Objects.toStringHelper(this) + .add("networkId", networkId) + .add("enableSnat", enableSnat) + .toString(); + } + + public static class Builder { + protected String networkId; + protected Boolean enableSnat; + + /** + * Provide the networkId to the ExternalGatewayInfo's Builder. + * + * @return the Builder. + * @see ExternalGatewayInfo#getNetworkId() + */ + public Builder networkId(String networkId) { + this.networkId = networkId; + return this; + } + + public Builder enableSnat(boolean enableSnat) { + this.enableSnat = enableSnat; + return this; + } + + /** + * @return a ExternalGatewayInfo constructed with this Builder. + */ + public ExternalGatewayInfo build() { + return new ExternalGatewayInfo(networkId, enableSnat); + } + + /** + * @return a Builder from another ExternalGatewayInfo. + */ + public Builder fromExternalGatewayInfo(ExternalGatewayInfo in) { + return this.networkId(in.getNetworkId()).enableSnat(in.getEnableSnat()); + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/9c4bd944/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/ExtraDhcpOption.java ---------------------------------------------------------------------- diff --git a/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/ExtraDhcpOption.java b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/ExtraDhcpOption.java new file mode 100644 index 0000000..6b7dfd8 --- /dev/null +++ b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/ExtraDhcpOption.java @@ -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.neutron.v2.domain; + +import com.google.common.base.Objects; + +import javax.inject.Named; + +/** + * This is used to provide additional DHCP-related options to Subnet. This is + * based on a neutron extension. + * For example PXE boot options to DHCP clients can be specified (e.g. tftp-server, + * server-ip-address, bootfile-name) + * + * @see <a + * href="http://docs.openstack.org/api/openstack-network/2.0/content/Subnets.html">api + * doc</a> + */ +public class ExtraDhcpOption { + + protected final String id; + @Named("opt_name") + protected final String optionName; + @Named("opt_value") + protected final String optionValue; + + protected ExtraDhcpOption(String id, String optionName, String optionValue) { + this.id = id; + this.optionName = optionName; + this.optionValue = optionValue; + } + + /** + * @return the id of the ExtraDhcpOption + */ + public String getId() { + return id; + } + + /** + * @return the optionName of the ExtraDhcpOption + */ + public String getOptionName() { + return optionName; + } + + /** + * @return the optionValue of the ExtraDhcpOption + */ + public String getOptionValue() { + return optionValue; + } + + @Override + public int hashCode() { + return Objects.hashCode(id, optionName, optionValue); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + ExtraDhcpOption that = ExtraDhcpOption.class.cast(obj); + return Objects.equal(this.id, that.id) && Objects.equal(this.optionName, that.optionName) + && Objects.equal(this.optionValue, that.optionValue); + } + + protected Objects.ToStringHelper string() { + return Objects.toStringHelper(this).add("id", id).add("optionName", optionName).add("optionValue", optionValue); + } + + @Override + public String toString() { + return string().toString(); + } + + /** + * @return the Builder for ExtraDhcpOption + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Gets a Builder configured as this object. + */ + public Builder toBuilder() { + return new Builder().fromExtraDhcpOption(this); + } + + public static class Builder { + protected String id; + protected String optionName; + protected String optionValue; + + /** + * Provide the id to the ExtraDhcpOption's Builder. + * + * @return the Builder. + * @see ExtraDhcpOption#getId() + */ + public Builder id(String id) { + this.id = id; + return this; + } + + /** + * Provide the optionName to the ExtraDhcpOption's Builder. + * + * @return the Builder. + * @see ExtraDhcpOption#getOptionName() + */ + public Builder optionName(String optionName) { + this.optionName = optionName; + return this; + } + + /** + * Provide the optionValue to the ExtraDhcpOption's Builder. + * + * @return the Builder. + * @see ExtraDhcpOption#getOptionValue() + */ + public Builder optionValue(String optionValue) { + this.optionValue = optionValue; + return this; + } + + /** + * @return a ExtraDhcpOption constructed with this Builder. + */ + public ExtraDhcpOption build() { + return new ExtraDhcpOption(id, optionName, optionValue); + } + + /** + * @return a Builder from another ExtraDhcpOption. + */ + public Builder fromExtraDhcpOption(ExtraDhcpOption in) { + return this.id(in.getId()).optionName(in.getOptionName()).optionValue(in.getOptionValue()); + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/9c4bd944/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/HostRoute.java ---------------------------------------------------------------------- diff --git a/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/HostRoute.java b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/HostRoute.java new file mode 100644 index 0000000..04c3bda --- /dev/null +++ b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/HostRoute.java @@ -0,0 +1,118 @@ +/* + * 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.neutron.v2.domain; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; + +import javax.inject.Named; + +/** + * A Neutron Subnet Host Route + * + * @see <a href="http://docs.openstack.org/api/openstack-network/2.0/content/Subnets.html">api doc</a> + */ +public class HostRoute { + + @Named("destination") + private final String destinationCidr; + @Named("nexthop") + private final String nextHop; + + protected HostRoute(String destinationCidr, String nextHop) { + this.destinationCidr = destinationCidr; + this.nextHop = nextHop; + } + + /** + * @return the destination CIDR for this route. + */ + public String getDestinationCidr() { + return destinationCidr; + } + + /** + * @return the IP of the next hop to forward traffic to. + */ + public String getNextHop() { + return nextHop; + } + + @Override + public int hashCode() { + return Objects.hashCode(destinationCidr, nextHop); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + HostRoute that = HostRoute.class.cast(obj); + return Objects.equal(this.destinationCidr, that.destinationCidr) && Objects.equal(this.nextHop, that.nextHop); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("destinationCidr", destinationCidr).add("nextHop", nextHop); + } + + @Override + public String toString() { + return string().toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromHostRoute(this); + } + + public static class Builder { + protected String destinationCidr; + protected String nextHop; + + /** + * This should be a valid CIDR. + * @see HostRoute#getDestinationCidr() + */ + public Builder destinationCidr(String destinationCidr) { + this.destinationCidr = destinationCidr; + return this; + } + + /** + * This should be a valid IP address. + * @see HostRoute#getNextHop() + */ + public Builder nextHop(String nextHop) { + this.nextHop = nextHop; + return this; + } + + public HostRoute build() { + return new HostRoute(destinationCidr, nextHop); + } + + public Builder fromHostRoute(HostRoute in) { + return this.destinationCidr(in.getDestinationCidr()).nextHop(in.getNextHop()); + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/9c4bd944/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/IP.java ---------------------------------------------------------------------- diff --git a/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/IP.java b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/IP.java new file mode 100644 index 0000000..1885e99 --- /dev/null +++ b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/IP.java @@ -0,0 +1,132 @@ +/* + * 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.neutron.v2.domain; + +import com.google.common.base.Objects; + +import javax.inject.Named; + +/** + * Describes an IP address + */ +public class IP { + + @Named("ip_address") + protected final String ipAddress; + @Named("subnet_id") + protected final String subnetId; + + protected IP(String ipAddress, String subnetId) { + this.ipAddress = ipAddress; + this.subnetId = subnetId; + } + + /** + * @return the ipAddress of the IP + */ + public String getIpAddress() { + return ipAddress; + } + + /** + * @return the subnetId of the IP + */ + public String getSubnetId() { + return subnetId; + } + + @Override + public int hashCode() { + return Objects.hashCode(ipAddress, subnetId); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + IP that = IP.class.cast(obj); + return Objects.equal(this.ipAddress, that.ipAddress) && Objects.equal(this.subnetId, that.subnetId); + } + + protected Objects.ToStringHelper string() { + return Objects.toStringHelper(this).add("ipAddress", ipAddress).add("subnetId", subnetId); + } + + @Override + public String toString() { + return string().toString(); + } + + /** + * @return the Builder for IP + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Gets a Builder configured as this object. + */ + public Builder toBuilder() { + return new Builder().fromIP(this); + } + + public static class Builder { + protected String ipAddress; + protected String subnetId; + + /** + * Provide the ipAddress to the IP's Builder. + * + * @return the Builder. + * @see IP#getIpAddress() + */ + public Builder ipAddress(String ipAddress) { + this.ipAddress = ipAddress; + return this; + } + + /** + * Provide the subnetId to the IP's Builder. + * + * @return the Builder. + * @see IP#getSubnetId() + */ + public Builder subnetId(String subnetId) { + this.subnetId = subnetId; + return this; + } + + /** + * @return a IP constructed with this Builder. + */ + public IP build() { + return new IP(ipAddress, subnetId); + } + + /** + * @return a Builder from another IP. + */ + public Builder fromIP(IP in) { + return this.ipAddress(in.getIpAddress()).subnetId(in.getSubnetId()); + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/9c4bd944/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/IPv6DHCPMode.java ---------------------------------------------------------------------- diff --git a/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/IPv6DHCPMode.java b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/IPv6DHCPMode.java new file mode 100644 index 0000000..f985041 --- /dev/null +++ b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/IPv6DHCPMode.java @@ -0,0 +1,57 @@ +/* + * 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; + +/** + * Enumerates DHCP modes for UPv6 + */ +public enum IPv6DHCPMode { + OFF("off"), + SLAAC("slaac"), + DHCPV6_STATEFUL("dhcpv6-stateful"), + DHCPV6_STATELESS("dhcpv6-stateless"), + /** + * Used by jclouds when the service returns an unknown value other than null. + */ + UNRECOGNIZED("unrecognized"); + + private String name; + + private IPv6DHCPMode(String name) { + this.name = name; + } + + public String toString() { + return name; + } + + /** + * This provides GSON enum support in jclouds. + * */ + public static IPv6DHCPMode fromValue(String name){ + if (name != null) { + for (IPv6DHCPMode value : IPv6DHCPMode.values()) { + if (name.equalsIgnoreCase(value.name)) { + return value; + } + } + return UNRECOGNIZED; + } + return null; + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/9c4bd944/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/Network.java ---------------------------------------------------------------------- diff --git a/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/Network.java b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/Network.java new file mode 100644 index 0000000..1810fa2 --- /dev/null +++ b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/Network.java @@ -0,0 +1,647 @@ +/* + * 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.neutron.v2.domain; + +import com.google.common.base.Objects; +import com.google.common.collect.ImmutableSet; +import org.jclouds.javax.annotation.Nullable; + +import javax.inject.Named; +import java.beans.ConstructorProperties; +import java.util.Set; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * A Neutron network + * + * @see <a + * href="http://docs.openstack.org/api/openstack-network/2.0/content/Networks.html">api + * doc</a> + */ +public class Network { + + private String id; + private NetworkStatus status; + private ImmutableSet<String> subnets; + + private String name; + @Named("admin_state_up") + private Boolean adminStateUp; + private Boolean shared; + @Named("tenant_id") + private String tenantId; + + // providernet.py: Provider Networks Extension + @Named("provider:network_type") + private NetworkType networkType; + @Named("provider:physical_network") + private String physicalNetworkName; + @Named("provider:segmentation_id") + private Integer segmentationId; + + // external_net.py: Configurable external gateway modes extension + @Named("router:external") + private Boolean external; + + // portsecurity.py: VMWare port security + @Named("port_security_enabled") + private Boolean portSecurity; + + // n1kv.py: Cisco plugin extension; admin rights might be needed + @Named("n1kv:profile_id") + // UUID + private String profileId; + @Named("n1kv:multicast_ip") + private String multicastIp; + @Named("n1kv:segment_add") + private String segmentAdd; + @Named("n1kv:segment_del") + private String segmentDel; + @Named("n1kv:member_segments") + private String memberSegments; + + // multiprovidernet.py: Multiprovider net extension; Segments and provider + // values cannot both be set. + private ImmutableSet<NetworkSegment> segments; + + // flavor.py: Flavor support for network and router + @Named("flavor:network") + private String networkFlavor; + + @ConstructorProperties({"id", "status", "subnets", "name", "admin_state_up", "shared", "tenant_id", + "provider:network_type", "provider:physical_network", "provider:segmentation_id", "router:external", + "port_security_enabled", "n1kv:profile_id", "n1kv:multicast_ip", "n1kv:segment_add", "n1kv:segment_del", + "n1kv:member_segments", "segments", "flavor:network"}) + private Network(String id, NetworkStatus status, ImmutableSet<String> subnets, String name, Boolean adminStateUp, + Boolean shared, String tenantId, NetworkType networkType, String physicalNetworkName, Integer segmentationId, + Boolean external, Boolean portSecurity, String profileId, String multicastIp, String segmentAdd, + String segmentDel, String memberSegments, ImmutableSet<NetworkSegment> segments, String networkFlavor) { + // No checkNotNulls. With Neutron, any of these properties can be left null when used in an update. + this.id = id; + this.status = status; + this.subnets = subnets; + this.name = name; + this.adminStateUp = adminStateUp; + this.shared = shared; + this.tenantId = tenantId; + this.networkType = networkType; + this.physicalNetworkName = physicalNetworkName; + this.segmentationId = segmentationId; + this.external = external; + this.portSecurity = portSecurity; + this.profileId = profileId; + this.multicastIp = multicastIp; + this.segmentAdd = segmentAdd; + this.segmentDel = segmentDel; + this.memberSegments = memberSegments; + this.segments = segments; + this.networkFlavor = networkFlavor; + } + + /** + * Default constructor. + */ + private Network() {} + + /** + * Copy constructor + * @param network + */ + private Network(Network network) { + this(network.id, + network.status, + network.subnets, + network.name, + network.adminStateUp, + network.shared, + network.tenantId, + network.networkType, + network.physicalNetworkName, + network.segmentationId, + network.external, + network.portSecurity, + network.profileId, + network.multicastIp, + network.segmentAdd, + network.segmentDel, + network.memberSegments, + network.segments, + network.networkFlavor); + } + + /** + * @return the id of the Network + */ + @Nullable + public String getId() { + return id; + } + + /** + * @return the status of the Network + */ + @Nullable + public NetworkStatus getStatus() { + return status; + } + + /** + * @return the subnets of the Network + */ + @Nullable + public ImmutableSet<String> getSubnets() { + return subnets; + } + + /** + * @return the name of the Network + */ + @Nullable + public String getName() { + return name; + } + + /** + * @return the adminStateUp of the Network + */ + @Nullable + public Boolean isAdminStateUp() { + return adminStateUp; + } + + /** + * The shared attribute can be used to create a public network, i.e.: a network which is shared with all other tenants. + * Control of the shared attribute could be reserved to particular users only, such as administrators. + * In this case, regular users trying to create a shared network will receive a 403 - Forbidden error. + * @return true if the network resource can be accessed by any tenant or not, false if not + */ + @Nullable + public Boolean isShared() { + return shared; + } + + /** + * @return the tenantId of the Network + */ + @Nullable + public String getTenantId() { + return tenantId; + } + + /** + * @return the networkType of the Network + */ + @Nullable + public NetworkType getNetworkType() { + return networkType; + } + + /** + * @return the physicalNetworkName of the Network + */ + @Nullable + public String getPhysicalNetworkName() { + return physicalNetworkName; + } + + /** + * @return the segmentationId of the Network + */ + @Nullable + public Integer getSegmentationId() { + return segmentationId; + } + + /** + * Adds external network attribute to network resource. + * @return the external of the Network + */ + @Nullable + public Boolean isExternal() { + return external; + } + + /** + * @return the portSecurity of the Network + */ + @Nullable + public Boolean isPortSecurity() { + return portSecurity; + } + + /** + * @return the profileId of the Network + */ + @Nullable + public String getProfileId() { + return profileId; + } + + /** + * @return the multicastIp of the Network + */ + @Nullable + public String getMulticastIp() { + return multicastIp; + } + + /** + * @return the segmentAdd of the Network + */ + @Nullable + public String getSegmentAdd() { + return segmentAdd; + } + + /** + * @return the segmentDel of the Network + */ + @Nullable + public String getSegmentDel() { + return segmentDel; + } + + /** + * @return the memberSegments of the Network + */ + @Nullable + public String getMemberSegments() { + return memberSegments; + } + + /** + * @return the segments of the Network + */ + @Nullable + public ImmutableSet<NetworkSegment> getSegments() { + return segments; + } + + /** + * @return the networkFlavor of the Network + */ + @Nullable + public String getNetworkFlavor() { + return networkFlavor; + } + + @Override + public int hashCode() { + return Objects.hashCode(id, status, subnets, name, adminStateUp, shared, tenantId, networkType, + physicalNetworkName, segmentationId, external, portSecurity, profileId, multicastIp, segmentAdd, segmentDel, + memberSegments, segments, networkFlavor); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + Network that = Network.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.status, that.status) + && Objects.equal(this.subnets, that.subnets) + && Objects.equal(this.name, that.name) + && Objects.equal(this.adminStateUp, that.adminStateUp) + && Objects.equal(this.shared, that.shared) + && Objects.equal(this.tenantId, that.tenantId) + && Objects.equal(this.networkType, that.networkType) + && Objects.equal(this.physicalNetworkName, that.physicalNetworkName) + && Objects.equal(this.segmentationId, that.segmentationId) + && Objects.equal(this.external, that.external) + && Objects.equal(this.portSecurity, that.portSecurity) + && Objects.equal(this.profileId, that.profileId) + && Objects.equal(this.multicastIp, that.multicastIp) + && Objects.equal(this.segmentAdd, that.segmentAdd) + && Objects.equal(this.segmentDel, that.segmentDel) + && Objects.equal(this.memberSegments, that.memberSegments) + && Objects.equal(this.segments, that.segments) + && Objects.equal(this.networkFlavor, that.networkFlavor); + } + + @Override + public String toString() { + return Objects.toStringHelper(this) + .add("id", id) + .add("status", status) + .add("subnets", subnets) + .add("name", name) + .add("adminStateUp", adminStateUp) + .add("shared", shared) + .add("tenantId", tenantId) + .add("networkType", networkType) + .add("physicalNetworkName", physicalNetworkName) + .add("segmentationId", segmentationId) + .add("external", external) + .add("portSecurity", portSecurity) + .add("profileId", profileId) + .add("multicastIp", multicastIp) + .add("segmentAdd", segmentAdd) + .add("segmentDel", segmentDel) + .add("memberSegments", memberSegments) + .add("segments", segments) + .add("networkFlavor", networkFlavor) + .toString(); + } + + /* + * Methods to get the Create and Update builders follow + */ + + /** + * @return the Builder for creating a new Router + */ + public static CreateBuilder createOptions(String name) { + return new CreateBuilder(name); + } + + /** + * @return the Builder for updating a Router + */ + public static UpdateBuilder updateOptions() { + return new UpdateBuilder(); + } + + private static abstract class Builder<ParameterizedBuilderType> { + protected Network network; + + /** + * No-parameters constructor used when updating. + * */ + private Builder() { + network = new Network(); + } + + protected abstract ParameterizedBuilderType self(); + + /** + * Provide the name to the Network's Builder. + * + * @return the Builder. + * @see Network#getName() + */ + public ParameterizedBuilderType name(String name) { + network.name = name; + return self(); + } + + /** + * Provide the adminStateUp to the Network's Builder. + * + * @return the Builder. + * @see Network#isAdminStateUp() + */ + public ParameterizedBuilderType adminStateUp(Boolean adminStateUp) { + network.adminStateUp = adminStateUp; + return self(); + } + + /** + * Provide the shared to the Network's Builder. + * + * @return the Builder. + * @see Network#isShared() + */ + public ParameterizedBuilderType shared(Boolean shared) { + network.shared = shared; + return self(); + } + + /** + * Provide the tenantId to the Network's Builder. + * + * @return the Builder. + * @see Network#getTenantId() + */ + public ParameterizedBuilderType tenantId(String tenantId) { + network.tenantId = tenantId; + return self(); + } + + /** + * Provide the networkType to the Network's Builder. + * + * @return the Builder. + * @see Network#getNetworkType() + */ + public ParameterizedBuilderType networkType(NetworkType networkType) { + network.networkType = networkType; + return self(); + } + + /** + * Provide the physicalNetworkName to the Network's Builder. + * + * @return the Builder. + * @see Network#getPhysicalNetworkName() + */ + public ParameterizedBuilderType physicalNetworkName(String physicalNetworkName) { + network.physicalNetworkName = physicalNetworkName; + return self(); + } + + /** + * Provide the segmentationId to the Network's Builder. + * + * @return the Builder. + * @see Network#getSegmentationId() + */ + public ParameterizedBuilderType segmentationId(Integer segmentationId) { + network.segmentationId = segmentationId; + return self(); + } + + /** + * Adds external network attribute to network resource. + * + * @return the Builder. + * @see Network#isExternal() + */ + public ParameterizedBuilderType external(Boolean external) { + network.external = external; + return self(); + } + + /** + * Provide the portSecurity to the Network's Builder. + * + * @return the Builder. + * @see Network#isPortSecurity() + */ + public ParameterizedBuilderType portSecurity(Boolean portSecurity) { + network.portSecurity = portSecurity; + return self(); + } + + /** + * Provide the profileId to the Network's Builder. + * + * @return the Builder. + * @see Network#getProfileId() + */ + public ParameterizedBuilderType profileId(String profileId) { + network.profileId = profileId; + return self(); + } + + /** + * Provide the multicastIp to the Network's Builder. + * + * @return the Builder. + * @see Network#getMulticastIp() + */ + public ParameterizedBuilderType multicastIp(String multicastIp) { + network.multicastIp = multicastIp; + return self(); + } + + /** + * Provide the segmentAdd to the Network's Builder. + * Cisco plugin extension; admin right might be needed to use this. + * + * @return the Builder. + * @see Network#getSegmentAdd() + */ + public ParameterizedBuilderType segmentAdd(String segmentAdd) { + network.segmentAdd = segmentAdd; + return self(); + } + + /** + * Provide the segmentDel to the Network's Builder. + * Cisco plugin extension; admin right might be needed to use this. + * + * @return the Builder. + * @see Network#getSegmentDel() + */ + public ParameterizedBuilderType segmentDel(String segmentDel) { + network.segmentDel = segmentDel; + return self(); + } + + /** + * Provide the memberSegments to the Network's Builder. + * Cisco plugin extension; admin right might be needed to use this. + * + * @return the Builder. + * @see Network#getMemberSegments() + */ + public ParameterizedBuilderType memberSegments(String memberSegments) { + network.memberSegments = memberSegments; + return self(); + } + + /** + * Provide the segments to the Network's Builder. + * Multiprovider extension. + * + * @return the Builder. + * @see Network#getSegments() + */ + public ParameterizedBuilderType segments(ImmutableSet<NetworkSegment> segments) { + network.segments = segments; + return self(); + } + + /** + * Provide the networkFlavor to the Network's Builder. + * + * @return the Builder. + * @see Network#getNetworkFlavor() + */ + public ParameterizedBuilderType networkFlavor(String networkFlavor) { + network.networkFlavor = networkFlavor; + return self(); + } + } + + /** + * Create and Update builders (inheriting from Builder) + */ + public static class CreateBuilder extends Builder<CreateBuilder> { + /** + * Supply required properties for creating a Builder + */ + private CreateBuilder(String name) { + network.name = name; + } + + /** + * @return a CreateOptions constructed with this Builder. + */ + public CreateOptions build() { + return new CreateOptions(network); + } + + protected CreateBuilder self() { + return this; + } + } + + /** + * Create and Update builders (inheriting from Builder) + */ + public static class UpdateBuilder extends Builder<UpdateBuilder> { + /** + * Supply required properties for updating a Builder + */ + private UpdateBuilder() { + } + + /** + * @return a UpdateOptions constructed with this Builder. + */ + public UpdateOptions build() { + return new UpdateOptions(network); + } + + protected UpdateBuilder self() { + return this; + } + } + + /** + * Create and Update options - extend the domain class, passed to API update and create calls. + * Essentially the same as the domain class. Ensure validation and safe typing. + */ + public static class CreateOptions extends Network { + /** + * Copy constructor + */ + private CreateOptions(Network network) { + super(network); + checkNotNull(network.name, "name should not be null"); + } + } + + /** + * Create and Update options - extend the domain class, passed to API update and create calls. + * Essentially the same as the domain class. Ensure validation and safe typing. + */ + public static class UpdateOptions extends Network { + /** + * Copy constructor + */ + private UpdateOptions(Network network) { + super(network); + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/9c4bd944/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/NetworkSegment.java ---------------------------------------------------------------------- diff --git a/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/NetworkSegment.java b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/NetworkSegment.java new file mode 100644 index 0000000..3406746 --- /dev/null +++ b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/NetworkSegment.java @@ -0,0 +1,163 @@ +/* + * 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.neutron.v2.domain; + +import com.google.common.base.Objects; + +import javax.inject.Named; + +/** + * A Neutron Network Segment + * Segments and provider values cannot both be set. + * + * @see <a + * href="http://docs.openstack.org/api/openstack-network/2.0/content/Subnets.html">api + * doc</a> + */ +public class NetworkSegment { + + @Named("provider:network_type") + protected final NetworkType networkType; + @Named("provider:physical_network") + protected final String physicalNetwork; + @Named("provider:segmentation_id") + protected final int segmentationId; + + protected NetworkSegment(NetworkType networkType, String physicalNetwork, int segmentationId) { + this.networkType = networkType; + this.physicalNetwork = physicalNetwork; + this.segmentationId = segmentationId; + } + + /** + * @return the networkType of the NetworkSegment + */ + public NetworkType getNetworkType() { + return networkType; + } + + /** + * @return the physicalNetwork of the NetworkSegment + */ + public String getPhysicalNetwork() { + return physicalNetwork; + } + + /** + * @return the segmentationId of the NetworkSegment + */ + public int getSegmentationId() { + return segmentationId; + } + + @Override + public int hashCode() { + return Objects.hashCode(networkType, physicalNetwork, segmentationId); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + NetworkSegment that = NetworkSegment.class.cast(obj); + return Objects.equal(this.networkType, that.networkType) + && Objects.equal(this.physicalNetwork, that.physicalNetwork) + && Objects.equal(this.segmentationId, that.segmentationId); + } + + protected Objects.ToStringHelper string() { + return Objects.toStringHelper(this).add("networkType", networkType).add("physicalNetwork", physicalNetwork) + .add("segmentationId", segmentationId); + } + + @Override + public String toString() { + return string().toString(); + } + + /** + * @return the Builder for NetworkSegment + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Gets a Builder configured as this object. + */ + public Builder toBuilder() { + return new Builder().fromNetworkSegment(this); + } + + public static class Builder { + protected NetworkType networkType; + protected String physicalNetwork; + protected int segmentationId; + + /** + * Provide the networkType to the NetworkSegment's Builder. + * + * @return the Builder. + * @see NetworkSegment#getNetworkType() + */ + public Builder networkType(NetworkType networkType) { + this.networkType = networkType; + return this; + } + + /** + * Provide the physicalNetwork to the NetworkSegment's Builder. + * + * @return the Builder. + * @see NetworkSegment#getPhysicalNetwork() + */ + public Builder physicalNetwork(String physicalNetwork) { + this.physicalNetwork = physicalNetwork; + return this; + } + + /** + * Provide the segmentationId to the NetworkSegment's Builder. + * + * @return the Builder. + * @see NetworkSegment#getSegmentationId() + */ + public Builder segmentationId(int segmentationId) { + this.segmentationId = segmentationId; + return this; + } + + /** + * @return a NetworkSegment constructed with this Builder. + */ + public NetworkSegment build() { + return new NetworkSegment(networkType, physicalNetwork, segmentationId); + } + + /** + * @return a Builder from another NetworkSegment. + */ + public Builder fromNetworkSegment(NetworkSegment in) { + return this.networkType(in.getNetworkType()).physicalNetwork(in.getPhysicalNetwork()) + .segmentationId(in.getSegmentationId()); + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/9c4bd944/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/NetworkStatus.java ---------------------------------------------------------------------- diff --git a/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/NetworkStatus.java b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/NetworkStatus.java new file mode 100644 index 0000000..059ffa7 --- /dev/null +++ b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/NetworkStatus.java @@ -0,0 +1,57 @@ +/* + * 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; + +public enum NetworkStatus { + ACTIVE("active"), + DOWN("down"), + BUILD("build"), + ERROR("error"), + /** + * Used by jclouds when the service returns an unknown value other than null. + */ + UNRECOGNIZED("unrecognized"); + + private final String name; + + private NetworkStatus(String name) { + this.name = name; + } + + @Override + public String toString() { + return name(); + } + + /** + * This provides GSON enum support in jclouds. + * @param name The string representation of this enum value. + * @return The corresponding enum value. + */ + public static NetworkStatus fromValue(String name) { + if (name != null) { + for (NetworkStatus value : NetworkStatus.values()) { + if (name.equalsIgnoreCase(value.name)) { + return value; + } + } + return UNRECOGNIZED; + } + return null; + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/9c4bd944/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/NetworkType.java ---------------------------------------------------------------------- diff --git a/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/NetworkType.java b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/NetworkType.java new file mode 100644 index 0000000..5281cdf --- /dev/null +++ b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/NetworkType.java @@ -0,0 +1,69 @@ +/* + * 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; + +/** + * Enumerates supported Network types. + */ +public enum NetworkType { + /** + * Used to describe a local network. + */ + LOCAL("local"), + /** + * Used to describe a flat network. + */ + FLAT("flat"), + /** + * Used to describe a VLAN network. NetworkSegment might have to be set. + */ + VLAN("vlan"), + GRE("gre"), + /** + * Used by jclouds when the service returns an unknown value other than null. + */ + UNRECOGNIZED("unrecognized"); + + private String name; + + private NetworkType(String name) { + this.name = name; + } + + @Override + public String toString() { + return name; + } + + /** + * This provides GSON enum support in jclouds. + * @param name The string representation of this enum value. + * @return The corresponding enum value. + */ + public static NetworkType fromValue(String name) { + if (name != null) { + for (NetworkType value : NetworkType.values()) { + if (name.equalsIgnoreCase(value.name)) { + return value; + } + } + return UNRECOGNIZED; + } + return null; + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/9c4bd944/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/Networks.java ---------------------------------------------------------------------- diff --git a/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/Networks.java b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/Networks.java new file mode 100644 index 0000000..45f6c56 --- /dev/null +++ b/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2/domain/Networks.java @@ -0,0 +1,35 @@ +/* + * 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 com.google.common.collect.ImmutableSet; +import org.jclouds.openstack.v2_0.domain.Link; +import org.jclouds.openstack.v2_0.domain.PaginatedCollection; + +import java.beans.ConstructorProperties; + +/** + * A collection of Networks + */ +public class Networks extends PaginatedCollection<Network> { + public static final Networks EMPTY = new Networks(ImmutableSet.<Network> of(), ImmutableSet.<Link> of()); + + @ConstructorProperties({ "networks", "networks_links" }) + protected Networks(Iterable<Network> networks, Iterable<Link> networksLinks) { + super(networks, networksLinks); + } +}
