OpenStack Neutron v2.0 implementation

This commit is contained in:
Kris Sterckx 2013-08-27 09:39:32 +02:00 committed by Everett Toews
commit d54117547b
57 changed files with 7273 additions and 0 deletions

View File

@ -0,0 +1,125 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-project</artifactId>
<version>1.7.0-SNAPSHOT</version>
</parent>
<!-- TODO: when out of labs, switch to org.jclouds.api -->
<groupId>org.apache.jclouds.labs</groupId>
<artifactId>openstack-neutron</artifactId>
<version>1.7.0-SNAPSHOT</version>
<name>jclouds openstack-neutron api</name>
<description>jclouds components to access an implementation of OpenStack Neutron</description>
<packaging>bundle</packaging>
<properties>
<!-- keystone endpoint -->
<test.openstack-neutron.endpoint>http://localhost:5000/v2.0/</test.openstack-neutron.endpoint>
<!-- keystone version -->
<test.openstack-neutron.api-version>2.0</test.openstack-neutron.api-version>
<test.openstack-neutron.build-version />
<test.openstack-neutron.identity>FIXME_IDENTITY</test.openstack-neutron.identity>
<test.openstack-neutron.credential>FIXME_CREDENTIALS</test.openstack-neutron.credential>
<test.jclouds.keystone.credential-type>passwordCredentials</test.jclouds.keystone.credential-type>
<jclouds.osgi.export>org.jclouds.openstack.neutron.v2_0*;version="${project.version}"</jclouds.osgi.export>
<jclouds.osgi.import>
org.jclouds.rest.internal;version="${jclouds.version}",
org.jclouds.labs*;version="${project.version}",
org.jclouds*;version="${jclouds.version}",
*
</jclouds.osgi.import>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.jclouds.api</groupId>
<artifactId>openstack-keystone</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.parent.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.jclouds.api</groupId>
<artifactId>openstack-keystone</artifactId>
<version>${project.parent.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.jclouds.driver</groupId>
<artifactId>jclouds-slf4j</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>live</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>integration</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemPropertyVariables>
<test.openstack-neutron.endpoint>${test.openstack-neutron.endpoint}</test.openstack-neutron.endpoint>
<test.openstack-neutron.api-version>${test.openstack-neutron.api-version}</test.openstack-neutron.api-version>
<test.openstack-neutron.build-version>${test.openstack-neutron.build-version}</test.openstack-neutron.build-version>
<test.openstack-neutron.identity>${test.openstack-neutron.identity}</test.openstack-neutron.identity>
<test.openstack-neutron.credential>${test.openstack-neutron.credential}</test.openstack-neutron.credential>
<test.jclouds.keystone.credential-type>${test.jclouds.keystone.credential-type}</test.jclouds.keystone.credential-type>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -0,0 +1,74 @@
/**
* 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_0;
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_0.features.NetworkApi;
import org.jclouds.openstack.neutron.v2_0.features.PortApi;
import org.jclouds.openstack.neutron.v2_0.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/>
*
* @author Nick Livens
* @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> getConfiguredZones();
/**
* 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);
}

View File

@ -0,0 +1,102 @@
/**
* 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_0;
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_0.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
*
* @author Nick Livens
*/
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("KeyStone 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;
}
}
}

View File

@ -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_0.config;
import java.net.URI;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import javax.inject.Provider;
import javax.inject.Singleton;
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_0.NeutronApi;
import org.jclouds.openstack.neutron.v2_0.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 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;
/**
* Configures the Neutron connection.
*
* @author Nick Livens
*/
@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);
}
}

View File

@ -0,0 +1,127 @@
/*
* 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_0.domain;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import java.beans.ConstructorProperties;
/**
* A Neutron Subnet Allocation Pool
*
* @author Nick Livens
* @see <a href="http://docs.openstack.org/api/openstack-network/2.0/content/Subnets.html">api doc</a>
*/
public class AllocationPool {
private final String start;
private final String end;
@ConstructorProperties({
"start", "end"
})
protected AllocationPool(String start, String end) {
this.start = start;
this.end = end;
}
/**
* @return the start ip
*/
public String getStart() {
return start;
}
/**
* @return the end ip
*/
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 ToStringHelper string() {
return Objects.toStringHelper(this).add("start", start).add("end", end);
}
@Override
public String toString() {
return string().toString();
}
public static Builder builder() {
return new ConcreteBuilder();
}
public Builder toBuilder() {
return new ConcreteBuilder().fromAllocationPool(this);
}
public static abstract class Builder {
protected abstract Builder self();
protected String start;
protected String end;
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.AllocationPool#getStart()
*/
public Builder start(String start) {
this.start = start;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.AllocationPool#getEnd()
*/
public Builder end(String end) {
this.end = end;
return self();
}
public AllocationPool build() {
return new AllocationPool(start, end);
}
public Builder fromAllocationPool(AllocationPool in) {
return this.start(in.getStart()).end(in.getEnd());
}
}
private static class ConcreteBuilder extends Builder {
@Override
protected ConcreteBuilder self() {
return this;
}
}
}

View File

@ -0,0 +1,211 @@
/*
* 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_0.domain;
import com.google.common.base.Objects;
import java.beans.ConstructorProperties;
/**
* A Neutron network used for creating networks in bulk
* The only difference between this and the actual network are the missing fields id, tenantId, state & shared
*
* @author Nick Livens
*/
public class BulkNetwork {
private final String name;
private final Boolean adminStateUp;
private final Boolean external;
private final NetworkType networkType;
private final String physicalNetworkName;
private final Integer segmentationId;
@ConstructorProperties({
"name", "admin_state_up", "router:external", "provider:network_type", "provider:physical_network", "provider:segmentation_id"
})
protected BulkNetwork(String name, Boolean adminStateUp, Boolean external, String networkType, String physicalNetworkName, Integer segmentationId) {
this.name = name;
this.adminStateUp = adminStateUp;
this.external = external;
this.networkType = NetworkType.fromValue(networkType);
this.physicalNetworkName = physicalNetworkName;
this.segmentationId = segmentationId;
}
/**
* @return the name of the network
*/
public String getName() {
return name;
}
/**
* @return the administrative state of network. If false, the network does not forward packets.
*/
public Boolean getAdminStateUp() {
return adminStateUp;
}
/**
* @return true if network is external, false if not
*/
public Boolean getExternal() {
return external;
}
/**
* @return the type of network
*/
public NetworkType getNetworkType() {
return networkType;
}
/**
* @return the physical network name
*/
public String getPhysicalNetworkName() {
return physicalNetworkName;
}
/**
* @return the segmentation id of the network
*/
public Integer getSegmentationId() {
return segmentationId;
}
@Override
public int hashCode() {
return Objects.hashCode(name, adminStateUp, external, networkType, physicalNetworkName, segmentationId);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
BulkNetwork that = BulkNetwork.class.cast(obj);
return Objects.equal(this.name, that.name)
&& Objects.equal(this.adminStateUp, that.adminStateUp)
&& Objects.equal(this.external, that.external)
&& Objects.equal(this.networkType, that.networkType)
&& Objects.equal(this.physicalNetworkName, that.physicalNetworkName)
&& Objects.equal(this.segmentationId, that.segmentationId);
}
protected Objects.ToStringHelper string() {
return Objects.toStringHelper(this)
.add("name", name).add("adminStateUp", adminStateUp).add("external", external)
.add("networkType", networkType).add("physicalNetworkName", physicalNetworkName)
.add("segmentationId", segmentationId);
}
@Override
public String toString() {
return string().toString();
}
public static Builder builder() {
return new ConcreteBuilder();
}
public Builder toBuilder() {
return new ConcreteBuilder().fromBulkNetwork(this);
}
public static abstract class Builder {
protected abstract Builder self();
protected String name;
protected Boolean adminStateUp;
protected Boolean external;
protected NetworkType networkType;
protected String physcialNetworkName;
protected Integer segmentationId;
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.BulkNetwork#getName()
*/
public Builder name(String name) {
this.name = name;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.BulkNetwork#getAdminStateUp()
*/
public Builder adminStateUp(Boolean adminStateUp) {
this.adminStateUp = adminStateUp;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.BulkNetwork#getExternal()
*/
public Builder external(Boolean external) {
this.external = external;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.BulkNetwork#getNetworkType()
*/
public Builder networkType(NetworkType networkType) {
this.networkType = networkType;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.BulkNetwork#getPhysicalNetworkName()
*/
public Builder physicalNetworkName(String physicalNetworkName) {
this.physcialNetworkName = physicalNetworkName;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.BulkNetwork#getSegmentationId()
*/
public Builder segmentationId(Integer segmentationId) {
this.segmentationId = segmentationId;
return self();
}
public BulkNetwork build() {
return new BulkNetwork(name, adminStateUp, external, networkType == null ? null : networkType.getValue(), physcialNetworkName, segmentationId);
}
public Builder fromBulkNetwork(BulkNetwork in) {
return this.name(in.getName())
.adminStateUp(in.getAdminStateUp())
.external(in.getExternal())
.networkType(in.getNetworkType())
.physicalNetworkName(in.getPhysicalNetworkName())
.segmentationId(in.getSegmentationId());
}
}
private static class ConcreteBuilder extends Builder {
@Override
protected ConcreteBuilder self() {
return this;
}
}
}

View File

@ -0,0 +1,233 @@
/*
* 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_0.domain;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
import java.beans.ConstructorProperties;
import java.util.Collection;
import java.util.Set;
/**
* A Neutron port used for creating ports in bulk
* The only difference between this and the actual port are the missing fields id, tenantId & state
*
* @author Nick Livens
*/
public class BulkPort {
private final String name;
private final String networkId;
private final Boolean adminStateUp;
private final String deviceId;
private final String deviceOwner;
private final Set<IP> fixedIps;
private final String macAddress;
@ConstructorProperties({
"name", "network_id", "admin_state_up", "device_id", "device_owner", "fixed_ips", "mac_address"
})
protected BulkPort(String name, String networkId, Boolean adminStateUp, String deviceId, String deviceOwner, Set<IP> fixedIps, String macAddress) {
this.name = name;
this.networkId = networkId;
this.adminStateUp = adminStateUp;
this.deviceId = deviceId;
this.deviceOwner = deviceOwner;
this.fixedIps = fixedIps != null ? ImmutableSet.copyOf(fixedIps) : ImmutableSet.<IP>of();
this.macAddress = macAddress;
}
/**
* @return the name of the port
*/
public String getName() {
return name;
}
/**
* @return the id of the network where this port is associated with
*/
public String getNetworkId() {
return networkId;
}
/**
* @return the administrative state of port. If false, port does not forward packets
*/
public Boolean getAdminStateUp() {
return adminStateUp;
}
/**
* @return the id of the device (e.g. server) using this port.
*/
public String getDeviceId() {
return deviceId;
}
/**
* @return the entity (e.g.: dhcp agent) using this port.
*/
public String getDeviceOwner() {
return deviceOwner;
}
/**
* @return the set of fixed ips this port has been assigned
*/
public Set<IP> getFixedIps() {
return fixedIps;
}
/**
* @return the mac address of this port
*/
public String getMacAddress() {
return macAddress;
}
@Override
public int hashCode() {
return Objects.hashCode(name, networkId, adminStateUp, deviceId, deviceOwner, fixedIps, macAddress);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
BulkPort that = BulkPort.class.cast(obj);
return Objects.equal(this.name, that.name)
&& Objects.equal(this.networkId, that.networkId)
&& Objects.equal(this.adminStateUp, that.adminStateUp)
&& Objects.equal(this.deviceId, that.deviceId)
&& Objects.equal(this.deviceOwner, that.deviceOwner)
&& Objects.equal(this.fixedIps, that.fixedIps)
&& Objects.equal(this.macAddress, that.macAddress);
}
protected Objects.ToStringHelper string() {
return Objects.toStringHelper(this)
.add("name", name).add("networkId", networkId).add("adminStateUp", adminStateUp)
.add("deviceId", deviceId).add("deviceOwner", deviceOwner).add("fixedIps", fixedIps).add("macAddress", macAddress);
}
@Override
public String toString() {
return string().toString();
}
public static Builder builder() {
return new ConcreteBuilder();
}
public Builder toBuilder() {
return new ConcreteBuilder().fromBulkPort(this);
}
public static abstract class Builder {
protected abstract Builder self();
protected String name;
protected String networkId;
protected String deviceId;
protected String deviceOwner;
protected String macAddress;
protected Set<IP> fixedIps;
protected Boolean adminStateUp;
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.BulkPort#getName()
*/
public Builder name(String name) {
this.name = name;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.BulkPort#getNetworkId()
*/
public Builder networkId(String networkId) {
this.networkId = networkId;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.BulkPort#getDeviceId()
*/
public Builder deviceId(String deviceId) {
this.deviceId = deviceId;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.BulkPort#getDeviceOwner()
*/
public Builder deviceOwner(String deviceOwner) {
this.deviceOwner = deviceOwner;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.BulkPort#getMacAddress()
*/
public Builder macAddress(String macAddress) {
this.macAddress = macAddress;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.BulkPort#getFixedIps()
*/
public Builder fixedIps(Collection<IP> fixedIps) {
this.fixedIps = ImmutableSet.copyOf(fixedIps);
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.BulkPort#getAdminStateUp()
*/
public Builder adminStateUp(Boolean adminStateUp) {
this.adminStateUp = adminStateUp;
return self();
}
public BulkPort build() {
return new BulkPort(name, networkId, adminStateUp, deviceId, deviceOwner, fixedIps, macAddress);
}
public Builder fromBulkPort(BulkPort in) {
return this.name(in.getName())
.networkId(in.getNetworkId())
.adminStateUp(in.getAdminStateUp())
.deviceId(in.getDeviceId())
.deviceOwner(in.getDeviceOwner())
.fixedIps(in.getFixedIps())
.macAddress(in.getMacAddress());
}
}
private static class ConcreteBuilder extends Builder {
@Override
protected ConcreteBuilder self() {
return this;
}
}
}

View File

@ -0,0 +1,276 @@
/*
* 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_0.domain;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
import java.beans.ConstructorProperties;
import java.util.Collection;
import java.util.Set;
/**
* A Neutron subnet used for creating subnets in bulk
* The only difference between this and the actual subnet are the missing fields id & tenantId
*
* @author Nick Livens
*/
public class BulkSubnet {
protected String name;
protected String networkId;
protected String gatewayIp;
protected Integer ipVersion;
protected String cidr;
protected Set<AllocationPool> allocationPools;
protected Boolean enableDhcp;
protected Set<String> dnsNameServers;
protected Set<HostRoute> hostRoutes;
@ConstructorProperties({
"name", "network_id", "gateway_ip", "ip_version", "cidr", "allocation_pools", "enable_dhcp", "dns_nameservers", "host_routes"
})
protected BulkSubnet(String name, String networkId, String gatewayIp, Integer ipVersion, String cidr,
Set<AllocationPool> allocationPools, Boolean enableDhcp, Set<String> dnsNameServers, Set<HostRoute> hostRoutes) {
this.name = name;
this.networkId = networkId;
this.gatewayIp = gatewayIp;
this.ipVersion = ipVersion;
this.cidr = cidr;
this.allocationPools = allocationPools != null ? ImmutableSet.copyOf(allocationPools) : ImmutableSet.<AllocationPool>of();
this.enableDhcp = enableDhcp;
this.dnsNameServers = dnsNameServers != null ? ImmutableSet.copyOf(dnsNameServers) : ImmutableSet.<String>of();
this.hostRoutes = hostRoutes != null ? ImmutableSet.copyOf(hostRoutes) : ImmutableSet.<HostRoute>of();
}
/**
* @return the name of the subnet
*/
public String getName() {
return name;
}
/**
* @return the id of the network this subnet is associated with
*/
public String getNetworkId() {
return networkId;
}
/**
* @return the default gateway used by devices in this subnet
*/
public String getGatewayIp() {
return gatewayIp;
}
/**
* @return the ip version used by this subnet
*/
public Integer getIpVersion() {
return ipVersion;
}
/**
* @return the cidr representing the IP range for this subnet, based on IP version
*/
public String getCidr() {
return cidr;
}
/**
* @return the sub-ranges of cidr available for dynamic allocation to ports
*/
public Set<AllocationPool> getAllocationPools() {
return allocationPools;
}
/**
* @return true if DHCP is enabled for this subnet, false if not.
*/
public Boolean getEnableDhcp() {
return enableDhcp;
}
/**
* @return the set of DNS name servers used by hosts in this subnet.
*/
public Set<String> getDnsNameServers() {
return dnsNameServers;
}
/**
* @return the set of routes that should be used by devices with IPs from this subnet
*/
public Set<HostRoute> getHostRoutes() {
return hostRoutes;
}
@Override
public int hashCode() {
return Objects.hashCode(name, networkId, gatewayIp, ipVersion, cidr,
allocationPools, enableDhcp, dnsNameServers, hostRoutes);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
BulkSubnet that = BulkSubnet.class.cast(obj);
return Objects.equal(this.name, that.name)
&& Objects.equal(this.networkId, that.networkId)
&& Objects.equal(this.gatewayIp, that.gatewayIp)
&& Objects.equal(this.ipVersion, that.ipVersion)
&& Objects.equal(this.cidr, that.cidr)
&& Objects.equal(this.allocationPools, that.allocationPools)
&& Objects.equal(this.enableDhcp, that.enableDhcp)
&& Objects.equal(this.dnsNameServers, that.dnsNameServers)
&& Objects.equal(this.hostRoutes, that.hostRoutes);
}
protected Objects.ToStringHelper string() {
return Objects.toStringHelper(this)
.add("name", name).add("networkId", networkId).add("gatewayIp", gatewayIp).add("ipVersion", ipVersion)
.add("cidr", cidr).add("enableDhcp", enableDhcp).add("allocationPools", allocationPools)
.add("dnsNameServers", dnsNameServers).add("hostRoutes", hostRoutes);
}
@Override
public String toString() {
return string().toString();
}
public static Builder builder() {
return new ConcreteBuilder();
}
public Builder toBuilder() {
return new ConcreteBuilder().fromBulkSubnet(this);
}
public static abstract class Builder {
protected abstract Builder self();
protected String name;
protected String networkId;
protected String gatewayIp;
protected Integer ipVersion;
protected String cidr;
protected Set<AllocationPool> allocationPools;
protected Boolean enableDhcp;
protected Set<String> dnsNameServers;
protected Set<HostRoute> hostRoutes;
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.BulkSubnet#getName()
*/
public Builder name(String name) {
this.name = name;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.BulkSubnet#getNetworkId()
*/
public Builder networkId(String networkId) {
this.networkId = networkId;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.BulkSubnet#getGatewayIp()
*/
public Builder gatewayIp(String gatewayIp) {
this.gatewayIp = gatewayIp;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.BulkSubnet#getIpVersion()
*/
public Builder ipVersion(Integer ipVersion) {
this.ipVersion = ipVersion;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.BulkSubnet#getCidr()
*/
public Builder cidr(String cidr) {
this.cidr = cidr;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.BulkSubnet#getAllocationPools()
*/
public Builder allocationPools(Collection<AllocationPool> allocationPools) {
this.allocationPools = ImmutableSet.copyOf(allocationPools);
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.BulkSubnet#getEnableDhcp()
*/
public Builder enableDhcp(Boolean enableDhcp) {
this.enableDhcp = enableDhcp;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.BulkSubnet#getDnsNameServers()
*/
public Builder dnsNameServers(Collection<String> dnsNameServers) {
this.dnsNameServers = ImmutableSet.copyOf(dnsNameServers);
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.BulkSubnet#getHostRoutes()
*/
public Builder hostRoutes(Collection<HostRoute> hostRoutes) {
this.hostRoutes = ImmutableSet.copyOf(hostRoutes);
return self();
}
public BulkSubnet build() {
return new BulkSubnet(name, networkId, gatewayIp, ipVersion, cidr, allocationPools, enableDhcp, dnsNameServers, hostRoutes);
}
public Builder fromBulkSubnet(BulkSubnet in) {
return this.name(in.getName())
.networkId(in.getNetworkId())
.gatewayIp(in.getGatewayIp())
.ipVersion(in.getIpVersion())
.cidr(in.getCidr())
.allocationPools(in.getAllocationPools())
.enableDhcp(in.getEnableDhcp())
.dnsNameServers(in.getDnsNameServers())
.hostRoutes(in.getHostRoutes());
}
}
private static class ConcreteBuilder extends Builder {
@Override
protected ConcreteBuilder self() {
return this;
}
}
}

View File

@ -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_0.domain;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import java.beans.ConstructorProperties;
/**
* A Neutron Subnet Host Route
*
* @author Nick Livens
* @see <a href="http://docs.openstack.org/api/openstack-network/2.0/content/Subnets.html">api doc</a>
*/
public class HostRoute {
private final String destinationCidr;
private final String nextHop;
@ConstructorProperties({
"destination", "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 ConcreteBuilder();
}
public Builder toBuilder() {
return new ConcreteBuilder().fromHostRoute(this);
}
public static abstract class Builder {
protected abstract Builder self();
protected String destinationCidr;
protected String nextHop;
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.HostRoute#getDestinationCidr()
*/
public Builder destinationCidr(String destinationCidr) {
this.destinationCidr = destinationCidr;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.HostRoute#getNextHop()
*/
public Builder nextHop(String nextHop) {
this.nextHop = nextHop;
return self();
}
public HostRoute build() {
return new HostRoute(destinationCidr, nextHop);
}
public Builder fromHostRoute(HostRoute in) {
return this.destinationCidr(in.getDestinationCidr()).nextHop(in.getNextHop());
}
}
private static class ConcreteBuilder extends Builder {
@Override
protected ConcreteBuilder self() {
return this;
}
}
}

View File

@ -0,0 +1,124 @@
/*
* 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_0.domain;
import com.google.common.base.Objects;
import java.beans.ConstructorProperties;
/**
* @author Nick Livens
*/
public class IP {
private String ipAddress;
private String subnetId;
@ConstructorProperties({
"ip_address", "subnet_id"
})
protected IP(String ipAddress, String subnetId) {
this.ipAddress = ipAddress;
this.subnetId = subnetId;
}
/**
* @return the fixed ip address
*/
public String getIpAddress() {
return ipAddress;
}
/**
* @return the id of the subnet of this 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();
}
public static Builder builder() {
return new ConcreteBuilder();
}
public Builder toBuilder() {
return new ConcreteBuilder().fromIP(this);
}
public static abstract class Builder {
protected abstract Builder self();
protected String ipAddress;
protected String subnetId;
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.IP#getIpAddress
*/
public Builder ipAddress(String ipAddress) {
this.ipAddress = ipAddress;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.IP#getSubnetId
*/
public Builder subnetId(String subnetId) {
this.subnetId = subnetId;
return self();
}
public IP build() {
return new IP(ipAddress, subnetId);
}
public Builder fromIP(IP in) {
return this.ipAddress(in.getIpAddress()).subnetId(in.getSubnetId());
}
}
private static class ConcreteBuilder extends Builder {
@Override
protected ConcreteBuilder self() {
return this;
}
}
}

View File

@ -0,0 +1,257 @@
/*
* 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_0.domain;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
import java.beans.ConstructorProperties;
import java.util.Set;
/**
* A Neutron network
*
* @author Nick Livens
* @see <a href="http://docs.openstack.org/api/openstack-network/2.0/content/Networks.html">api doc</a>
*/
public class Network extends ReferenceWithName {
private final State state;
private final Set<String> subnets;
private final Boolean adminStateUp;
private final Boolean shared;
private final Boolean external;
private final NetworkType networkType;
private final String physicalNetworkName;
private final Integer segmentationId;
@ConstructorProperties({
"id", "tenant_id", "name", "status", "subnets", "admin_state_up", "shared", "router:external",
"provider:network_type", "provider:physical_network", "provider:segmentation_id"
})
protected Network(String id, String tenantId, String name, State state,
Set<String> subnets, Boolean adminStateUp, Boolean shared, Boolean external,
String networkType, String physicalNetworkName, Integer segmentationId) {
super(id, tenantId, name);
this.state = state;
this.subnets = subnets != null ? ImmutableSet.copyOf(subnets) : ImmutableSet.<String>of();
this.adminStateUp = adminStateUp;
this.shared = shared;
this.external = external;
this.networkType = NetworkType.fromValue(networkType);
this.physicalNetworkName = physicalNetworkName;
this.segmentationId = segmentationId;
}
/**
* @return the current state of the network
*/
public State getState() {
return state;
}
/**
* @return set of subnet ids that are associated with this network
*/
public Set<String> getSubnets() {
return subnets;
}
/**
* @return the administrative state of network. If false, the network does not forward packets.
*/
public Boolean getAdminStateUp() {
return adminStateUp;
}
/**
* @return true if the network resource can be accessed by any tenant or not, false if not
*/
public Boolean getShared() {
return shared;
}
/**
* @return true if network is external, false if not
*/
public Boolean getExternal() {
return external;
}
/**
* @return the type of network
*/
public NetworkType getNetworkType() {
return networkType;
}
/**
* @return the physical network name
*/
public String getPhysicalNetworkName() {
return physicalNetworkName;
}
/**
* @return the segmentation id of the network
*/
public Integer getSegmentationId() {
return segmentationId;
}
@Override
public int hashCode() {
return Objects.hashCode(super.hashCode(), state, subnets, adminStateUp, shared, external,
networkType, physicalNetworkName, segmentationId);
}
@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 super.equals(obj)
&& Objects.equal(this.state, that.state)
&& Objects.equal(this.subnets, that.subnets)
&& Objects.equal(this.adminStateUp, that.adminStateUp)
&& Objects.equal(this.shared, that.shared)
&& Objects.equal(this.external, that.external)
&& Objects.equal(this.networkType, that.networkType)
&& Objects.equal(this.physicalNetworkName, that.physicalNetworkName)
&& Objects.equal(this.segmentationId, that.segmentationId);
}
protected Objects.ToStringHelper string() {
return super.string()
.add("state", state).add("subnets", subnets).add("adminStateUp", adminStateUp).add("shared", shared).add("external", external)
.add("networkType", networkType).add("physicalNetworkName", physicalNetworkName).add("segmentationId", segmentationId);
}
@Override
public String toString() {
return string().toString();
}
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromNetwork(this);
}
public static abstract class Builder<T extends Builder<T>> extends ReferenceWithName.Builder<T> {
protected State state;
protected Set<String> subnets;
protected Boolean adminStateUp;
protected Boolean shared;
protected Boolean external;
protected NetworkType networkType;
protected String physicalNetworkName;
protected Integer segmentationId;
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.Network#getState()
*/
public T state(State state) {
this.state = state;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.Network#getSubnets()
*/
public T subnets(Set<String> subnets) {
this.subnets = subnets;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.Network#getAdminStateUp()
*/
public T adminStateUp(Boolean adminStateUp) {
this.adminStateUp = adminStateUp;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.Network#getShared()
*/
public T shared(Boolean shared) {
this.shared = shared;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.Network#getExternal()
*/
public T external(Boolean external) {
this.external = external;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.Network#getNetworkType()
*/
public T networkType(NetworkType networkType) {
this.networkType = networkType;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.Network#getPhysicalNetworkName()
*/
public T physicalNetworkName(String physicalNetworkName) {
this.physicalNetworkName = physicalNetworkName;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.Network#getSegmentationId()
*/
public T segmentationId(Integer segmentationId) {
this.segmentationId = segmentationId;
return self();
}
public Network build() {
return new Network(id, tenantId, name, state, subnets, adminStateUp, shared, external, networkType == null ? null : networkType.getValue(), physicalNetworkName, segmentationId);
}
public T fromNetwork(Network in) {
return super.fromReference(in)
.state(in.getState())
.subnets(in.getSubnets())
.adminStateUp(in.getAdminStateUp())
.shared(in.getShared())
.external(in.getExternal())
.networkType(in.getNetworkType())
.physicalNetworkName(in.getPhysicalNetworkName())
.segmentationId(in.getSegmentationId());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
}

View File

@ -0,0 +1,46 @@
/*
* 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_0.domain;
/**
* The type of Network
*
* @author Nick Livens
*/
public enum NetworkType {
LOCAL("local"), FLAT("flat"), VLAN("vlan"), GRE("gre");
private String value;
private NetworkType(String value) {
this.value = value;
}
public String getValue() {
return value;
}
public static NetworkType fromValue(String value) {
for (NetworkType networkType : values()) {
if (networkType.getValue().equalsIgnoreCase(value))
return networkType;
}
return null;
}
}

View File

@ -0,0 +1,234 @@
/*
* 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_0.domain;
import com.google.common.base.Objects;
import java.beans.ConstructorProperties;
import java.util.Set;
/**
* A Neutron port
*
* @author Nick Livens
* @see <a href="http://docs.openstack.org/api/openstack-network/1.0/content/Ports.html">api doc</a>
*/
public class Port extends ReferenceWithName {
private final State state;
private final Boolean adminStateUp;
private final String networkId;
private final String deviceId;
private final String deviceOwner;
private final String macAddress;
private final Set<IP> fixedIps;
@ConstructorProperties({
"id", "tenant_id", "name", "status", "network_id", "admin_state_up", "device_id", "device_owner", "fixed_ips", "mac_address"
})
protected Port(String id, String tenantId, String name, State state, String networkId, Boolean adminStateUp,
String deviceId, String deviceOwner, Set<IP> fixedIps, String macAddress) {
super(id, tenantId, name);
this.adminStateUp = adminStateUp;
this.state = state;
this.networkId = networkId;
this.deviceId = deviceId;
this.deviceOwner = deviceOwner;
this.fixedIps = fixedIps;
this.macAddress = macAddress;
}
/**
* @return the current state of the port
*/
public State getState() {
return this.state;
}
/**
* @return the administrative state of port. If false, port does not forward packets.
*/
public Boolean getAdminStateUp() {
return adminStateUp;
}
/**
* @return the id of the network where this port is associated with
*/
public String getNetworkId() {
return networkId;
}
/**
* @return the id of the device (e.g. server) using this port.
*/
public String getDeviceId() {
return deviceId;
}
/**
* @return the entity (e.g.: dhcp agent) using this port.
*/
public String getDeviceOwner() {
return deviceOwner;
}
/**
* @return the set of fixed ips this port has been assigned
*/
public Set<IP> getFixedIps() {
return fixedIps;
}
/**
* @return the mac address of this port
*/
public String getMacAddress() {
return macAddress;
}
@Override
public int hashCode() {
return Objects.hashCode(super.hashCode(), state, adminStateUp, networkId, deviceId, deviceOwner, fixedIps, macAddress);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Port that = Port.class.cast(obj);
return super.equals(obj)
&& Objects.equal(this.state, that.state)
&& Objects.equal(this.adminStateUp, that.adminStateUp)
&& Objects.equal(this.networkId, that.networkId)
&& Objects.equal(this.deviceId, that.deviceId)
&& Objects.equal(this.deviceOwner, that.deviceOwner)
&& Objects.equal(this.fixedIps, that.fixedIps)
&& Objects.equal(this.macAddress, that.macAddress);
}
protected Objects.ToStringHelper string() {
return super.string()
.add("state", state).add("adminStateUp", adminStateUp).add("networkId", networkId).add("deviceId", deviceId)
.add("deviceOwner", deviceOwner).add("fixedIps", fixedIps).add("macAddress", macAddress);
}
@Override
public String toString() {
return string().toString();
}
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromPort(this);
}
public static abstract class Builder<T extends Builder<T>> extends ReferenceWithName.Builder<T> {
protected String networkId;
protected String deviceId;
protected String deviceOwner;
protected String macAddress;
protected Set<IP> fixedIps;
protected State state;
protected Boolean adminStateUp;
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.Port#getState()
*/
public T state(State state) {
this.state = state;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.Port#getNetworkId()
*/
public T networkId(String networkId) {
this.networkId = networkId;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.Port#getAdminStateUp()
*/
public T adminStateUp(Boolean adminStateUp) {
this.adminStateUp = adminStateUp;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.Port#getDeviceId()
*/
public T deviceId(String deviceId) {
this.deviceId = deviceId;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.Port#getDeviceOwner()
*/
public T deviceOwner(String deviceOwner) {
this.deviceOwner = deviceOwner;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.Port#getDeviceId()
*/
public T fixedIps(Set<IP> fixedIps) {
this.fixedIps = fixedIps;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.Port#getMacAddress()
*/
public T macAddress(String macAddress) {
this.macAddress = macAddress;
return self();
}
public Port build() {
return new Port(id, tenantId, name, state, networkId, adminStateUp, deviceId, deviceOwner, fixedIps, macAddress);
}
public T fromPort(Port in) {
return super.fromReference(in)
.state(in.getState())
.networkId(in.getNetworkId())
.adminStateUp(in.getAdminStateUp())
.deviceId(in.getDeviceId())
.deviceOwner(in.getDeviceOwner())
.fixedIps(in.getFixedIps())
.macAddress(in.getMacAddress());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
}

View File

@ -0,0 +1,129 @@
/*
* 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_0.domain;
import com.google.common.base.Objects;
import java.beans.ConstructorProperties;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Base class for beans in the Neutron v2.0 api
*
* @author Nick Livens
* @see <a href="http://docs.openstack.org/api/openstack-network/2.0/content/Networks.html">api doc</a>
*/
public class Reference {
private final String id;
private final String tenantId;
@ConstructorProperties({
"id", "tenant_id"
})
protected Reference(String id, String tenantId) {
this.id = checkNotNull(id, "id");
this.tenantId = checkNotNull(tenantId, "tenantId");
}
/**
* @return the id of the entity
*/
public String getId() {
return this.id;
}
/**
* @return the id of the tenant where this entity is associated with
*/
public String getTenantId() {
return tenantId;
}
@Override
public int hashCode() {
return Objects.hashCode(id, tenantId);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Reference that = Reference.class.cast(obj);
return Objects.equal(this.id, that.id) && Objects.equal(this.tenantId, that.tenantId);
}
protected Objects.ToStringHelper string() {
return Objects.toStringHelper(this)
.add("id", id).add("tenantId", tenantId);
}
@Override
public String toString() {
return string().toString();
}
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromReference(this);
}
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected String id;
protected String tenantId;
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.Reference#getId()
*/
public T id(String id) {
this.id = id;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.Reference#getTenantId()
*/
public T tenantId(String tenantId) {
this.tenantId = tenantId;
return self();
}
public Reference build() {
return new Reference(id, tenantId);
}
public T fromReference(Reference in) {
return this.id(in.getId()).tenantId(in.getTenantId());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
}

View File

@ -0,0 +1,111 @@
/*
* 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_0.domain;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.base.Strings;
import java.beans.ConstructorProperties;
/**
* Base class for beans in the Neutron v2.0 api
*
* @author Nick Livens
* @see <a href="http://docs.openstack.org/api/openstack-network/2.0/content/Networks.html">api doc</a>
*/
public class ReferenceWithName extends Reference {
private final String name;
@ConstructorProperties({
"id", "tenant_id", "name"
})
protected ReferenceWithName(String id, String tenantId, String name) {
super(id, tenantId);
this.name = Strings.nullToEmpty(name);
}
/**
* @return the name of the entity
*/
public String getName() {
return name;
}
@Override
public int hashCode() {
return Objects.hashCode(super.hashCode(), name);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
ReferenceWithName that = ReferenceWithName.class.cast(obj);
return super.equals(obj) && Objects.equal(this.name, that.name);
}
protected ToStringHelper string() {
return super.string().add("name", name);
}
@Override
public String toString() {
return string().toString();
}
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromReferenceWithName(this);
}
public static abstract class Builder<T extends Builder<T>> extends Reference.Builder<T> {
protected abstract T self();
protected String name;
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.ReferenceWithName#getName()
*/
public T name(String name) {
this.name = name;
return self();
}
public ReferenceWithName build() {
return new ReferenceWithName(id, tenantId, name);
}
public T fromReferenceWithName(ReferenceWithName in) {
return super.fromReference(in).name(in.getName());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
}

View File

@ -0,0 +1,29 @@
/*
* 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_0.domain;
/**
* The possible state of an entity
*
* @author Nick Livens
* @see <a href="http://docs.openstack.org/api/openstack-network/2.0/content/Concepts-d1e369.html">api doc</a>
*/
public enum State {
ACTIVE, DOWN, BUILD, ERROR
}

View File

@ -0,0 +1,264 @@
/*
* 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_0.domain;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet;
import java.beans.ConstructorProperties;
import java.util.Collection;
import java.util.Set;
/**
* A Neutron network
*
* @author Nick Livens
* @see <a href="http://docs.openstack.org/api/openstack-network/2.0/content/Subnets.html">api doc</a>
*/
public class Subnet extends ReferenceWithName {
private final String networkId;
private final String gatewayIp;
private final Integer ipVersion;
private final String cidr;
private final Set<AllocationPool> allocationPools;
private final Boolean enableDhcp;
private final Set<String> dnsNameServers;
private final Set<HostRoute> hostRoutes;
@ConstructorProperties({
"id", "tenant_id", "name", "network_id", "gateway_ip", "ip_version", "cidr", "allocation_pools", "enable_dhcp", "dns_nameservers", "host_routes"
})
protected Subnet(String id, String tenantId, String name, String networkId,
String gatewayIp, Integer ipVersion, String cidr, Set<AllocationPool> allocationPools,
Boolean enableDhcp, Set<String> dnsNameServers, Set<HostRoute> hostRoutes) {
super(id, tenantId, name);
this.networkId = networkId;
this.gatewayIp = gatewayIp;
this.ipVersion = ipVersion;
this.cidr = cidr;
this.allocationPools = allocationPools != null ? ImmutableSet.copyOf(allocationPools) : ImmutableSet.<AllocationPool>of();
this.enableDhcp = enableDhcp;
this.dnsNameServers = dnsNameServers != null ? ImmutableSet.copyOf(dnsNameServers) : ImmutableSet.<String>of();
this.hostRoutes = hostRoutes != null ? ImmutableSet.copyOf(hostRoutes) : ImmutableSet.<HostRoute>of();
}
/**
* @return the id of the network this subnet is associated with
*/
public String getNetworkId() {
return networkId;
}
/**
* @return the default gateway used by devices in this subnet
*/
public String getGatewayIp() {
return gatewayIp;
}
/**
* @return the ip version used by this subnet
*/
public Integer getIpVersion() {
return ipVersion;
}
/**
* @return the cidr representing the IP range for this subnet, based on IP version
*/
public String getCidr() {
return cidr;
}
/**
* @return the sub-ranges of cidr available for dynamic allocation to ports
*/
public Set<AllocationPool> getAllocationPools() {
return allocationPools;
}
/**
* @return true if DHCP is enabled for this subnet, false if not.
*/
public Boolean getEnableDhcp() {
return enableDhcp;
}
/**
* @return the set of DNS name servers used by hosts in this subnet.
*/
public Set<String> getDnsNameServers() {
return dnsNameServers;
}
/**
* @return the set of routes that should be used by devices with IPs from this subnet
*/
public Set<HostRoute> getHostRoutes() {
return hostRoutes;
}
@Override
public int hashCode() {
return Objects.hashCode(super.hashCode(), networkId, gatewayIp, ipVersion, cidr,
allocationPools, enableDhcp, dnsNameServers, hostRoutes);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Subnet that = Subnet.class.cast(obj);
return super.equals(obj)
&& Objects.equal(this.networkId, that.networkId)
&& Objects.equal(this.gatewayIp, that.gatewayIp)
&& Objects.equal(this.ipVersion, that.ipVersion)
&& Objects.equal(this.cidr, that.cidr)
&& Objects.equal(this.allocationPools, that.allocationPools)
&& Objects.equal(this.enableDhcp, that.enableDhcp)
&& Objects.equal(this.dnsNameServers, that.dnsNameServers)
&& Objects.equal(this.hostRoutes, that.hostRoutes);
}
protected ToStringHelper string() {
return super.string()
.add("networkId", networkId)
.add("gatewayIp", gatewayIp)
.add("ipVersion", ipVersion)
.add("cidr", cidr)
.add("enableDHCP", enableDhcp)
.add("allocationPools", allocationPools)
.add("dnsNameServers", dnsNameServers)
.add("hostRoutes", hostRoutes);
}
@Override
public String toString() {
return string().toString();
}
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromSubnet(this);
}
public static abstract class Builder<T extends Builder<T>> extends ReferenceWithName.Builder<T> {
protected String networkId;
protected String gatewayIp;
protected Integer ipVersion;
protected String cidr;
protected Set<AllocationPool> allocationPools;
protected Boolean enableDhcp;
protected Set<String> dnsNameServers;
protected Set<HostRoute> hostRoutes;
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.Subnet#getNetworkId()
*/
public T networkId(String networkId) {
this.networkId = networkId;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.Subnet#getGatewayIp()
*/
public T gatewayIp(String gatewayIp) {
this.gatewayIp = gatewayIp;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.Subnet#getIpVersion()
*/
public T ipVersion(Integer ipVersion) {
this.ipVersion = ipVersion;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.Subnet#getCidr()
*/
public T cidr(String cidr) {
this.cidr = cidr;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.Subnet#getAllocationPools()
*/
public T allocationPools(Collection<AllocationPool> allocationPools) {
this.allocationPools = ImmutableSet.copyOf(allocationPools);
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.Subnet#getEnableDhcp()
*/
public T enableDhcp(Boolean enableDhcp) {
this.enableDhcp = enableDhcp;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.Subnet#getDnsNameServers()
*/
public T dnsNameServers(Collection<String> dnsNameServers) {
this.dnsNameServers = ImmutableSet.copyOf(dnsNameServers);
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.domain.Subnet#getHostRoutes()
*/
public T hostRoutes(Collection<HostRoute> hostRoutes) {
this.hostRoutes = ImmutableSet.copyOf(hostRoutes);
return self();
}
public Subnet build() {
return new Subnet(id, tenantId, name, networkId, gatewayIp, ipVersion, cidr, allocationPools, enableDhcp, dnsNameServers, hostRoutes);
}
public T fromSubnet(Subnet in) {
return super.fromReference(in)
.networkId(in.getNetworkId())
.gatewayIp(in.getGatewayIp())
.ipVersion(in.getIpVersion())
.cidr(in.getCidr())
.allocationPools(in.getAllocationPools())
.enableDhcp(in.getEnableDhcp())
.dnsNameServers(in.getDnsNameServers())
.hostRoutes(in.getHostRoutes());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
}

View File

@ -0,0 +1,172 @@
/**
* 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_0.features;
import com.google.common.collect.FluentIterable;
import org.jclouds.Fallbacks;
import org.jclouds.collect.PagedIterable;
import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection;
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
import org.jclouds.openstack.neutron.v2_0.domain.Network;
import org.jclouds.openstack.neutron.v2_0.domain.ReferenceWithName;
import org.jclouds.openstack.neutron.v2_0.functions.ParseNetworkDetails;
import org.jclouds.openstack.neutron.v2_0.functions.ParseNetworks;
import org.jclouds.openstack.neutron.v2_0.options.CreateNetworkBulkOptions;
import org.jclouds.openstack.neutron.v2_0.options.CreateNetworkOptions;
import org.jclouds.openstack.neutron.v2_0.options.UpdateNetworkOptions;
import org.jclouds.openstack.v2_0.options.PaginationOptions;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.Transform;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.core.MediaType;
import static org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import static org.jclouds.openstack.keystone.v2_0.KeystoneFallbacks.EmptyPaginatedCollectionOnNotFoundOr404;
/**
* Provides synchronous access to Network operations on the openstack Neutron API.
* <p/>
* Each tenant can define one or more networks. A network is a virtual isolated layer-2 broadcast domain reserved to the
* tenant. A tenant can create several ports for a network, and plug virtual interfaces into these ports.
*
* @author Adam Lowe
* @author Nick Livens
* @see <a href=
* "http://docs.openstack.org/api/openstack-network/2.0/content/Networks.html">api doc</a>
*/
@Path("/v2.0/networks")
@RequestFilters(AuthenticateRequest.class)
@Consumes(MediaType.APPLICATION_JSON)
public interface NetworkApi {
/**
* Returns the list of all networks currently defined in Neutron for the current tenant. The list provides the unique
* identifier of each network configured for the tenant.
*
* @return the list of all network references configured for the tenant
*/
@Named("network:list")
@GET
@ResponseParser(ParseNetworks.class)
@Transform(ParseNetworks.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
@QueryParams(keys = {"fields", "fields", "fields"}, values = {"id", "tenant_id", "name"})
PagedIterable<? extends ReferenceWithName> list();
@Named("network:list")
@GET
@ResponseParser(ParseNetworks.class)
@Fallback(EmptyPaginatedCollectionOnNotFoundOr404.class)
@QueryParams(keys = {"fields", "fields", "fields"}, values = {"id", "tenant_id", "name"})
PaginatedCollection<? extends ReferenceWithName> list(PaginationOptions options);
/**
* Returns all networks currently defined in Neutron for the current tenant.
*
* @return the list of all networks configured for the tenant
*/
@Named("network:list")
@GET
@ResponseParser(ParseNetworkDetails.class)
@Transform(ParseNetworkDetails.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<? extends Network> listInDetail();
@Named("network:list")
@GET
@ResponseParser(ParseNetworkDetails.class)
@Fallback(EmptyPaginatedCollectionOnNotFoundOr404.class)
PaginatedCollection<? extends Network> listInDetail(PaginationOptions options);
/**
* Return a specific network
*
* @param id the id of the network to return
* @return Network or null if not found
*/
@Named("network:get")
@GET
@Path("/{id}")
@SelectJson("network")
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
Network get(@PathParam("id") String id);
/**
* Create a new network with the specified type
*
* @param options optional arguments
* @return a reference of the newly-created network
*/
@Named("network:create")
@POST
@SelectJson("network")
@MapBinder(CreateNetworkOptions.class)
Network create(CreateNetworkOptions... options);
/**
* Create multiple networks
*
* @param networks the bulk of networks to create
* @return list of references of the newly-created networks
*/
@Named("network:createBulk")
@POST
@SelectJson("networks")
@MapBinder(CreateNetworkBulkOptions.class)
FluentIterable<? extends Network> createBulk(CreateNetworkBulkOptions networks);
/**
* Update a network
*
* @param id the id of the network to update
* @param options the attributes to update
* @return true if update successful, false if not
*/
@Named("network:update")
@PUT
@Path("/{id}")
@MapBinder(UpdateNetworkOptions.class)
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
boolean update(@PathParam("id") String id, UpdateNetworkOptions... options);
/**
* Deletes the specified network
*
* @param id the id of the network to delete
* @return true if delete was successful, false if not
*/
@Named("network:delete")
@DELETE
@Path("/{id}")
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
boolean delete(@PathParam("id") String id);
}

View File

@ -0,0 +1,175 @@
/**
* 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_0.features;
import com.google.common.collect.FluentIterable;
import org.jclouds.Fallbacks;
import org.jclouds.collect.PagedIterable;
import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection;
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
import org.jclouds.openstack.neutron.v2_0.domain.Port;
import org.jclouds.openstack.neutron.v2_0.domain.ReferenceWithName;
import org.jclouds.openstack.neutron.v2_0.functions.ParsePortDetails;
import org.jclouds.openstack.neutron.v2_0.functions.ParsePorts;
import org.jclouds.openstack.neutron.v2_0.options.CreatePortBulkOptions;
import org.jclouds.openstack.neutron.v2_0.options.CreatePortOptions;
import org.jclouds.openstack.neutron.v2_0.options.UpdatePortOptions;
import org.jclouds.openstack.v2_0.options.PaginationOptions;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.Transform;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.core.MediaType;
import static org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import static org.jclouds.openstack.keystone.v2_0.KeystoneFallbacks.EmptyPaginatedCollectionOnNotFoundOr404;
/**
* Provides synchronous access to Port operations on the openstack Neutron API.
* <p/>
* A port represents a virtual switch port on a logical network switch where all the interfaces attached to a given network are connected.
* <p/>
* A port has an administrative state which is either 'DOWN' or 'ACTIVE'. Ports which are administratively down will not be able to receive/send traffic.
* @author Nick Livens
* @see <a href=
* "http://docs.openstack.org/api/openstack-network/2.0/content/Ports.html">api doc</a>
*/
@Path("/v2.0/ports")
@RequestFilters(AuthenticateRequest.class)
@Consumes(MediaType.APPLICATION_JSON)
public interface PortApi {
/**
* Returns the list of all ports currently defined in Neutron for the current tenant. The list provides the unique
* identifier of each network configured for the tenant.
*
* @return the list of all port references configured for the tenant
*/
@Named("port:list")
@GET
@ResponseParser(ParsePorts.class)
@Transform(ParsePorts.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
@QueryParams(keys = {"fields", "fields", "fields"}, values = {"id", "tenant_id", "name"})
PagedIterable<? extends ReferenceWithName> list();
@Named("port:list")
@GET
@ResponseParser(ParsePorts.class)
@Fallback(EmptyPaginatedCollectionOnNotFoundOr404.class)
@QueryParams(keys = {"fields", "fields", "fields"}, values = {"id", "tenant_id", "name"})
PaginatedCollection<? extends ReferenceWithName> list(PaginationOptions options);
/**
* Returns the set of ports currently defined in Neutron for the requested network.
*
* @return the list of all ports configured for the tenant
*/
@Named("port:list")
@GET
@ResponseParser(ParsePortDetails.class)
@Transform(ParsePortDetails.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<? extends Port> listInDetail();
@Named("port:list")
@GET
@ResponseParser(ParsePortDetails.class)
@Fallback(EmptyPaginatedCollectionOnNotFoundOr404.class)
PaginatedCollection<? extends Port> listInDetail(PaginationOptions options);
/**
* Returns the specific port
*
* @param id the id of the port to return
* @return Port or null if not found
*/
@Named("port:get")
@GET
@Path("/{id}")
@SelectJson("port")
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
Port get(@PathParam("id") String id);
/**
* Create a new port in the specified network
*
* @param networkId the id of the network to associate this port with
* @param options optional arguments
* @return a reference of the newly-created port
*/
@Named("port:create")
@POST
@SelectJson("port")
@MapBinder(CreatePortOptions.class)
Port create(@PayloadParam("network_id") String networkId, CreatePortOptions... options);
/**
* Create multiple ports
*
* @param ports the bulk of ports to create
* @return list of references of the newly-created ports
*/
@Named("port:createBulk")
@POST
@SelectJson("ports")
@MapBinder(CreatePortBulkOptions.class)
FluentIterable<? extends Port> createBulk(CreatePortBulkOptions ports);
/**
* Update a port
*
* @param id the id of the port to update
* @param options the attributes to update
* @return true if update successful, false if not
*/
@Named("port:update")
@PUT
@Path("/{id}")
@MapBinder(UpdatePortOptions.class)
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
boolean update(@PathParam("id") String id, UpdatePortOptions... options);
/**
* Delete a port
*
* @param id the id of the port to delete
* @return true if delete successful, false if not
*/
@Named("port:delete")
@DELETE
@Path("/{id}")
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
boolean delete(@PathParam("id") String id);
}

View File

@ -0,0 +1,174 @@
/**
* 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_0.features;
import com.google.common.collect.FluentIterable;
import org.jclouds.Fallbacks;
import org.jclouds.collect.PagedIterable;
import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection;
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
import org.jclouds.openstack.neutron.v2_0.domain.ReferenceWithName;
import org.jclouds.openstack.neutron.v2_0.domain.Subnet;
import org.jclouds.openstack.neutron.v2_0.functions.ParseSubnetDetails;
import org.jclouds.openstack.neutron.v2_0.functions.ParseSubnets;
import org.jclouds.openstack.neutron.v2_0.options.CreateSubnetBulkOptions;
import org.jclouds.openstack.neutron.v2_0.options.CreateSubnetOptions;
import org.jclouds.openstack.neutron.v2_0.options.UpdateSubnetOptions;
import org.jclouds.openstack.v2_0.options.PaginationOptions;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.Transform;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.core.MediaType;
import static org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import static org.jclouds.openstack.keystone.v2_0.KeystoneFallbacks.EmptyPaginatedCollectionOnNotFoundOr404;
/**
* Provides synchronous access to Subnet operations on the Openstack Neutron API.
*
* @author Nick Livens
* @see <a href=
* "http://docs.openstack.org/api/openstack-network/2.0/content/Subnets.html">api doc</a>
*/
@Path("/v2.0/subnets")
@RequestFilters(AuthenticateRequest.class)
@Consumes(MediaType.APPLICATION_JSON)
public interface SubnetApi {
/**
* Returns the list of all subnets currently defined in Neutron for the current tenant. The list provides the unique
* identifier of each subnet configured for the tenant.
*
* @return the list of all subnet references configured for the tenant
*/
@Named("subnet:list")
@GET
@ResponseParser(ParseSubnets.class)
@Transform(ParseSubnets.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
@QueryParams(keys = {"fields", "fields", "fields"}, values = {"id", "tenant_id", "name"})
PagedIterable<? extends ReferenceWithName> list();
@Named("subnet:list")
@GET
@ResponseParser(ParseSubnets.class)
@Fallback(EmptyPaginatedCollectionOnNotFoundOr404.class)
@QueryParams(keys = {"fields", "fields", "fields"}, values = {"id", "tenant_id", "name"})
PaginatedCollection<? extends ReferenceWithName> list(PaginationOptions options);
/**
* Returns all subnets currently defined in Neutron for the current tenant.
*
* @return the list of all subnets configured for the tenant
*/
@Named("subnet:list")
@GET
@ResponseParser(ParseSubnetDetails.class)
@Transform(ParseSubnetDetails.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<? extends Subnet> listInDetail();
@Named("subnet:list")
@GET
@ResponseParser(ParseSubnetDetails.class)
@Fallback(EmptyPaginatedCollectionOnNotFoundOr404.class)
PaginatedCollection<? extends Subnet> listInDetail(PaginationOptions options);
/**
* Returns the specific Subnet.
*
* @param id the id of the subnet to return
* @return Subnet or null if not found
*/
@Named("subnet:get")
@GET
@Path("/{id}")
@SelectJson("subnet")
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
Subnet get(@PathParam("id") String id);
/**
* Create a subnet within a specified network
*
* @param networkId the id of the network to associate the subnet with
* @param ipVersion the ip version of this subnet
* @param cidr the cidr for this subnet
* @param options optional arugments
* @return a reference of the newly-created subnet
*/
@Named("subnet:create")
@POST
@SelectJson("subnet")
@MapBinder(CreateSubnetOptions.class)
Subnet create(@PayloadParam("network_id") String networkId, @PayloadParam("ip_version") Integer ipVersion,
@PayloadParam("cidr") String cidr, CreateSubnetOptions... options);
/**
* Create multiple subnets
*
* @param subnets the bulk of subnets to create
* @return list of references of the newly-created subnets
*/
@Named("subnet:createBulk")
@POST
@SelectJson("subnets")
@MapBinder(CreateSubnetBulkOptions.class)
FluentIterable<? extends Subnet> createBulk(CreateSubnetBulkOptions subnets);
/**
* Update a subnet
*
* @param id the id of the subnet to update
* @param options the attributes to update
* @return true if update was successful, false if not
*/
@Named("subnet:update")
@PUT
@Path("/{id}")
@MapBinder(UpdateSubnetOptions.class)
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
boolean update(@PathParam("id") String id, UpdateSubnetOptions... options);
/**
* Delete a subnet
*
* @param id the id of the subnet to delete
* @return true if delete successful, false if not
*/
@Named("subnet:delete")
@DELETE
@Path("/{id}")
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
boolean delete(@PathParam("id") String id);
}

View File

@ -0,0 +1,91 @@
/*
* 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_0.functions;
import com.google.common.annotations.Beta;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.inject.TypeLiteral;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.internal.Arg0ToPagedIterable;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.json.Json;
import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection;
import org.jclouds.openstack.neutron.v2_0.NeutronApi;
import org.jclouds.openstack.neutron.v2_0.domain.Network;
import org.jclouds.openstack.neutron.v2_0.features.NetworkApi;
import org.jclouds.openstack.neutron.v2_0.functions.ParseNetworkDetails.Networks;
import org.jclouds.openstack.v2_0.domain.Link;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.beans.ConstructorProperties;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.openstack.v2_0.options.PaginationOptions.Builder.marker;
/**
* @author Nick Livens
*/
@Beta
@Singleton
public class ParseNetworkDetails extends ParseJson<Networks> {
static class Networks extends PaginatedCollection<Network> {
@ConstructorProperties({ "networks", "networks_links" })
protected Networks(Iterable<Network> networks, Iterable<Link> networks_links) {
super(networks, networks_links);
}
}
@Inject
public ParseNetworkDetails(Json json) {
super(json, TypeLiteral.get(Networks.class));
}
public static class ToPagedIterable extends Arg0ToPagedIterable.FromCaller<Network, ToPagedIterable> {
private final NeutronApi api;
@Inject
protected ToPagedIterable(NeutronApi api) {
this.api = checkNotNull(api, "api");
}
@Override
protected Function<Object, IterableWithMarker<Network>> markerToNextForArg0(Optional<Object> arg0) {
String zone = arg0.isPresent() ? arg0.get().toString() : null;
final NetworkApi networkApi = api.getNetworkApiForZone(zone);
return new Function<Object, IterableWithMarker<Network>>() {
@SuppressWarnings("unchecked")
@Override
public IterableWithMarker<Network> apply(Object input) {
return IterableWithMarker.class.cast(networkApi.listInDetail(marker(input.toString())));
}
@Override
public String toString() {
return "list()";
}
};
}
}
}

View File

@ -0,0 +1,91 @@
/*
* 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_0.functions;
import com.google.common.annotations.Beta;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.inject.TypeLiteral;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.internal.Arg0ToPagedIterable;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.json.Json;
import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection;
import org.jclouds.openstack.neutron.v2_0.NeutronApi;
import org.jclouds.openstack.neutron.v2_0.domain.ReferenceWithName;
import org.jclouds.openstack.neutron.v2_0.features.NetworkApi;
import org.jclouds.openstack.neutron.v2_0.functions.ParseNetworks.Networks;
import org.jclouds.openstack.v2_0.domain.Link;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.beans.ConstructorProperties;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.openstack.v2_0.options.PaginationOptions.Builder.marker;
/**
* @author Nick Livens
*/
@Beta
@Singleton
public class ParseNetworks extends ParseJson<Networks> {
static class Networks extends PaginatedCollection<ReferenceWithName> {
@ConstructorProperties({ "networks", "networks_links" })
protected Networks(Iterable<ReferenceWithName> networks, Iterable<Link> networks_links) {
super(networks, networks_links);
}
}
@Inject
public ParseNetworks(Json json) {
super(json, TypeLiteral.get(Networks.class));
}
public static class ToPagedIterable extends Arg0ToPagedIterable.FromCaller<ReferenceWithName, ToPagedIterable> {
private final NeutronApi api;
@Inject
protected ToPagedIterable(NeutronApi api) {
this.api = checkNotNull(api, "api");
}
@Override
protected Function<Object, IterableWithMarker<ReferenceWithName>> markerToNextForArg0(Optional<Object> arg0) {
String zone = arg0.isPresent() ? arg0.get().toString() : null;
final NetworkApi networkApi = api.getNetworkApiForZone(zone);
return new Function<Object, IterableWithMarker<ReferenceWithName>>() {
@SuppressWarnings("unchecked")
@Override
public IterableWithMarker<ReferenceWithName> apply(Object input) {
return IterableWithMarker.class.cast(networkApi.list(marker(input.toString())));
}
@Override
public String toString() {
return "list()";
}
};
}
}
}

View File

@ -0,0 +1,92 @@
/*
* 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_0.functions;
import com.google.common.annotations.Beta;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.inject.TypeLiteral;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.internal.Arg0ToPagedIterable;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.json.Json;
import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection;
import org.jclouds.openstack.neutron.v2_0.NeutronApi;
import org.jclouds.openstack.neutron.v2_0.domain.Port;
import org.jclouds.openstack.neutron.v2_0.domain.ReferenceWithName;
import org.jclouds.openstack.neutron.v2_0.features.PortApi;
import org.jclouds.openstack.neutron.v2_0.functions.ParsePortDetails.Ports;
import org.jclouds.openstack.v2_0.domain.Link;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.beans.ConstructorProperties;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.openstack.v2_0.options.PaginationOptions.Builder.marker;
/**
* @author Nick Livens
*/
@Beta
@Singleton
public class ParsePortDetails extends ParseJson<Ports> {
static class Ports extends PaginatedCollection<Port> {
@ConstructorProperties({ "ports", "ports_links" })
protected Ports(Iterable<Port> ports, Iterable<Link> ports_links) {
super(ports, ports_links);
}
}
@Inject
public ParsePortDetails(Json json) {
super(json, TypeLiteral.get(Ports.class));
}
public static class ToPagedIterable extends Arg0ToPagedIterable.FromCaller<ReferenceWithName, ToPagedIterable> {
private final NeutronApi api;
@Inject
protected ToPagedIterable(NeutronApi api) {
this.api = checkNotNull(api, "api");
}
@Override
protected Function<Object, IterableWithMarker<ReferenceWithName>> markerToNextForArg0(Optional<Object> arg0) {
String zone = arg0.isPresent() ? arg0.get().toString() : null;
final PortApi portApi = api.getPortApiForZone(zone);
return new Function<Object, IterableWithMarker<ReferenceWithName>>() {
@SuppressWarnings("unchecked")
@Override
public IterableWithMarker<ReferenceWithName> apply(Object input) {
return IterableWithMarker.class.cast(portApi.listInDetail(marker(input.toString())));
}
@Override
public String toString() {
return "list()";
}
};
}
}
}

View File

@ -0,0 +1,92 @@
/*
* 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_0.functions;
import com.google.common.annotations.Beta;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.inject.TypeLiteral;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.internal.Arg0ToPagedIterable;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.json.Json;
import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection;
import org.jclouds.openstack.neutron.v2_0.NeutronApi;
import org.jclouds.openstack.neutron.v2_0.domain.ReferenceWithName;
import org.jclouds.openstack.neutron.v2_0.features.NetworkApi;
import org.jclouds.openstack.neutron.v2_0.features.PortApi;
import org.jclouds.openstack.neutron.v2_0.functions.ParsePorts.Ports;
import org.jclouds.openstack.v2_0.domain.Link;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.beans.ConstructorProperties;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.openstack.v2_0.options.PaginationOptions.Builder.marker;
/**
* @author Nick Livens
*/
@Beta
@Singleton
public class ParsePorts extends ParseJson<Ports> {
static class Ports extends PaginatedCollection<ReferenceWithName> {
@ConstructorProperties({ "ports", "ports_links" })
protected Ports(Iterable<ReferenceWithName> ports, Iterable<Link> ports_links) {
super(ports, ports_links);
}
}
@Inject
public ParsePorts(Json json) {
super(json, TypeLiteral.get(Ports.class));
}
public static class ToPagedIterable extends Arg0ToPagedIterable.FromCaller<ReferenceWithName, ToPagedIterable> {
private final NeutronApi api;
@Inject
protected ToPagedIterable(NeutronApi api) {
this.api = checkNotNull(api, "api");
}
@Override
protected Function<Object, IterableWithMarker<ReferenceWithName>> markerToNextForArg0(Optional<Object> arg0) {
String zone = arg0.isPresent() ? arg0.get().toString() : null;
final PortApi portApi = api.getPortApiForZone(zone);
return new Function<Object, IterableWithMarker<ReferenceWithName>>() {
@SuppressWarnings("unchecked")
@Override
public IterableWithMarker<ReferenceWithName> apply(Object input) {
return IterableWithMarker.class.cast(portApi.list(marker(input.toString())));
}
@Override
public String toString() {
return "list()";
}
};
}
}
}

View File

@ -0,0 +1,91 @@
/*
* 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_0.functions;
import com.google.common.annotations.Beta;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.inject.TypeLiteral;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.internal.Arg0ToPagedIterable;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.json.Json;
import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection;
import org.jclouds.openstack.neutron.v2_0.NeutronApi;
import org.jclouds.openstack.neutron.v2_0.domain.Subnet;
import org.jclouds.openstack.neutron.v2_0.features.SubnetApi;
import org.jclouds.openstack.neutron.v2_0.functions.ParseSubnetDetails.Subnets;
import org.jclouds.openstack.v2_0.domain.Link;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.beans.ConstructorProperties;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.openstack.v2_0.options.PaginationOptions.Builder.marker;
/**
* @author Nick Livens
*/
@Beta
@Singleton
public class ParseSubnetDetails extends ParseJson<Subnets> {
static class Subnets extends PaginatedCollection<Subnet> {
@ConstructorProperties({ "subnets", "subnets_links" })
protected Subnets(Iterable<Subnet> subnets, Iterable<Link> subnets_links) {
super(subnets, subnets_links);
}
}
@Inject
public ParseSubnetDetails(Json json) {
super(json, TypeLiteral.get(Subnets.class));
}
public static class ToPagedIterable extends Arg0ToPagedIterable.FromCaller<Subnet, ToPagedIterable> {
private final NeutronApi api;
@Inject
protected ToPagedIterable(NeutronApi api) {
this.api = checkNotNull(api, "api");
}
@Override
protected Function<Object, IterableWithMarker<Subnet>> markerToNextForArg0(Optional<Object> arg0) {
String zone = arg0.isPresent() ? arg0.get().toString() : null;
final SubnetApi subnetApi = api.getSubnetApiForZone(zone);
return new Function<Object, IterableWithMarker<Subnet>>() {
@SuppressWarnings("unchecked")
@Override
public IterableWithMarker<Subnet> apply(Object input) {
return IterableWithMarker.class.cast(subnetApi.listInDetail(marker(input.toString())));
}
@Override
public String toString() {
return "list()";
}
};
}
}
}

View File

@ -0,0 +1,91 @@
/*
* 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_0.functions;
import com.google.common.annotations.Beta;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.inject.TypeLiteral;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.internal.Arg0ToPagedIterable;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.json.Json;
import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection;
import org.jclouds.openstack.neutron.v2_0.NeutronApi;
import org.jclouds.openstack.neutron.v2_0.domain.ReferenceWithName;
import org.jclouds.openstack.neutron.v2_0.features.SubnetApi;
import org.jclouds.openstack.neutron.v2_0.functions.ParseSubnets.Subnets;
import org.jclouds.openstack.v2_0.domain.Link;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.beans.ConstructorProperties;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.openstack.v2_0.options.PaginationOptions.Builder.marker;
/**
* @author Nick Livens
*/
@Beta
@Singleton
public class ParseSubnets extends ParseJson<Subnets> {
static class Subnets extends PaginatedCollection<ReferenceWithName> {
@ConstructorProperties({ "subnets", "subnets_links" })
protected Subnets(Iterable<ReferenceWithName> subnets, Iterable<Link> subnets_links) {
super(subnets, subnets_links);
}
}
@Inject
public ParseSubnets(Json json) {
super(json, TypeLiteral.get(Subnets.class));
}
public static class ToPagedIterable extends Arg0ToPagedIterable.FromCaller<ReferenceWithName, ToPagedIterable> {
private final NeutronApi api;
@Inject
protected ToPagedIterable(NeutronApi api) {
this.api = checkNotNull(api, "api");
}
@Override
protected Function<Object, IterableWithMarker<ReferenceWithName>> markerToNextForArg0(Optional<Object> arg0) {
String zone = arg0.isPresent() ? arg0.get().toString() : null;
final SubnetApi subnetApi = api.getSubnetApiForZone(zone);
return new Function<Object, IterableWithMarker<ReferenceWithName>>() {
@SuppressWarnings("unchecked")
@Override
public IterableWithMarker<ReferenceWithName> apply(Object input) {
return IterableWithMarker.class.cast(subnetApi.list(marker(input.toString())));
}
@Override
public String toString() {
return "list()";
}
};
}
}
}

View File

@ -0,0 +1,62 @@
/*
* 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_0.handlers;
import static org.jclouds.http.HttpUtils.closeClientButKeepContentStream;
import javax.inject.Singleton;
import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpResponseException;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ResourceNotFoundException;
/**
* This will parse and set an appropriate exception on the command object.
*
* @author Nick Livens
*
*/
@Singleton
public class NeutronErrorHandler implements HttpErrorHandler {
public void handleError(HttpCommand command, HttpResponse response) {
// it is important to always read fully and close streams
byte[] data = closeClientButKeepContentStream(response);
String message = data != null ? new String(data) : null;
Exception exception = message != null ? new HttpResponseException(command, response, message)
: new HttpResponseException(command, response);
message = message != null ? message : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(),
response.getStatusLine());
switch (response.getStatusCode()) {
case 400:
break;
case 401:
case 403:
exception = new AuthorizationException(message, exception);
break;
case 404:
if (!command.getCurrentRequest().getMethod().equals("DELETE")) {
exception = new ResourceNotFoundException(message, exception);
}
break;
}
command.setException(exception);
}
}

View File

@ -0,0 +1,142 @@
/**
* 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_0.options;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.jclouds.http.HttpRequest;
import org.jclouds.openstack.neutron.v2_0.domain.BulkNetwork;
import org.jclouds.openstack.neutron.v2_0.domain.NetworkType;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToJsonPayload;
import javax.inject.Inject;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.openstack.neutron.v2_0.options.CreateNetworkOptions.CreateNetworkRequest;
/**
* @author Nick Livens
*/
public class CreateNetworkBulkOptions implements MapBinder {
@Inject
private BindToJsonPayload jsonBinder;
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromCreateNetworkOptions(this);
}
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected List<BulkNetwork> networks;
/**
* @see org.jclouds.openstack.neutron.v2_0.options.CreateNetworkBulkOptions#getNetworks()
*/
public T networks(Collection<BulkNetwork> networks) {
this.networks = ImmutableList.copyOf(networks);
return self();
}
public CreateNetworkBulkOptions build() {
return new CreateNetworkBulkOptions(networks);
}
public T fromCreateNetworkOptions(CreateNetworkBulkOptions in) {
return this.networks(in.getNetworks());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final List<BulkNetwork> networks;
protected CreateNetworkBulkOptions() {
this.networks = Lists.newArrayList();
}
public CreateNetworkBulkOptions(List<BulkNetwork> networks) {
this.networks = networks != null ? ImmutableList.copyOf(networks) : Lists.<BulkNetwork>newArrayList();
}
/**
* @return the list of networks to create
*/
public List<BulkNetwork> getNetworks() {
return networks;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
List<CreateNetworkRequest> createNetworkRequests = Lists.newArrayList();
for (BulkNetwork network : this.networks) {
if (network.getNetworkType() != null) {
//Validations for each NetworkType
if (network.getNetworkType() == NetworkType.FLAT) {
checkNotNull(network.getPhysicalNetworkName(), "physicalNetworkName must be present when networkType=FLAT");
} else if (network.getNetworkType() == NetworkType.VLAN) {
checkNotNull(network.getPhysicalNetworkName(), "physicalNetworkName must be present when networkType=VLAN");
checkNotNull(network.getSegmentationId(), "segmentationId must be present when networkType=VLAN");
} else if (network.getNetworkType() == NetworkType.GRE) {
checkNotNull(network.getSegmentationId(), "segmentationId must be present when NetworkType=GRE");
}
}
CreateNetworkRequest createNetworkRequest = new CreateNetworkRequest();
if (network.getName() != null)
createNetworkRequest.name = network.getName();
if (network.getAdminStateUp() != null)
createNetworkRequest.admin_state_up = network.getAdminStateUp();
if (network.getExternal() != null)
createNetworkRequest.external = network.getExternal();
if (network.getNetworkType() != null)
createNetworkRequest.networkType = network.getNetworkType().getValue();
if (network.getPhysicalNetworkName() != null && (network.getNetworkType() == NetworkType.FLAT || network.getNetworkType() == NetworkType.VLAN))
createNetworkRequest.physicalNetworkName = network.getPhysicalNetworkName();
if (network.getSegmentationId() != null && (network.getNetworkType() == NetworkType.VLAN || network.getNetworkType() == NetworkType.GRE))
createNetworkRequest.segmentationId = network.getSegmentationId();
createNetworkRequests.add(createNetworkRequest);
}
return bindToRequest(request, ImmutableMap.of("networks", createNetworkRequests));
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
return jsonBinder.bindToRequest(request, input);
}
}

View File

@ -0,0 +1,244 @@
/**
* 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_0.options;
import com.google.common.collect.ImmutableMap;
import com.google.gson.annotations.SerializedName;
import org.jclouds.http.HttpRequest;
import org.jclouds.openstack.neutron.v2_0.domain.NetworkType;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToJsonPayload;
import javax.inject.Inject;
import java.util.Map;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Nick Livens
*/
public class CreateNetworkOptions implements MapBinder {
@Inject
private BindToJsonPayload jsonBinder;
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromCreateNetworkOptions(this);
}
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected String name;
protected Boolean adminStateUp;
protected Boolean external;
protected NetworkType networkType;
protected String physicalNetworkName;
protected Integer segmentationId;
/**
* @see org.jclouds.openstack.neutron.v2_0.options.CreateNetworkOptions#getName()
*/
public T name(String name) {
this.name = name;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.options.CreateNetworkOptions#getAdminStateUp()
*/
public T adminStateUp(Boolean adminStateUp) {
this.adminStateUp = adminStateUp;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.options.CreateNetworkOptions#getExternal()
*/
public T external(Boolean external) {
this.external = external;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.options.CreateNetworkOptions#getNetworkType()
*/
public T networkType(NetworkType networkType) {
this.networkType = networkType;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.options.CreateNetworkOptions#getPhysicalNetworkName()
*/
public T physicalNetworkName(String physicalNetworkName) {
this.physicalNetworkName = physicalNetworkName;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.options.CreateNetworkOptions#getSegmentationId()
*/
public T segmentationId(Integer segmentationId) {
this.segmentationId = segmentationId;
return self();
}
public CreateNetworkOptions build() {
return new CreateNetworkOptions(name, adminStateUp, external, networkType, physicalNetworkName, segmentationId);
}
public T fromCreateNetworkOptions(CreateNetworkOptions in) {
return this.name(in.getName())
.adminStateUp(in.getAdminStateUp())
.external(in.getExternal())
.networkType(in.getNetworkType())
.physicalNetworkName(in.getPhysicalNetworkName())
.segmentationId(in.getSegmentationId());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
protected static class CreateNetworkRequest {
protected String name;
protected Boolean admin_state_up;
@SerializedName("router:external")
protected Boolean external;
@SerializedName("provider:network_type")
protected String networkType;
@SerializedName("provider:physical_network")
protected String physicalNetworkName;
@SerializedName("provider:segmentation_id")
protected Integer segmentationId;
}
private final String name;
private final Boolean adminStateUp;
private final Boolean external;
private final NetworkType networkType;
private final String physicalNetworkName;
private final Integer segmentationId;
protected CreateNetworkOptions() {
this.name = null;
this.adminStateUp = null;
this.external = null;
this.networkType = null;
this.physicalNetworkName = null;
this.segmentationId = null;
}
public CreateNetworkOptions(String name, Boolean adminStateUp, Boolean external, NetworkType networkType, String physicalNetworkName, Integer segmentationId) {
this.name = name;
this.adminStateUp = adminStateUp;
this.external = external;
this.networkType = networkType;
this.physicalNetworkName = physicalNetworkName;
this.segmentationId = segmentationId;
}
/**
* @return the name of the network
*/
public String getName() {
return name;
}
/**
* @return the administrative state of network. If false, the network does not forward packets.
*/
public Boolean getAdminStateUp() {
return adminStateUp;
}
/**
* @return true if network is external, false if not
*/
public Boolean getExternal() {
return external;
}
/**
* @return the type of the network
*/
public NetworkType getNetworkType() {
return networkType;
}
/**
* @return the physical network name
*/
public String getPhysicalNetworkName() {
return physicalNetworkName;
}
/**
* @return the segmentation id of the network
*/
public Integer getSegmentationId() {
return segmentationId;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
if (this.networkType != null) {
//Validations for each NetworkType
if (this.networkType == NetworkType.FLAT) {
checkNotNull(this.physicalNetworkName, "physicalNetworkName must be present when networkType=FLAT");
} else if (this.networkType == NetworkType.VLAN) {
checkNotNull(this.physicalNetworkName, "physicalNetworkName must be present when networkType=VLAN");
checkNotNull(this.segmentationId, "segmentationId must be present when networkType=VLAN");
} else if (this.networkType == NetworkType.GRE) {
checkNotNull(this.segmentationId, "segmentationId must be present when NetworkType=GRE");
}
}
CreateNetworkRequest createNetworkRequest = new CreateNetworkRequest();
if (this.name != null)
createNetworkRequest.name = this.name;
if (this.adminStateUp != null)
createNetworkRequest.admin_state_up = this.adminStateUp;
if (this.external != null)
createNetworkRequest.external = this.external;
if (this.networkType != null)
createNetworkRequest.networkType = this.networkType.getValue();
if (this.physicalNetworkName != null && (networkType == NetworkType.FLAT || networkType == NetworkType.VLAN))
createNetworkRequest.physicalNetworkName = this.physicalNetworkName;
if (this.segmentationId != null && (networkType == NetworkType.VLAN || networkType == NetworkType.GRE))
createNetworkRequest.segmentationId = this.segmentationId;
return bindToRequest(request, ImmutableMap.of("network", createNetworkRequest));
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
return jsonBinder.bindToRequest(request, input);
}
}

View File

@ -0,0 +1,137 @@
/**
* 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_0.options;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.jclouds.http.HttpRequest;
import org.jclouds.openstack.neutron.v2_0.domain.BulkPort;
import org.jclouds.openstack.neutron.v2_0.domain.IP;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToJsonPayload;
import javax.inject.Inject;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Nick Livens
*/
public class CreatePortBulkOptions implements MapBinder {
@Inject
private BindToJsonPayload jsonBinder;
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromCreatePortBulkOptions(this);
}
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected List<BulkPort> ports;
/**
* @see org.jclouds.openstack.neutron.v2_0.options.CreatePortBulkOptions#getPorts()
*/
public T ports(Collection<BulkPort> ports) {
this.ports = ImmutableList.copyOf(ports);
return self();
}
public CreatePortBulkOptions build() {
return new CreatePortBulkOptions(this.ports);
}
public T fromCreatePortBulkOptions(CreatePortBulkOptions in) {
return this.ports(in.getPorts());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final List<BulkPort> ports;
protected CreatePortBulkOptions() {
this.ports = Lists.newArrayList();
}
public CreatePortBulkOptions(List<BulkPort> ports) {
this.ports = ports;
}
/**
* @return the list of ports to create
*/
public List<BulkPort> getPorts() {
return ports;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
List<CreatePortOptions.CreatePortRequest> createPortRequests = Lists.newArrayList();
for (BulkPort port : this.ports) {
CreatePortOptions.CreatePortRequest createPortRequest = new CreatePortOptions.CreatePortRequest(checkNotNull(port.getNetworkId(), "network id parameter not present"));
if (port.getName() != null)
createPortRequest.name = port.getName();
if (port.getAdminStateUp() != null)
createPortRequest.admin_state_up = port.getAdminStateUp();
if (port.getDeviceId() != null)
createPortRequest.device_id = port.getDeviceId();
if (port.getDeviceOwner() != null)
createPortRequest.device_owner = port.getDeviceOwner();
if (port.getMacAddress() != null)
createPortRequest.mac_address = port.getMacAddress();
if (!port.getFixedIps().isEmpty()) {
createPortRequest.fixed_ips = Sets.newHashSet();
for (IP fixedIp : port.getFixedIps()) {
CreatePortOptions.CreatePortRequest.IP requestIp = new CreatePortOptions.CreatePortRequest.IP();
requestIp.subnet_id = fixedIp.getSubnetId();
requestIp.ip_address = fixedIp.getIpAddress();
createPortRequest.fixed_ips.add(requestIp);
}
}
createPortRequests.add(createPortRequest);
}
return bindToRequest(request, ImmutableMap.of("ports", createPortRequests));
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
return jsonBinder.bindToRequest(request, input);
}
}

View File

@ -0,0 +1,245 @@
/**
* 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_0.options;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import org.jclouds.http.HttpRequest;
import org.jclouds.openstack.neutron.v2_0.domain.IP;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToJsonPayload;
import javax.inject.Inject;
import java.util.Map;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Nick Livens
*/
public class CreatePortOptions implements MapBinder {
@Inject
private BindToJsonPayload jsonBinder;
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromCreatePortOptions(this);
}
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected String name;
protected String deviceId;
protected String deviceOwner;
protected String macAddress;
protected Set<IP> fixedIps;
protected Boolean adminStateUp;
/**
* @see org.jclouds.openstack.neutron.v2_0.options.CreatePortOptions#getName()
*/
public T name(String name) {
this.name = name;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.options.CreatePortOptions#getDeviceId()
*/
public T deviceId(String deviceId) {
this.deviceId = deviceId;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.options.CreatePortOptions#getDeviceOwner()
*/
public T deviceOwner(String deviceOwner) {
this.deviceOwner = deviceOwner;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.options.CreatePortOptions#getMacAddress()
*/
public T macAddress(String macAddress) {
this.macAddress = macAddress;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.options.CreatePortOptions#getFixedIps()
*/
public T fixedIps(Set<IP> fixedIps) {
this.fixedIps = fixedIps;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.options.CreatePortOptions#getAdminStateUp()
*/
public T adminStateUp(Boolean adminStateUp) {
this.adminStateUp = adminStateUp;
return self();
}
public CreatePortOptions build() {
return new CreatePortOptions(name, deviceId, deviceOwner, macAddress, fixedIps, adminStateUp);
}
public T fromCreatePortOptions(CreatePortOptions options) {
return this.name(options.getName())
.deviceId(options.getDeviceId())
.deviceOwner(options.getDeviceOwner())
.macAddress(options.getMacAddress())
.fixedIps(options.getFixedIps())
.adminStateUp(options.getAdminStateUp());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
protected static class CreatePortRequest {
protected String network_id;
protected String name;
protected String device_id;
protected String device_owner;
protected String mac_address;
protected Set<IP> fixed_ips;
protected Boolean admin_state_up;
protected CreatePortRequest(String networkId) {
this.network_id = networkId;
}
protected static final class IP {
protected String ip_address;
protected String subnet_id;
}
}
private final String name;
private final String deviceId;
private final String deviceOwner;
private final String macAddress;
private final Set<IP> fixedIps;
private final Boolean adminStateUp;
protected CreatePortOptions() {
this.name = null;
this.deviceId = null;
this.deviceOwner = null;
this.macAddress = null;
this.fixedIps = Sets.newHashSet();
this.adminStateUp = null;
}
public CreatePortOptions(String name, String deviceId, String deviceOwner, String macAddress,
Set<IP> fixedIps, Boolean adminStateUp) {
this.name = name;
this.deviceId = deviceId;
this.deviceOwner = deviceOwner;
this.macAddress = macAddress;
this.fixedIps = fixedIps != null ? ImmutableSet.copyOf(fixedIps) : Sets.<IP>newHashSet();
this.adminStateUp = adminStateUp;
}
public String getName() {
return name;
}
/**
* @return the id of the device (e.g. server) which will use this port.
*/
public String getDeviceId() {
return deviceId;
}
/**
* @return the entity (e.g.: dhcp agent) who will be using this port.
*/
public String getDeviceOwner() {
return deviceOwner;
}
/**
* @return the mac address of this port
*/
public String getMacAddress() {
return macAddress;
}
/**
* @return the set of fixed ips this port will get assigned
*/
public Set<IP> getFixedIps() {
return fixedIps;
}
/**
* @return the administrative state of port. If false, port does not forward packets.
*/
public Boolean getAdminStateUp() {
return adminStateUp;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
CreatePortRequest createPortRequest = new CreatePortRequest(checkNotNull(postParams.get("network_id"), "networkId not present").toString());
if (this.name != null)
createPortRequest.name = this.name;
if (this.deviceId != null)
createPortRequest.device_id = this.deviceId;
if (this.deviceOwner != null)
createPortRequest.device_owner = this.deviceOwner;
if (this.macAddress != null)
createPortRequest.mac_address = this.macAddress;
if (!this.fixedIps.isEmpty()) {
createPortRequest.fixed_ips = Sets.newHashSet();
for (IP ip : this.fixedIps) {
CreatePortRequest.IP requestIp = new CreatePortRequest.IP();
requestIp.subnet_id = ip.getSubnetId();
requestIp.ip_address = ip.getIpAddress();
createPortRequest.fixed_ips.add(requestIp);
}
}
if (this.adminStateUp != null)
createPortRequest.admin_state_up = this.adminStateUp;
return bindToRequest(request, ImmutableMap.of("port", createPortRequest));
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
return jsonBinder.bindToRequest(request, input);
}
}

View File

@ -0,0 +1,143 @@
/**
* 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_0.options;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.jclouds.http.HttpRequest;
import org.jclouds.openstack.neutron.v2_0.domain.BulkSubnet;
import org.jclouds.openstack.neutron.v2_0.domain.HostRoute;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToJsonPayload;
import javax.inject.Inject;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Nick Livens
*/
public class CreateSubnetBulkOptions implements MapBinder {
@Inject
private BindToJsonPayload jsonBinder;
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromCreateSubnetBulkOptions(this);
}
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected List<BulkSubnet> subnets;
/**
* @see org.jclouds.openstack.neutron.v2_0.options.CreateSubnetBulkOptions#getSubnets()
*/
public T subnets(Collection<BulkSubnet> subnets) {
this.subnets = ImmutableList.copyOf(subnets);
return self();
}
public CreateSubnetBulkOptions build() {
return new CreateSubnetBulkOptions(this.subnets);
}
public T fromCreateSubnetBulkOptions(CreateSubnetBulkOptions in) {
return this.subnets(in.getSubnets());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private final List<BulkSubnet> subnets;
protected CreateSubnetBulkOptions() {
this.subnets = Lists.newArrayList();
}
public CreateSubnetBulkOptions(List<BulkSubnet> subnets) {
this.subnets = subnets != null ? ImmutableList.copyOf(subnets) : Lists.<BulkSubnet>newArrayList();
}
/**
* @return The list of subnets to create
*/
public List<BulkSubnet> getSubnets() {
return subnets;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
List<CreateSubnetOptions.CreateSubnetRequest> createSubnetRequests = Lists.newArrayList();
for (BulkSubnet subnet : subnets) {
CreateSubnetOptions.CreateSubnetRequest createSubnetRequest =
new CreateSubnetOptions.CreateSubnetRequest(
checkNotNull(subnet.getNetworkId(), "network id parameter not present"),
checkNotNull(subnet.getIpVersion(), "ip version parameter not present"),
checkNotNull(subnet.getCidr(), "cidr parameter not present")
);
if (subnet.getName() != null)
createSubnetRequest.name = subnet.getName();
if (!subnet.getAllocationPools().isEmpty())
createSubnetRequest.allocation_pools = subnet.getAllocationPools();
if (subnet.getGatewayIp() != null)
createSubnetRequest.gateway_ip = subnet.getGatewayIp();
if (subnet.getEnableDhcp() != null)
createSubnetRequest.enable_dhcp = subnet.getEnableDhcp();
if (!subnet.getDnsNameServers().isEmpty())
createSubnetRequest.dns_nameservers = subnet.getDnsNameServers();
if (!subnet.getHostRoutes().isEmpty()) {
createSubnetRequest.host_routes = Sets.newHashSet();
for (HostRoute hostRoute : subnet.getHostRoutes()) {
CreateSubnetOptions.CreateSubnetRequest.HostRoute requestHostRoute = new CreateSubnetOptions.CreateSubnetRequest.HostRoute();
requestHostRoute.destination = hostRoute.getDestinationCidr();
requestHostRoute.nexthop = hostRoute.getNextHop();
createSubnetRequest.host_routes.add(requestHostRoute);
}
}
createSubnetRequests.add(createSubnetRequest);
}
return bindToRequest(request, ImmutableMap.of("subnets", createSubnetRequests));
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
return jsonBinder.bindToRequest(request, input);
}
}

View File

@ -0,0 +1,261 @@
/**
* 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_0.options;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import org.jclouds.http.HttpRequest;
import org.jclouds.openstack.neutron.v2_0.domain.AllocationPool;
import org.jclouds.openstack.neutron.v2_0.domain.HostRoute;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToJsonPayload;
import javax.inject.Inject;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Nick Livens
*/
public class CreateSubnetOptions implements MapBinder {
@Inject
private BindToJsonPayload jsonBinder;
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromCreateSubnetOptions(this);
}
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected String name;
protected Set<AllocationPool> allocationPools;
protected String gatewayIp;
protected Boolean enableDhcp;
protected Set<String> dnsNameServers;
protected Set<HostRoute> hostRoutes;
/**
* @see org.jclouds.openstack.neutron.v2_0.options.CreateSubnetOptions#getName()
*/
public T name(String name) {
this.name = name;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.options.CreateSubnetOptions#getAllocationPools()
*/
public T allocationPools(Collection<AllocationPool> allocationPools) {
this.allocationPools = ImmutableSet.copyOf(allocationPools);
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.options.CreateSubnetOptions#getGatewayIp()
*/
public T gatewayIp(String gatewayIp) {
this.gatewayIp = gatewayIp;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.options.CreateSubnetOptions#getEnableDhcp()
*/
public T enableDhcp(Boolean enableDhcp) {
this.enableDhcp = enableDhcp;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.options.CreateSubnetOptions#getDnsNameServers()
*/
public T dnsNameServers(Collection<String> dnsNameServers) {
this.dnsNameServers = ImmutableSet.copyOf(dnsNameServers);
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.options.CreateSubnetOptions#getHostRoutes()
*/
public T hostRoutes(Collection<HostRoute> hostRoutes) {
this.hostRoutes = ImmutableSet.copyOf(hostRoutes);
return self();
}
public CreateSubnetOptions build() {
return new CreateSubnetOptions(name, allocationPools, gatewayIp, enableDhcp, dnsNameServers, hostRoutes);
}
public T fromCreateSubnetOptions(CreateSubnetOptions in) {
return this.name(in.getName())
.allocationPools(in.getAllocationPools())
.gatewayIp(in.getGatewayIp())
.enableDhcp(in.getEnableDhcp())
.dnsNameServers(in.getDnsNameServers())
.hostRoutes(in.getHostRoutes());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
protected static class CreateSubnetRequest {
protected String network_id;
protected Integer ip_version;
protected String cidr;
protected String name;
protected Set<AllocationPool> allocation_pools;
protected String gateway_ip;
protected Boolean enable_dhcp;
protected Set<String> dns_nameservers;
protected Set<HostRoute> host_routes;
protected CreateSubnetRequest(String networkId, Integer ipVersion, String cidr) {
this.network_id = networkId;
this.ip_version = ipVersion;
this.cidr = cidr;
}
protected static class HostRoute {
protected String destination;
protected String nexthop;
}
}
private final String name;
private final Set<AllocationPool> allocationPools;
private final String gatewayIp;
private final Boolean enableDhcp;
private final Set<String> dnsNameServers;
private final Set<HostRoute> hostRoutes;
protected CreateSubnetOptions() {
this.name = null;
this.allocationPools = Sets.newHashSet();
this.gatewayIp = null;
this.enableDhcp = null;
this.dnsNameServers = Sets.newHashSet();
this.hostRoutes = Sets.newHashSet();
}
public CreateSubnetOptions(String name, Set<AllocationPool> allocationPools, String gatewayIp,
Boolean enableDhcp, Set<String> dnsNameServers, Set<HostRoute> hostRoutes) {
this.name = name;
this.allocationPools = allocationPools != null ? ImmutableSet.copyOf(allocationPools) : Sets.<AllocationPool>newHashSet();
this.gatewayIp = gatewayIp;
this.enableDhcp = enableDhcp;
this.dnsNameServers = dnsNameServers != null ? ImmutableSet.copyOf(dnsNameServers) : Sets.<String>newHashSet();
this.hostRoutes = hostRoutes != null ? ImmutableSet.copyOf(hostRoutes) : Sets.<HostRoute>newHashSet();
}
/**
* @return the name for the subnet
*/
public String getName() {
return name;
}
/**
* @return the sub-ranges of cidr which will be available for dynamic allocation to ports
*/
public Set<AllocationPool> getAllocationPools() {
return allocationPools;
}
/**
* @return the default gateway which will be used by devices in this subnet
*/
public String getGatewayIp() {
return gatewayIp;
}
/**
* @return true to enable DHCP, false to disable
*/
public Boolean getEnableDhcp() {
return enableDhcp;
}
/**
* @return the set of DNS name servers to be used by hosts in this subnet.
*/
public Set<String> getDnsNameServers() {
return dnsNameServers;
}
/**
* @return the set of routes that should be used by devices with IPs from this subnet
*/
public Set<HostRoute> getHostRoutes() {
return hostRoutes;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
CreateSubnetRequest createSubnetRequest =
new CreateSubnetRequest(
checkNotNull(postParams.get("network_id"), "networkId not present").toString(),
Integer.parseInt(checkNotNull(postParams.get("ip_version"), "ipVersion not present").toString()),
checkNotNull(postParams.get("cidr"), "cidr not present").toString()
);
if (this.name != null)
createSubnetRequest.name = this.name;
if (!this.allocationPools.isEmpty())
createSubnetRequest.allocation_pools = this.allocationPools;
if (this.gatewayIp != null)
createSubnetRequest.gateway_ip = this.gatewayIp;
if (this.enableDhcp != null)
createSubnetRequest.enable_dhcp = this.enableDhcp;
if (!this.dnsNameServers.isEmpty())
createSubnetRequest.dns_nameservers = this.dnsNameServers;
if (!this.hostRoutes.isEmpty()) {
createSubnetRequest.host_routes = Sets.newHashSet();
for (HostRoute hostRoute : this.hostRoutes) {
CreateSubnetRequest.HostRoute requestHostRoute = new CreateSubnetRequest.HostRoute();
requestHostRoute.destination = hostRoute.getDestinationCidr();
requestHostRoute.nexthop = hostRoute.getNextHop();
createSubnetRequest.host_routes.add(requestHostRoute);
}
}
return bindToRequest(request, ImmutableMap.of("subnet", createSubnetRequest));
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
return jsonBinder.bindToRequest(request, input);
}
}

View File

@ -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_0.options;
import com.google.common.collect.ImmutableMap;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToJsonPayload;
import javax.inject.Inject;
import java.util.Map;
/**
* @author Nick Livens
*/
public class UpdateNetworkOptions implements MapBinder {
@Inject
private BindToJsonPayload jsonBinder;
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromUpdateNetworkOptions(this);
}
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected String name;
protected Boolean adminStateUp;
/**
* @see org.jclouds.openstack.neutron.v2_0.options.UpdateNetworkOptions#getName()
*/
public T name(String name) {
this.name = name;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.options.UpdateNetworkOptions#getAdminStateUp()
*/
public T adminStateUp(Boolean adminStateUp) {
this.adminStateUp = adminStateUp;
return self();
}
public UpdateNetworkOptions build() {
return new UpdateNetworkOptions(name, adminStateUp);
}
public T fromUpdateNetworkOptions(UpdateNetworkOptions options) {
return this.name(options.getName()).adminStateUp(options.getAdminStateUp());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private static class UpdateNetworkRequest {
protected String name;
protected Boolean admin_state_up;
}
private final String name;
private final Boolean adminStateUp;
protected UpdateNetworkOptions() {
this.name = null;
this.adminStateUp = null;
}
public UpdateNetworkOptions(String name, Boolean adminStateUp) {
this.name = name;
this.adminStateUp = adminStateUp;
}
/**
* @return the new name for the network
*/
public String getName() {
return name;
}
/**
* @return the new administrative state for the network. If false, the network does not forward packets.
*/
public boolean getAdminStateUp() {
return adminStateUp;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
UpdateNetworkRequest updateNetworkRequest = new UpdateNetworkRequest();
if (this.name != null)
updateNetworkRequest.name = this.name;
if (this.adminStateUp != null)
updateNetworkRequest.admin_state_up = this.adminStateUp;
return bindToRequest(request, ImmutableMap.of("network", updateNetworkRequest));
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
return jsonBinder.bindToRequest(request, input);
}
}

View File

@ -0,0 +1,219 @@
/**
* 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_0.options;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import org.jclouds.http.HttpRequest;
import org.jclouds.openstack.neutron.v2_0.domain.IP;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToJsonPayload;
import javax.inject.Inject;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
/**
* @author Nick Livens
*/
public class UpdatePortOptions implements MapBinder {
@Inject
private BindToJsonPayload jsonBinder;
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromUpdatePortOptions(this);
}
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected String name;
protected Boolean adminStateUp;
protected String deviceId;
protected String deviceOwner;
protected Set<IP> fixedIps;
/**
* @see org.jclouds.openstack.neutron.v2_0.options.UpdatePortOptions#getName()
*/
public T name(String name) {
this.name = name;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.options.UpdatePortOptions#getAdminStateUp()
*/
public T adminStateUp(Boolean adminStateUp) {
this.adminStateUp = adminStateUp;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.options.UpdatePortOptions#getDeviceId()
*/
public T deviceId(String deviceId) {
this.deviceId = deviceId;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.options.UpdatePortOptions#getDeviceOwner()
*/
public T deviceOwner(String deviceOwner) {
this.deviceOwner = deviceOwner;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.options.UpdatePortOptions#getFixedIps()
*/
public T fixedIps(Collection<IP> fixedIps) {
this.fixedIps = ImmutableSet.copyOf(fixedIps);
return self();
}
public UpdatePortOptions build() {
return new UpdatePortOptions(name, adminStateUp, deviceId, deviceOwner, fixedIps);
}
public T fromUpdatePortOptions(UpdatePortOptions options) {
return this.name(options.getName())
.adminStateUp(options.getAdminStateUp())
.deviceId(options.getDeviceId())
.deviceOwner(options.getDeviceOwner())
.fixedIps(options.getFixedIps());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private static class UpdatePortRequest {
protected String name;
protected Boolean admin_state_up;
protected String device_id;
protected String device_owner;
protected Set<IP> fixed_ips;
private static class IP {
protected String ip_address;
protected String subnet_id;
}
}
private final String name;
private final Boolean adminStateUp;
private final String deviceId;
private final String deviceOwner;
private final Set<IP> fixedIps;
protected UpdatePortOptions() {
this.name = null;
this.adminStateUp = null;
this.deviceId = null;
this.deviceOwner = null;
this.fixedIps = Sets.newHashSet();
}
public UpdatePortOptions(String name, Boolean adminStateUp, String deviceId, String deviceOwner, Set<IP> fixedIps) {
this.name = name;
this.adminStateUp = adminStateUp;
this.deviceId = deviceId;
this.deviceOwner = deviceOwner;
this.fixedIps = fixedIps != null ? ImmutableSet.copyOf(fixedIps) : Sets.<IP>newHashSet();
}
/**
* @return the new name for the port
*/
public String getName() {
return name;
}
/**
* @return the new administrative state for the port. If false, port does not forward packets.
*/
public Boolean getAdminStateUp() {
return adminStateUp;
}
/**
* @return the new device id for the port
*/
public String getDeviceId() {
return deviceId;
}
/**
* @return the new device owner for the port
*/
public String getDeviceOwner() {
return deviceOwner;
}
/**
* @return a new set of fixed ips this port will get assigned
*/
public Set<IP> getFixedIps() {
return fixedIps;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
UpdatePortRequest updatePortRequest = new UpdatePortRequest();
if (this.name != null)
updatePortRequest.name = this.name;
if (this.adminStateUp != null)
updatePortRequest.admin_state_up = this.adminStateUp;
if (this.deviceId != null)
updatePortRequest.device_id = this.deviceId;
if (this.deviceOwner != null)
updatePortRequest.device_owner = this.deviceOwner;
if (!this.fixedIps.isEmpty()) {
updatePortRequest.fixed_ips = Sets.newHashSet();
for (IP fixedIp : this.fixedIps) {
UpdatePortRequest.IP requestIp = new UpdatePortRequest.IP();
requestIp.ip_address = fixedIp.getIpAddress();
requestIp.subnet_id = fixedIp.getSubnetId();
updatePortRequest.fixed_ips.add(requestIp);
}
}
return bindToRequest(request, ImmutableMap.of("port", updatePortRequest));
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
return jsonBinder.bindToRequest(request, input);
}
}

View File

@ -0,0 +1,219 @@
/**
* 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_0.options;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import org.jclouds.http.HttpRequest;
import org.jclouds.openstack.neutron.v2_0.domain.HostRoute;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToJsonPayload;
import javax.inject.Inject;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
/**
* @author Nick Livens
*/
public class UpdateSubnetOptions implements MapBinder {
@Inject
private BindToJsonPayload jsonBinder;
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromUpdateSubnetOptions(this);
}
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected String name;
protected String gatewayIp;
protected Boolean enableDhcp;
protected Set<String> dnsNameServers;
protected Set<HostRoute> hostRoutes;
/**
* @see org.jclouds.openstack.neutron.v2_0.options.UpdateSubnetOptions#getName()
*/
public T name(String name) {
this.name = name;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.options.UpdateSubnetOptions#getGatewayIp()
*/
public T gatewayIp(String gatewayIp) {
this.gatewayIp = gatewayIp;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.options.UpdateSubnetOptions#getEnableDhcp()
*/
public T enableDhcp(Boolean enableDhcp) {
this.enableDhcp = enableDhcp;
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.options.UpdateSubnetOptions#getDnsNameServers()
*/
public T dnsNameServers(Collection<String> dnsNameServers) {
this.dnsNameServers = ImmutableSet.copyOf(dnsNameServers);
return self();
}
/**
* @see org.jclouds.openstack.neutron.v2_0.options.UpdateSubnetOptions#getHostRoutes()
*/
public T hostRoutes(Collection<HostRoute> hostRoutes) {
this.hostRoutes = ImmutableSet.copyOf(hostRoutes);
return self();
}
public UpdateSubnetOptions build() {
return new UpdateSubnetOptions(name, gatewayIp, enableDhcp, dnsNameServers, hostRoutes);
}
public T fromUpdateSubnetOptions(UpdateSubnetOptions in) {
return this.name(in.getName())
.gatewayIp(in.getGatewayIp())
.enableDhcp(in.getEnableDhcp())
.dnsNameServers(in.getDnsNameServers())
.hostRoutes(in.getHostRoutes());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
private static class UpdateSubnetRequest {
protected String name;
protected String gateway_ip;
protected Boolean enable_dhcp;
protected Set<String> dns_nameservers;
protected Set<HostRoute> host_routes;
private static class HostRoute {
protected String destination;
protected String nexthop;
}
}
private final String name;
private final String gatewayIp;
private final Boolean enableDhcp;
private final Set<String> dnsNameServers;
private final Set<HostRoute> hostRoutes;
protected UpdateSubnetOptions() {
this.name = null;
this.gatewayIp = null;
this.enableDhcp = null;
this.dnsNameServers = Sets.newHashSet();
this.hostRoutes = Sets.newHashSet();
}
public UpdateSubnetOptions(String name, String gatewayIp, Boolean enableDhcp, Set<String> dnsNameServers, Set<HostRoute> hostRoutes) {
this.name = name;
this.gatewayIp = gatewayIp;
this.enableDhcp = enableDhcp;
this.dnsNameServers = dnsNameServers != null ? ImmutableSet.copyOf(dnsNameServers) : Sets.<String>newHashSet();
this.hostRoutes = hostRoutes != null ? ImmutableSet.copyOf(hostRoutes) : Sets.<HostRoute>newHashSet();
}
/**
* @return the new name for the subnet
*/
public String getName() {
return name;
}
/**
* @return the new default gateway used by devices in this subnet
*/
public String getGatewayIp() {
return gatewayIp;
}
/**
* @return true if DHCP is enabled for this subnet, false if not
*/
public Boolean getEnableDhcp() {
return enableDhcp;
}
/**
* @return the new set of DNS name servers used by hosts in this subnet
*/
public Set<String> getDnsNameServers() {
return dnsNameServers;
}
/**
* @return the new set of routes that should be used by devices with IPs from this subnet
*/
public Set<HostRoute> getHostRoutes() {
return hostRoutes;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
UpdateSubnetRequest updateSubnetRequest = new UpdateSubnetRequest();
if (this.name != null)
updateSubnetRequest.name = this.name;
if (this.gatewayIp != null)
updateSubnetRequest.gateway_ip = this.gatewayIp;
if (this.enableDhcp != null)
updateSubnetRequest.enable_dhcp = this.enableDhcp;
if (!this.dnsNameServers.isEmpty())
updateSubnetRequest.dns_nameservers = this.dnsNameServers;
if (!this.hostRoutes.isEmpty()) {
updateSubnetRequest.host_routes = Sets.newHashSet();
for (HostRoute hostRoute : this.hostRoutes) {
UpdateSubnetRequest.HostRoute requestHostRoute = new UpdateSubnetRequest.HostRoute();
requestHostRoute.destination = hostRoute.getDestinationCidr();
requestHostRoute.nexthop = hostRoute.getNextHop();
updateSubnetRequest.host_routes.add(requestHostRoute);
}
}
return bindToRequest(request, ImmutableMap.of("subnet", updateSubnetRequest));
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
return jsonBinder.bindToRequest(request, input);
}
}

View File

@ -0,0 +1,18 @@
#
# 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.
#
org.jclouds.openstack.neutron.v2_0.NeutronApiMetadata

View File

@ -0,0 +1,35 @@
/**
* 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_0;
import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.TypeToken;
import org.jclouds.View;
import org.jclouds.apis.internal.BaseApiMetadataTest;
import org.testng.annotations.Test;
/**
* @author Nick Livens
*/
@Test(groups = "unit", testName = "NeutronApiMetadataTest")
public class NeutronApiMetadataTest extends BaseApiMetadataTest {
public NeutronApiMetadataTest() {
super(new NeutronApiMetadata(), ImmutableSet.<TypeToken<? extends View>>of());
}
}

View File

@ -0,0 +1,241 @@
/*
* 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_0.features;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.jclouds.http.HttpResponse;
import org.jclouds.openstack.neutron.v2_0.domain.BulkNetwork;
import org.jclouds.openstack.neutron.v2_0.domain.Network;
import org.jclouds.openstack.neutron.v2_0.domain.NetworkType;
import org.jclouds.openstack.neutron.v2_0.domain.ReferenceWithName;
import org.jclouds.openstack.neutron.v2_0.internal.BaseNeutronApiExpectTest;
import org.jclouds.openstack.neutron.v2_0.options.CreateNetworkBulkOptions;
import org.jclouds.openstack.neutron.v2_0.options.CreateNetworkOptions;
import org.jclouds.openstack.neutron.v2_0.options.UpdateNetworkOptions;
import org.jclouds.openstack.neutron.v2_0.parse.ParseNetworkTest;
import org.jclouds.rest.AuthorizationException;
import org.testng.annotations.Test;
import javax.ws.rs.core.MediaType;
import java.util.Set;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.testng.Assert.*;
/**
* Tests parsing and Guice wiring of NetworkApi
*
* @author Nick Livens
*/
@Test(groups = "unit", testName = "NetworkApiExpectTest")
public class NetworkApiExpectTest extends BaseNeutronApiExpectTest {
private static final String ZONE = "region-a.geo-1";
public void testListReferencesReturns2xx() {
NetworkApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/networks").addQueryParam("fields", "id", "tenant_id", "name").build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/list_networks.json", APPLICATION_JSON)).build())
.getNetworkApiForZone(ZONE);
Set<? extends ReferenceWithName> references = api.list().concat().toSet();
assertEquals(references, listOfReferencesWithNames());
}
public void testListReferencesReturns4xx() {
NetworkApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/networks").addQueryParam("fields", "id", "tenant_id", "name").build(),
HttpResponse.builder().statusCode(404).build())
.getNetworkApiForZone(ZONE);
assertTrue(api.list().concat().isEmpty());
}
public void testListReturns2xx() {
NetworkApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/networks").build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/list_networks.json", APPLICATION_JSON)).build())
.getNetworkApiForZone(ZONE);
Set<? extends Network> nets = api.listInDetail().concat().toSet();
assertEquals(nets, listOfNetworks());
}
public void testListReturns4xx() {
NetworkApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/networks").build(),
HttpResponse.builder().statusCode(404).build())
.getNetworkApiForZone(ZONE);
assertTrue(api.listInDetail().concat().isEmpty());
}
public void testGetReturns2xx() {
NetworkApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/networks/16dba3bc-f3fa-4775-afdc-237e12c72f6a").build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/network.json", APPLICATION_JSON)).build())
.getNetworkApiForZone(ZONE);
Network net = api.get("16dba3bc-f3fa-4775-afdc-237e12c72f6a");
assertEquals(net, new ParseNetworkTest().expected());
}
public void testGetReturns4xx() {
NetworkApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/networks/16dba3bc-f3fa-4775-afdc-237e12c72f6a").build(),
HttpResponse.builder().statusCode(404).build())
.getNetworkApiForZone(ZONE);
assertNull(api.get("16dba3bc-f3fa-4775-afdc-237e12c72f6a"));
}
public void testCreateReturns2xx() {
NetworkApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/networks").method("POST")
.payload(payloadFromStringWithContentType("{\"network\":{\"name\":\"another-test\",\"router:external\":true,\"provider:network_type\":\"local\"}}", MediaType.APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromStringWithContentType("{\"network\":{\"id\":\"12345\",\"tenant_id\":\"6789\",\"router:external\":true,\"provider:network_type\":\"local\"}}", APPLICATION_JSON)).build())
.getNetworkApiForZone(ZONE);
Network net = api.create(CreateNetworkOptions.builder().name("another-test").external(true).networkType(NetworkType.LOCAL).build());
assertEquals(net, Network.builder().id("12345").tenantId("6789").external(true).networkType(NetworkType.LOCAL).build());
}
@Test(expectedExceptions = AuthorizationException.class)
public void testCreateReturns4xx() {
NetworkApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/networks").method("POST")
.payload(payloadFromStringWithContentType("{\"network\":{\"name\":\"another-test\",\"provider:network_type\":\"local\"}}", MediaType.APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(401).build())
.getNetworkApiForZone(ZONE);
api.create(CreateNetworkOptions.builder().name("another-test").networkType(NetworkType.LOCAL).build());
}
public void testCreateBulkReturns2xx() {
NetworkApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/networks").method("POST")
.payload(payloadFromStringWithContentType("{\"networks\":[{\"name\":\"test\",\"provider:network_type\":\"local\"},{\"name\":\"test-2\",\"provider:network_type\":\"local\"}]}", MediaType.APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromStringWithContentType("{\"networks\":[{\"id\":\"1\",\"tenant_id\":\"1\",\"name\":\"test\",\"provider:network_type\":\"local\"},{\"id\":\"2\",\"tenant_id\":\"1\",\"name\":\"test-2\",\"provider:network_type\":\"local\"}]}", APPLICATION_JSON)).build())
.getNetworkApiForZone(ZONE);
Set<? extends ReferenceWithName> nets = api.createBulk(
CreateNetworkBulkOptions.builder().networks(
ImmutableList.of(
BulkNetwork.builder().networkType(NetworkType.LOCAL).name("test").build(),
BulkNetwork.builder().networkType(NetworkType.LOCAL).name("test-2").build()
)
).build()
).toSet();
assertEquals(nets, createBulkReturns2xxResponse());
}
@Test(expectedExceptions = AuthorizationException.class)
public void testCreateBulkReturns4xx() {
NetworkApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/networks").method("POST")
.payload(payloadFromStringWithContentType("{\"networks\":[{\"name\":\"test\",\"provider:network_type\":\"local\"},{\"name\":\"test-2\",\"provider:network_type\":\"local\"}]}", MediaType.APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(401).build())
.getNetworkApiForZone(ZONE);
api.createBulk(
CreateNetworkBulkOptions.builder().networks(
ImmutableList.of(
BulkNetwork.builder().networkType(NetworkType.LOCAL).name("test").build(),
BulkNetwork.builder().networkType(NetworkType.LOCAL).name("test-2").build()
)
).build()
);
}
public void testUpdateReturns2xx() {
NetworkApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/networks/12345").method("PUT")
.payload(payloadFromStringWithContentType("{\"network\":{\"name\":\"another-test\",\"admin_state_up\":true}}", MediaType.APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(200).build())
.getNetworkApiForZone(ZONE);
assertTrue(api.update("12345", UpdateNetworkOptions.builder().name("another-test").adminStateUp(true).build()));
}
public void testUpdateReturns4xx() {
NetworkApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/networks/12345").method("PUT")
.payload(payloadFromStringWithContentType("{\"network\":{\"name\":\"another-test\",\"admin_state_up\":true}}", MediaType.APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(404).build())
.getNetworkApiForZone(ZONE);
assertFalse(api.update("12345", UpdateNetworkOptions.builder().name("another-test").adminStateUp(true).build()));
}
public void testDeleteReturns2xx() {
NetworkApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/networks/12345").method("DELETE").build(),
HttpResponse.builder().statusCode(200).build())
.getNetworkApiForZone(ZONE);
assertTrue(api.delete("12345"));
}
@Test(expectedExceptions = AuthorizationException.class)
public void testDeleteReturns4xx() {
NetworkApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/networks/12345").method("DELETE").build(),
HttpResponse.builder().statusCode(403).build())
.getNetworkApiForZone(ZONE);
api.delete("12345");
}
protected Set<Network> listOfNetworks() {
return ImmutableSet.of(
Network.builder().name("jclouds-test").tenantId("1234567890").id("16dba3bc-f3fa-4775-afdc-237e12c72f6a").build(),
Network.builder().name("wibble").tenantId("1234567890").id("1a104cf5-cb18-4d35-9407-2fd2646d9d0b").build(),
Network.builder().name("jclouds-test").tenantId("1234567890").id("31083ae2-420d-48b2-ac98-9f7a4fd8dbdc").build(),
Network.builder().name("jclouds-test").tenantId("1234567890").id("49c6d6fa-ff2a-459d-b975-75a8d31c9a89").build(),
Network.builder().name("wibble").tenantId("1234567890").id("5cb3d6f4-62cb-41c9-b964-ba7d9df79e4e").build(),
Network.builder().name("jclouds-test").tenantId("1234567890").id("5d51d012-3491-4db7-b1b5-6f254015015d").build(),
Network.builder().name("wibble").tenantId("1234567890").id("5f9cf7dc-22ca-4097-8e49-1cc8b23faf17").build(),
Network.builder().name("jclouds-test").tenantId("1234567890").id("6319ecad-6bff-48b2-9b53-02ede8cb7588").build(),
Network.builder().name("jclouds-test").tenantId("1234567890").id("6ba4c788-661f-49ab-9bf8-5f10cbbb2f57").build(),
Network.builder().name("jclouds-test").tenantId("1234567890").id("74ed170b-5069-4353-ab38-9719766dc57e").build(),
Network.builder().name("wibble").tenantId("1234567890").id("b71fcac1-e864-4031-8c5b-edbecd9ece36").build(),
Network.builder().name("jclouds-test").tenantId("1234567890").id("c7681895-d84d-4650-9ca0-82c72036b855").build()
);
}
protected Set<Network> createBulkReturns2xxResponse() {
return ImmutableSet.of(
Network.builder().id("1").tenantId("1").name("test").networkType(NetworkType.LOCAL).build(),
Network.builder().id("2").tenantId("1").name("test-2").networkType(NetworkType.LOCAL).build()
);
}
}

View File

@ -0,0 +1,113 @@
/*
* 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_0.features;
import com.google.common.collect.ImmutableList;
import org.jclouds.openstack.neutron.v2_0.domain.BulkNetwork;
import org.jclouds.openstack.neutron.v2_0.domain.Network;
import org.jclouds.openstack.neutron.v2_0.domain.NetworkType;
import org.jclouds.openstack.neutron.v2_0.domain.ReferenceWithName;
import org.jclouds.openstack.neutron.v2_0.internal.BaseNeutronApiLiveTest;
import org.jclouds.openstack.neutron.v2_0.options.CreateNetworkBulkOptions;
import org.jclouds.openstack.neutron.v2_0.options.CreateNetworkOptions;
import org.jclouds.openstack.neutron.v2_0.options.UpdateNetworkOptions;
import java.util.Set;
import static org.testng.Assert.*;
/**
* Tests parsing and Guice wiring of NetworkApi
*
* @author Nick Livens
*/
public class NetworkApiLiveTest extends BaseNeutronApiLiveTest {
public void testGetAndListNetworks() {
for (String zone : api.getConfiguredZones()) {
Set<? extends ReferenceWithName> references = api.getNetworkApiForZone(zone).list().concat().toSet();
Set<? extends Network> networks = api.getNetworkApiForZone(zone).listInDetail().concat().toSet();
assertNotNull(references);
assertNotNull(networks);
assertEquals(references.size(), networks.size());
for (Network network : networks) {
assertNotNull(network.getName());
assertTrue(references.contains(ReferenceWithName.builder().id(network.getId()).tenantId(network.getTenantId()).name(network.getName()).build()));
Network retrievedNetwork = api.getNetworkApiForZone(zone).get(network.getId());
assertEquals(network, retrievedNetwork);
}
}
}
public void testCreateUpdateAndDeleteNetwork() {
for (String zone : api.getConfiguredZones()) {
NetworkApi networkApi = api.getNetworkApiForZone(zone);
Network net = networkApi.create(CreateNetworkOptions.builder().name("jclouds-test").networkType(NetworkType.LOCAL).build());
Network test = networkApi.create();
assertNotNull(net);
Network network = networkApi.get(net.getId());
assertEquals(network.getId(), net.getId());
assertEquals(network.getName(), "jclouds-test");
assertEquals(network.getNetworkType(), NetworkType.LOCAL);
assertTrue(network.getSubnets().isEmpty());
assertTrue(networkApi.update(net.getId(), UpdateNetworkOptions.builder().name("jclouds-live-test").build()));
network = networkApi.get(net.getId());
assertEquals(network.getId(), net.getId());
assertEquals(network.getName(), "jclouds-live-test");
assertTrue(network.getSubnets().isEmpty());
Network net2 = networkApi.create(CreateNetworkOptions.builder().name("jclouds-test2").networkType(NetworkType.LOCAL).build());
assertNotNull(net2);
assertTrue(networkApi.delete(net.getId()));
assertTrue(networkApi.delete(net2.getId()));
assertTrue(networkApi.delete(test.getId()));
}
}
public void testBulkCreateNetwork() {
for (String zone : api.getConfiguredZones()) {
NetworkApi networkApi = api.getNetworkApiForZone(zone);
Set<? extends Network> nets = networkApi.createBulk(
CreateNetworkBulkOptions.builder().networks(
ImmutableList.of(
BulkNetwork.builder().networkType(NetworkType.LOCAL).name("jclouds-live-test-1").adminStateUp(true).build(),
BulkNetwork.builder().networkType(NetworkType.LOCAL).name("jclouds-live-test-2").adminStateUp(false).build(),
BulkNetwork.builder().networkType(NetworkType.LOCAL).name("jclouds-live-test-3").adminStateUp(false).build()
)
).build()
).toSet();
Set<? extends Network> existingNets = networkApi.listInDetail().concat().toSet();
assertNotNull(nets);
assertTrue(!nets.isEmpty());
assertEquals(nets.size(), 3);
for (Network net : nets) {
assertTrue(existingNets.contains(net));
assertTrue(networkApi.delete(net.getId()));
}
}
}
}

View File

@ -0,0 +1,242 @@
/*
* 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_0.features;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.jclouds.http.HttpResponse;
import org.jclouds.openstack.neutron.v2_0.domain.BulkPort;
import org.jclouds.openstack.neutron.v2_0.domain.Port;
import org.jclouds.openstack.neutron.v2_0.domain.ReferenceWithName;
import org.jclouds.openstack.neutron.v2_0.domain.State;
import org.jclouds.openstack.neutron.v2_0.internal.BaseNeutronApiExpectTest;
import org.jclouds.openstack.neutron.v2_0.options.CreatePortBulkOptions;
import org.jclouds.openstack.neutron.v2_0.options.CreatePortOptions;
import org.jclouds.openstack.neutron.v2_0.options.UpdatePortOptions;
import org.jclouds.openstack.neutron.v2_0.parse.ParsePortTest;
import org.jclouds.rest.AuthorizationException;
import org.testng.annotations.Test;
import java.util.Set;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.testng.Assert.*;
/**
* Tests parsing and Guice wiring of PortApi
*
* @author Nick Livens
*/
@Test(groups = "unit", testName = "PortApiExpectTest")
public class PortApiExpectTest extends BaseNeutronApiExpectTest {
private static final String ZONE = "region-a.geo-1";
public void testListReferencesReturns2xx() {
PortApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/ports").addQueryParam("fields", "id", "tenant_id", "name").build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/list_ports.json", APPLICATION_JSON)).build())
.getPortApiForZone(ZONE);
Set<? extends ReferenceWithName> references = api.list().concat().toSet();
assertEquals(references, listOfReferencesWithNames());
}
public void testListReferencesReturns4xx() {
PortApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/ports").addQueryParam("fields", "id", "tenant_id", "name").build(),
HttpResponse.builder().statusCode(404).build())
.getPortApiForZone(ZONE);
assertTrue(api.list().concat().isEmpty());
}
public void testListReturns2xx() {
PortApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/ports").build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/list_ports.json", APPLICATION_JSON)).build())
.getPortApiForZone(ZONE);
Set<? extends Port> ports = api.listInDetail().concat().toSet();
assertEquals(ports, listOfPorts());
}
public void testListReturns4xx() {
PortApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/ports").build(),
HttpResponse.builder().statusCode(404).build())
.getPortApiForZone(ZONE);
assertTrue(api.listInDetail().concat().isEmpty());
}
public void testGetReturns2xx() {
PortApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/ports/624312ff-d14b-4ba3-9834-1c78d23d574d").build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/port.json", APPLICATION_JSON)).build())
.getPortApiForZone(ZONE);
Port port = api.get("624312ff-d14b-4ba3-9834-1c78d23d574d");
assertEquals(port, new ParsePortTest().expected());
}
public void testGetReturns4xx() {
PortApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/ports/624312ff-d14b-4ba3-9834-1c78d23d574d").build(),
HttpResponse.builder().statusCode(404).build())
.getPortApiForZone(ZONE);
assertNull(api.get("624312ff-d14b-4ba3-9834-1c78d23d574d"));
}
public void testCreateReturns2xx() {
PortApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/ports").method("POST")
.payload(payloadFromStringWithContentType("{\"port\":{\"network_id\":\"1\",\"name\":\"test-port\"}}", APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromStringWithContentType("{\"port\":{\"id\":\"1\",\"tenant_id\":\"1\",\"network_id\":\"1\",\"name\":\"test-port\"}}", APPLICATION_JSON)).build())
.getPortApiForZone(ZONE);
Port port = api.create("1", CreatePortOptions.builder().name("test-port").build());
assertEquals(port, Port.builder().id("1").tenantId("1").name("test-port").networkId("1").build());
}
@Test(expectedExceptions = AuthorizationException.class)
public void testCreateReturns4xx() {
PortApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/ports").method("POST")
.payload(payloadFromStringWithContentType("{\"port\":{\"network_id\":\"1\",\"name\":\"test-port\"}}", APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(401).build())
.getPortApiForZone(ZONE);
api.create("1", CreatePortOptions.builder().name("test-port").build());
}
public void testCreateBulkReturns2xx() {
PortApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/ports").method("POST")
.payload(payloadFromStringWithContentType("{\"ports\":[{\"network_id\":\"1\",\"name\":\"test-port-1\"},{\"network_id\":\"2\",\"name\":\"test-port-2\"}]}", APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(200)
.payload(payloadFromStringWithContentType("{\"ports\":[{\"id\":\"1\",\"tenant_id\":\"1\",\"network_id\":\"1\",\"name\":\"test-port-1\"},{\"id\":\"2\",\"tenant_id\":\"1\",\"network_id\":\"2\",\"name\":\"test-port-2\"}]}", APPLICATION_JSON)).build())
.getPortApiForZone(ZONE);
Set<? extends ReferenceWithName> ports = api.createBulk(
CreatePortBulkOptions.builder().ports(
ImmutableList.of(
BulkPort.builder().networkId("1").name("test-port-1").build(),
BulkPort.builder().networkId("2").name("test-port-2").build()
)
).build()
).toSet();
assertEquals(ports, createBulkReturns2xxResponse());
}
@Test(expectedExceptions = AuthorizationException.class)
public void testCreateBulkReturns4xx() {
PortApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/ports").method("POST")
.payload(payloadFromStringWithContentType("{\"ports\":[{\"network_id\":\"1\",\"name\":\"test-port-1\"},{\"network_id\":\"2\",\"name\":\"test-port-2\"}]}", APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(401).build())
.getPortApiForZone(ZONE);
api.createBulk(
CreatePortBulkOptions.builder().ports(
ImmutableList.of(
BulkPort.builder().networkId("1").name("test-port-1").build(),
BulkPort.builder().networkId("2").name("test-port-2").build()
)
).build()
);
}
public void testUpdateReturns2xx() {
PortApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/ports/12345").method("PUT")
.payload(payloadFromStringWithContentType("{\"port\":{\"name\":\"another-test\",\"admin_state_up\":true}}", APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(200).build())
.getPortApiForZone(ZONE);
assertTrue(api.update("12345", UpdatePortOptions.builder().name("another-test").adminStateUp(true).build()));
}
public void testUpdateReturns4xx() {
PortApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/ports/12345").method("PUT")
.payload(payloadFromStringWithContentType("{\"port\":{\"name\":\"another-test\",\"admin_state_up\":true}}", APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(404).build())
.getPortApiForZone(ZONE);
assertFalse(api.update("12345", UpdatePortOptions.builder().name("another-test").adminStateUp(true).build()));
}
public void testDeleteReturns2xx() {
PortApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/ports/12345").method("DELETE").build(),
HttpResponse.builder().statusCode(200).build())
.getPortApiForZone(ZONE);
assertTrue(api.delete("12345"));
}
@Test(expectedExceptions = AuthorizationException.class)
public void testDeleteReturns4xx() {
PortApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/ports/12345").method("DELETE").build(),
HttpResponse.builder().statusCode(403).build())
.getPortApiForZone(ZONE);
api.delete("12345");
}
protected Set<Port> listOfPorts() {
return ImmutableSet.of(
Port.builder().state(State.ACTIVE).networkId("1234567890").name("jclouds-test").tenantId("1234567890").id("16dba3bc-f3fa-4775-afdc-237e12c72f6a").build(),
Port.builder().state(State.ACTIVE).networkId("1234567890").name("wibble").tenantId("1234567890").id("1a104cf5-cb18-4d35-9407-2fd2646d9d0b").build(),
Port.builder().state(State.ACTIVE).networkId("1234567890").name("jclouds-test").tenantId("1234567890").id("31083ae2-420d-48b2-ac98-9f7a4fd8dbdc").build(),
Port.builder().state(State.ACTIVE).networkId("1234567890").name("jclouds-test").tenantId("1234567890").id("49c6d6fa-ff2a-459d-b975-75a8d31c9a89").build(),
Port.builder().state(State.ACTIVE).networkId("1234567890").name("wibble").tenantId("1234567890").id("5cb3d6f4-62cb-41c9-b964-ba7d9df79e4e").build(),
Port.builder().state(State.ACTIVE).networkId("1234567890").name("jclouds-test").tenantId("1234567890").id("5d51d012-3491-4db7-b1b5-6f254015015d").build(),
Port.builder().state(State.ACTIVE).networkId("1234567890").name("wibble").tenantId("1234567890").id("5f9cf7dc-22ca-4097-8e49-1cc8b23faf17").build(),
Port.builder().state(State.ACTIVE).networkId("1234567890").name("jclouds-test").tenantId("1234567890").id("6319ecad-6bff-48b2-9b53-02ede8cb7588").build(),
Port.builder().state(State.ACTIVE).networkId("1234567890").name("jclouds-test").tenantId("1234567890").id("6ba4c788-661f-49ab-9bf8-5f10cbbb2f57").build(),
Port.builder().state(State.ACTIVE).networkId("1234567890").name("jclouds-test").tenantId("1234567890").id("74ed170b-5069-4353-ab38-9719766dc57e").build(),
Port.builder().state(State.ACTIVE).networkId("1234567890").name("wibble").tenantId("1234567890").id("b71fcac1-e864-4031-8c5b-edbecd9ece36").build(),
Port.builder().state(State.ACTIVE).networkId("1234567890").name("jclouds-test").tenantId("1234567890").id("c7681895-d84d-4650-9ca0-82c72036b855").build()
);
}
protected Set<Port> createBulkReturns2xxResponse() {
return ImmutableSet.of(
Port.builder().id("1").tenantId("1").name("test-port-1").networkId("1").build(),
Port.builder().id("2").tenantId("1").name("test-port-2").networkId("2").build()
);
}
}

View File

@ -0,0 +1,140 @@
/*
* 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_0.features;
import com.google.common.collect.ImmutableSet;
import org.jclouds.openstack.neutron.v2_0.domain.*;
import org.jclouds.openstack.neutron.v2_0.internal.BaseNeutronApiLiveTest;
import org.jclouds.openstack.neutron.v2_0.options.*;
import java.util.Set;
import static org.testng.Assert.*;
/**
* Tests PortApi in combination with the Network & SubnetApi
*
* @author Nick Livens
*/
public class PortApiLiveTest extends BaseNeutronApiLiveTest {
public void testGetAndListPorts() {
for (String zone : api.getConfiguredZones()) {
Set<? extends ReferenceWithName> references = api.getPortApiForZone(zone).list().concat().toSet();
Set<? extends Port> ports = api.getPortApiForZone(zone).listInDetail().concat().toSet();
assertNotNull(references);
assertNotNull(ports);
assertEquals(references.size(), ports.size());
for (Port port : ports) {
assertNotNull(port.getName());
assertTrue(references.contains(ReferenceWithName.builder().id(port.getId()).tenantId(port.getTenantId()).name(port.getName()).build()));
Port retrievedPort = api.getPortApiForZone(zone).get(port.getId());
assertEquals(port, retrievedPort);
}
}
}
public void testCreateUpdateAndDeletePort() {
for (String zone : api.getConfiguredZones()) {
NetworkApi networkApi = api.getNetworkApiForZone(zone);
SubnetApi subnetApi = api.getSubnetApiForZone(zone);
PortApi portApi = api.getPortApiForZone(zone);
String networkId = networkApi.create(CreateNetworkOptions.builder().name("JClouds-Live-Network").networkType(NetworkType.LOCAL).build()).getId();
String ipv4SubnetId = subnetApi.create(networkId, 4, "198.51.100.0/24", CreateSubnetOptions.builder().name("JClouds-Live-IPv4-Subnet").build()).getId();
String ipv6SubnetId = subnetApi.create(networkId, 6, "a1ca:1e1:c:107d::/96", CreateSubnetOptions.builder().name("JClouds-Live-IPv6-Subnet").build()).getId();
assertNotNull(networkId);
assertNotNull(ipv4SubnetId);
assertNotNull(ipv6SubnetId);
String ipv4PortId = portApi.create(networkId, CreatePortOptions.builder().name("JClouds-Live-IPv4-Port").fixedIps(getFixedAddresses(ipv4SubnetId)).build()).getId();
String ipv6PortId = portApi.create(networkId, CreatePortOptions.builder().name("JClouds-Live-IPv6-Port").fixedIps(getFixedAddresses(ipv6SubnetId)).build()).getId();
assertNotNull(ipv4PortId);
assertNotNull(ipv6PortId);
Port ipv4Port = portApi.get(ipv4PortId);
assertNotNull(ipv4Port);
assertEquals(ipv4Port.getId(), ipv4PortId);
assertEquals(ipv4Port.getName(), "JClouds-Live-IPv4-Port");
Port ipv6Port = portApi.get(ipv6PortId);
assertNotNull(ipv6Port);
assertEquals(ipv6Port.getId(), ipv6PortId);
assertEquals(ipv6Port.getName(), "JClouds-Live-IPv6-Port");
assertTrue(portApi.update(ipv4PortId, UpdatePortOptions.builder().name("Updated").build()));
Port updatedIpv4Port = portApi.get(ipv4PortId);
assertEquals(updatedIpv4Port.getName(), "Updated");
assertTrue(portApi.delete(ipv4PortId));
assertTrue(portApi.delete(ipv6PortId));
assertTrue(subnetApi.delete(ipv4SubnetId));
assertTrue(subnetApi.delete(ipv6SubnetId));
assertTrue(networkApi.delete(networkId));
}
}
public void testBulkCreatePort() {
for (String zone : api.getConfiguredZones()) {
NetworkApi networkApi = api.getNetworkApiForZone(zone);
SubnetApi subnetApi = api.getSubnetApiForZone(zone);
PortApi portApi = api.getPortApiForZone(zone);
String networkId = networkApi.create(CreateNetworkOptions.builder().name("JClouds-Live-Network").networkType(NetworkType.LOCAL).build()).getId();
String ipv4SubnetId = subnetApi.create(networkId, 4, "198.51.100.0/24", CreateSubnetOptions.builder().name("JClouds-Live-IPv4-Subnet").build()).getId();
String ipv6SubnetId = subnetApi.create(networkId, 6, "a1ca:1e1:c:107d::/96", CreateSubnetOptions.builder().name("JClouds-Live-IPv6-Subnet").build()).getId();
assertNotNull(networkId);
assertNotNull(ipv4SubnetId);
assertNotNull(ipv6SubnetId);
Set<? extends Port> ports = portApi.createBulk(
CreatePortBulkOptions.builder().ports(
ImmutableSet.of(
BulkPort.builder().networkId(networkId).name("JClouds-Live-IPv4-Subnet-1").fixedIps(getFixedAddresses(ipv4SubnetId)).build(),
BulkPort.builder().networkId(networkId).name("JClouds-Live-IPv4-Subnet-2").fixedIps(getFixedAddresses(ipv4SubnetId)).build(),
BulkPort.builder().networkId(networkId).name("JClouds-Live-IPv6-Subnet-1").fixedIps(getFixedAddresses(ipv6SubnetId)).build(),
BulkPort.builder().networkId(networkId).name("JClouds-Live-IPv6-Subnet-2").fixedIps(getFixedAddresses(ipv6SubnetId)).build()
)
).build()
).toSet();
Set<? extends Port> existingPorts = portApi.listInDetail().concat().toSet();
assertNotNull(ports);
assertFalse(ports.isEmpty());
assertEquals(ports.size(), 4);
for (Port port : ports) {
assertTrue(existingPorts.contains(port));
assertTrue(portApi.delete(port.getId()));
}
assertTrue(subnetApi.delete(ipv4SubnetId));
assertTrue(subnetApi.delete(ipv6SubnetId));
assertTrue(networkApi.delete(networkId));
}
}
public Set<IP> getFixedAddresses(String subnetId) {
return ImmutableSet.of(
IP.builder().subnetId(subnetId).build()
);
}
}

View File

@ -0,0 +1,251 @@
/*
* 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_0.features;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.jclouds.http.HttpResponse;
import org.jclouds.openstack.neutron.v2_0.domain.BulkSubnet;
import org.jclouds.openstack.neutron.v2_0.domain.ReferenceWithName;
import org.jclouds.openstack.neutron.v2_0.domain.Subnet;
import org.jclouds.openstack.neutron.v2_0.internal.BaseNeutronApiExpectTest;
import org.jclouds.openstack.neutron.v2_0.options.CreateSubnetBulkOptions;
import org.jclouds.openstack.neutron.v2_0.options.CreateSubnetOptions;
import org.jclouds.openstack.neutron.v2_0.options.UpdateSubnetOptions;
import org.jclouds.openstack.neutron.v2_0.parse.ParseSubnetTest;
import org.jclouds.rest.AuthorizationException;
import org.testng.annotations.Test;
import java.util.Set;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.testng.Assert.*;
/**
* Tests parsing and Guice wiring of SubnetApi
*
* @author Nick Livens
*/
@Test(groups = "unit", testName = "SubnetApiExpectTest")
public class SubnetApiExpectTest extends BaseNeutronApiExpectTest {
private static final String ZONE = "region-a.geo-1";
public void testListReferencesReturns2xx() {
SubnetApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/subnets").addQueryParam("fields", "id", "tenant_id", "name").build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/list_subnets.json", APPLICATION_JSON)).build())
.getSubnetApiForZone(ZONE);
Set<? extends ReferenceWithName> references = api.list().concat().toSet();
assertEquals(references, listOfReferencesWithNames());
}
public void testListReferencesReturns4xx() {
SubnetApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/subnets").addQueryParam("fields", "id", "tenant_id", "name").build(),
HttpResponse.builder().statusCode(404).build())
.getSubnetApiForZone(ZONE);
assertTrue(api.list().concat().isEmpty());
}
public void testListReturns2xx() {
SubnetApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/subnets").build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/list_subnets.json", APPLICATION_JSON)).build())
.getSubnetApiForZone(ZONE);
Set<? extends Subnet> subnets = api.listInDetail().concat().toSet();
assertEquals(subnets, listOfSubnets());
}
public void testListReturns4xx() {
SubnetApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/subnets").build(),
HttpResponse.builder().statusCode(404).build())
.getSubnetApiForZone(ZONE);
assertTrue(api.listInDetail().concat().isEmpty());
}
public void testGetReturns2xx() {
SubnetApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/subnets/624312ff-d14b-4ba3-9834-1c78d23d574d").build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/subnet.json", APPLICATION_JSON)).build())
.getSubnetApiForZone(ZONE);
Subnet subnet = api.get("624312ff-d14b-4ba3-9834-1c78d23d574d");
assertEquals(subnet, new ParseSubnetTest().expected());
}
public void testGetReturns4xx() {
SubnetApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/subnets/624312ff-d14b-4ba3-9834-1c78d23d574d").build(),
HttpResponse.builder().statusCode(404).build())
.getSubnetApiForZone(ZONE);
assertNull(api.get("624312ff-d14b-4ba3-9834-1c78d23d574d"));
}
public void testCreateReturns2xx() {
SubnetApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/subnets").method("POST")
.payload(payloadFromStringWithContentType("{\"subnet\":{\"network_id\":\"1234567890\",\"ip_version\":4,\"cidr\":\"10.0.3.0/24\",\"name\":\"subnet-test\"}}", APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromStringWithContentType("{\"subnet\":{\"id\":\"12345\",\"tenant_id\":\"6789\",\"network_id\":\"1234567890\",\"ip_version\":4,\"cidr\":\"10.0.3.0/24\",\"name\":\"subnet-test\"}}", APPLICATION_JSON)).build())
.getSubnetApiForZone(ZONE);
Subnet net = api.create("1234567890", 4, "10.0.3.0/24", CreateSubnetOptions.builder().name("subnet-test").build());
assertEquals(net, Subnet.builder().id("12345").tenantId("6789").name("subnet-test").networkId("1234567890").ipVersion(4).cidr("10.0.3.0/24").build());
}
@Test(expectedExceptions = AuthorizationException.class)
public void testCreateReturns4xx() {
SubnetApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/subnets").method("POST")
.payload(payloadFromStringWithContentType("{\"subnet\":{\"network_id\":\"1234567890\",\"ip_version\":4,\"cidr\":\"10.0.3.0/24\",\"name\":\"subnet-test\"}}", APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(401).build())
.getSubnetApiForZone(ZONE);
api.create("1234567890", 4, "10.0.3.0/24", CreateSubnetOptions.builder().name("subnet-test").build());
}
public void testCreateBulkReturns2xx() {
SubnetApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/subnets").method("POST")
.payload(payloadFromStringWithContentType(
"{\"subnets\":[" +
"{\"network_id\":\"1234567890\",\"ip_version\":4,\"cidr\":\"10.0.3.0/24\",\"name\":\"subnet-test\"}," +
"{\"network_id\":\"9876543210\",\"ip_version\":4,\"cidr\":\"192.168.3.0/24\",\"name\":\"subnet-test-2\"}" +
"]}", APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromStringWithContentType(
"{\"subnets\":[" +
"{\"id\":\"1\",\"tenant_id\":\"1\",\"network_id\":\"1234567890\",\"ip_version\":4,\"cidr\":\"10.0.3.0/24\",\"name\":\"subnet-test\"}," +
"{\"id\":\"2\",\"tenant_id\":\"1\",\"network_id\":\"9876543210\",\"ip_version\":4,\"cidr\":\"192.168.3.0/24\",\"name\":\"subnet-test-2\"}" +
"]}", APPLICATION_JSON)).build())
.getSubnetApiForZone(ZONE);
Set<? extends Subnet> nets = api.createBulk(
CreateSubnetBulkOptions.builder().subnets(
ImmutableList.of(
BulkSubnet.builder().networkId("1234567890").ipVersion(4).cidr("10.0.3.0/24").name("subnet-test").build(),
BulkSubnet.builder().networkId("9876543210").ipVersion(4).cidr("192.168.3.0/24").name("subnet-test-2").build()
)
).build()
).toSet();
assertEquals(nets, createBulkReturns2xxResponse());
}
@Test(expectedExceptions = AuthorizationException.class)
public void testCreateBulkReturns4xx() {
SubnetApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/subnets").method("POST")
.payload(payloadFromStringWithContentType(
"{\"subnets\":[" +
"{\"network_id\":\"1234567890\",\"ip_version\":4,\"cidr\":\"10.0.3.0/24\",\"name\":\"subnet-test\"}," +
"{\"network_id\":\"9876543210\",\"ip_version\":4,\"cidr\":\"192.168.3.0/24\",\"name\":\"subnet-test-2\"}" +
"]}", APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(401).build())
.getSubnetApiForZone(ZONE);
api.createBulk(
CreateSubnetBulkOptions.builder().subnets(
ImmutableList.of(
BulkSubnet.builder().networkId("1234567890").ipVersion(4).cidr("10.0.3.0/24").name("subnet-test").build(),
BulkSubnet.builder().networkId("9876543210").ipVersion(4).cidr("192.168.3.0/24").name("subnet-test-2").build()
)
).build()
);
}
public void testUpdateReturns2xx() {
SubnetApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/subnets/12345").method("PUT")
.payload(payloadFromStringWithContentType("{\"subnet\":{\"name\":\"another-test\",\"gateway_ip\":\"13.13.13.13\"}}", APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(200).build())
.getSubnetApiForZone(ZONE);
assertTrue(api.update("12345", UpdateSubnetOptions.builder().name("another-test").gatewayIp("13.13.13.13").build()));
}
public void testUpdateReturns4xx() {
SubnetApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/subnets/12345").method("PUT")
.payload(payloadFromStringWithContentType("{\"subnet\":{\"name\":\"another-test\",\"gateway_ip\":\"13.13.13.13\"}}", APPLICATION_JSON)).build(),
HttpResponse.builder().statusCode(404).build())
.getSubnetApiForZone(ZONE);
assertFalse(api.update("12345", UpdateSubnetOptions.builder().name("another-test").gatewayIp("13.13.13.13").build()));
}
public void testDeleteReturns2xx() {
SubnetApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/subnets/12345").method("DELETE").build(),
HttpResponse.builder().statusCode(200).build())
.getSubnetApiForZone(ZONE);
assertTrue(api.delete("12345"));
}
@Test(expectedExceptions = AuthorizationException.class)
public void testDeleteReturns4xx() {
SubnetApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
authenticatedGET().endpoint(endpoint + "/subnets/12345").method("DELETE").build(),
HttpResponse.builder().statusCode(403).build())
.getSubnetApiForZone(ZONE);
api.delete("12345");
}
protected Set<Subnet> listOfSubnets() {
return ImmutableSet.of(
Subnet.builder().ipVersion(4).cidr("10.0.3.0/24").networkId("1234567890").name("jclouds-test").tenantId("1234567890").id("16dba3bc-f3fa-4775-afdc-237e12c72f6a").build(),
Subnet.builder().ipVersion(4).cidr("10.0.3.0/24").networkId("1234567890").name("wibble").tenantId("1234567890").id("1a104cf5-cb18-4d35-9407-2fd2646d9d0b").build(),
Subnet.builder().ipVersion(4).cidr("10.0.3.0/24").networkId("1234567890").name("jclouds-test").tenantId("1234567890").id("31083ae2-420d-48b2-ac98-9f7a4fd8dbdc").build(),
Subnet.builder().ipVersion(4).cidr("10.0.3.0/24").networkId("1234567890").name("jclouds-test").tenantId("1234567890").id("49c6d6fa-ff2a-459d-b975-75a8d31c9a89").build(),
Subnet.builder().ipVersion(4).cidr("10.0.3.0/24").networkId("1234567890").name("wibble").tenantId("1234567890").id("5cb3d6f4-62cb-41c9-b964-ba7d9df79e4e").build(),
Subnet.builder().ipVersion(4).cidr("10.0.3.0/24").networkId("1234567890").name("jclouds-test").tenantId("1234567890").id("5d51d012-3491-4db7-b1b5-6f254015015d").build(),
Subnet.builder().ipVersion(4).cidr("10.0.3.0/24").networkId("1234567890").name("wibble").tenantId("1234567890").id("5f9cf7dc-22ca-4097-8e49-1cc8b23faf17").build(),
Subnet.builder().ipVersion(4).cidr("10.0.3.0/24").networkId("1234567890").name("jclouds-test").tenantId("1234567890").id("6319ecad-6bff-48b2-9b53-02ede8cb7588").build(),
Subnet.builder().ipVersion(4).cidr("10.0.3.0/24").networkId("1234567890").name("jclouds-test").tenantId("1234567890").id("6ba4c788-661f-49ab-9bf8-5f10cbbb2f57").build(),
Subnet.builder().ipVersion(4).cidr("10.0.3.0/24").networkId("1234567890").name("jclouds-test").tenantId("1234567890").id("74ed170b-5069-4353-ab38-9719766dc57e").build(),
Subnet.builder().ipVersion(4).cidr("10.0.3.0/24").networkId("1234567890").name("wibble").tenantId("1234567890").id("b71fcac1-e864-4031-8c5b-edbecd9ece36").build(),
Subnet.builder().ipVersion(4).cidr("10.0.3.0/24").networkId("1234567890").name("jclouds-test").tenantId("1234567890").id("c7681895-d84d-4650-9ca0-82c72036b855").build()
);
}
protected Set<Subnet> createBulkReturns2xxResponse() {
return ImmutableSet.of(
Subnet.builder().id("1").tenantId("1").name("subnet-test").networkId("1234567890").ipVersion(4).cidr("10.0.3.0/24").build(),
Subnet.builder().id("2").tenantId("1").name("subnet-test-2").networkId("9876543210").ipVersion(4).cidr("192.168.3.0/24").build()
);
}
}

View File

@ -0,0 +1,126 @@
/*
* 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_0.features;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.jclouds.openstack.neutron.v2_0.domain.*;
import org.jclouds.openstack.neutron.v2_0.internal.BaseNeutronApiLiveTest;
import org.jclouds.openstack.neutron.v2_0.options.CreateNetworkOptions;
import org.jclouds.openstack.neutron.v2_0.options.CreateSubnetBulkOptions;
import org.jclouds.openstack.neutron.v2_0.options.CreateSubnetOptions;
import org.jclouds.openstack.neutron.v2_0.options.UpdateSubnetOptions;
import java.util.Set;
import static org.testng.Assert.*;
/**
* Tests subnet api in combination with the network api
*
* @author Nick Livens
*/
public class SubnetApiLiveTest extends BaseNeutronApiLiveTest {
public void testGetAndListSubnets() {
for (String zone : api.getConfiguredZones()) {
Set<? extends ReferenceWithName> references = api.getSubnetApiForZone(zone).list().concat().toSet();
Set<? extends Subnet> subnets = api.getSubnetApiForZone(zone).listInDetail().concat().toSet();
assertNotNull(references);
assertNotNull(subnets);
assertEquals(references.size(), subnets.size());
for (Subnet subnet : subnets) {
assertNotNull(subnet.getNetworkId());
assertTrue(references.contains(ReferenceWithName.builder().id(subnet.getId()).tenantId(subnet.getTenantId()).name(subnet.getName()).build()));
Subnet retrievedSubnet = api.getSubnetApiForZone(zone).get(subnet.getId());
assertEquals(retrievedSubnet, subnet);
}
}
}
public void testCreateUpdateAndDeleteSubnet() {
for (String zone : api.getConfiguredZones()) {
NetworkApi networkApi = api.getNetworkApiForZone(zone);
String networkId = networkApi.create(CreateNetworkOptions.builder().name("jclouds-live-test").networkType(NetworkType.LOCAL).build()).getId();
SubnetApi subnetApi = api.getSubnetApiForZone(zone);
Set<AllocationPool> allocationPools = ImmutableSet.of(
AllocationPool.builder().start("a3:bc00::10").end("a3:bc00::20").build(),
AllocationPool.builder().start("a3:bc00::50").end("a3:bc00::90").build()
);
Set<HostRoute> hostRoutes = ImmutableSet.of(
HostRoute.builder().destinationCidr("a3:bc00::/48").nextHop("a3:bc00::0004").build()
);
Subnet subnet = subnetApi.create(networkId, 6, "a3:bc00::/48", CreateSubnetOptions.builder().allocationPools(allocationPools).hostRoutes(hostRoutes).build());
assertNotNull(subnet);
Subnet retrievedSubnet = subnetApi.get(subnet.getId());
assertEquals(retrievedSubnet.getId(), subnet.getId());
assertEquals(retrievedSubnet.getCidr(), "a3:bc00::/48");
assertTrue(retrievedSubnet.getDnsNameServers().isEmpty());
assertEquals(retrievedSubnet.getAllocationPools().size(), 2);
assertEquals(retrievedSubnet.getHostRoutes().size(), 1);
assertTrue(subnetApi.update(retrievedSubnet.getId(), UpdateSubnetOptions.builder().name("jclouds-live-test-update").build()));
retrievedSubnet = subnetApi.get(retrievedSubnet.getId());
assertEquals(retrievedSubnet.getId(), subnet.getId());
assertEquals(retrievedSubnet.getName(), "jclouds-live-test-update");
assertTrue(retrievedSubnet.getDnsNameServers().isEmpty());
Subnet subnet2 = subnetApi.create(networkId, 6, "a3:bd01::/48");
assertNotNull(subnet2);
assertTrue(subnetApi.delete(subnet.getId()));
assertTrue(subnetApi.delete(subnet2.getId()));
assertTrue(networkApi.delete(networkId));
}
}
public void testBulkCreateSubnet() {
for (String zone : api.getConfiguredZones()) {
NetworkApi networkApi = api.getNetworkApiForZone(zone);
String networkId = networkApi.create(CreateNetworkOptions.builder().name("jclouds-live-test").networkType(NetworkType.LOCAL).build()).getId();
SubnetApi subnetApi = api.getSubnetApiForZone(zone);
Set<? extends Subnet> subnets = subnetApi.createBulk(
CreateSubnetBulkOptions.builder().subnets(
ImmutableList.of(
BulkSubnet.builder().name("jclouds-live-test-1").cidr("a3:bd01::/48").ipVersion(6).networkId(networkId).build(),
BulkSubnet.builder().name("jclouds-live-test-2").cidr("a3:bd02::/48").ipVersion(6).networkId(networkId).build(),
BulkSubnet.builder().name("jclouds-live-test-3").cidr("a3:bd03::/48").ipVersion(6).networkId(networkId).build()
)
).build()
).toSet();
Set<? extends Subnet> existingSubnets = subnetApi.listInDetail().concat().toSet();
assertNotNull(subnets);
assertTrue(!subnets.isEmpty());
assertEquals(subnets.size(), 3);
for (Subnet net : subnets) {
assertTrue(existingSubnets.contains(net));
assertTrue(subnetApi.delete(net.getId()));
}
assertTrue(networkApi.delete(networkId));
}
}
}

View File

@ -0,0 +1,69 @@
/**
* 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_0.internal;
import com.google.common.collect.ImmutableSet;
import org.jclouds.openstack.neutron.v2_0.NeutronApi;
import org.jclouds.openstack.neutron.v2_0.domain.Reference;
import org.jclouds.openstack.neutron.v2_0.domain.ReferenceWithName;
import java.util.Set;
/**
* Base class for writing Neutron Rest Api Expect tests
*
* @author Nick Livens
*/
public class BaseNeutronApiExpectTest extends BaseNeutronExpectTest<NeutronApi> {
protected Set<Reference> listOfReferences() {
return ImmutableSet.of(
Reference.builder().tenantId("1234567890").id("16dba3bc-f3fa-4775-afdc-237e12c72f6a").build(),
Reference.builder().tenantId("1234567890").id("1a104cf5-cb18-4d35-9407-2fd2646d9d0b").build(),
Reference.builder().tenantId("1234567890").id("31083ae2-420d-48b2-ac98-9f7a4fd8dbdc").build(),
Reference.builder().tenantId("1234567890").id("49c6d6fa-ff2a-459d-b975-75a8d31c9a89").build(),
Reference.builder().tenantId("1234567890").id("5cb3d6f4-62cb-41c9-b964-ba7d9df79e4e").build(),
Reference.builder().tenantId("1234567890").id("5d51d012-3491-4db7-b1b5-6f254015015d").build(),
Reference.builder().tenantId("1234567890").id("5f9cf7dc-22ca-4097-8e49-1cc8b23faf17").build(),
Reference.builder().tenantId("1234567890").id("6319ecad-6bff-48b2-9b53-02ede8cb7588").build(),
Reference.builder().tenantId("1234567890").id("6ba4c788-661f-49ab-9bf8-5f10cbbb2f57").build(),
Reference.builder().tenantId("1234567890").id("74ed170b-5069-4353-ab38-9719766dc57e").build(),
Reference.builder().tenantId("1234567890").id("b71fcac1-e864-4031-8c5b-edbecd9ece36").build(),
Reference.builder().tenantId("1234567890").id("c7681895-d84d-4650-9ca0-82c72036b855").build()
);
}
protected Set<ReferenceWithName> listOfReferencesWithNames() {
return ImmutableSet.of(
ReferenceWithName.builder().name("jclouds-test").tenantId("1234567890").id("16dba3bc-f3fa-4775-afdc-237e12c72f6a").build(),
ReferenceWithName.builder().name("wibble").tenantId("1234567890").id("1a104cf5-cb18-4d35-9407-2fd2646d9d0b").build(),
ReferenceWithName.builder().name("jclouds-test").tenantId("1234567890").id("31083ae2-420d-48b2-ac98-9f7a4fd8dbdc").build(),
ReferenceWithName.builder().name("jclouds-test").tenantId("1234567890").id("49c6d6fa-ff2a-459d-b975-75a8d31c9a89").build(),
ReferenceWithName.builder().name("wibble").tenantId("1234567890").id("5cb3d6f4-62cb-41c9-b964-ba7d9df79e4e").build(),
ReferenceWithName.builder().name("jclouds-test").tenantId("1234567890").id("5d51d012-3491-4db7-b1b5-6f254015015d").build(),
ReferenceWithName.builder().name("wibble").tenantId("1234567890").id("5f9cf7dc-22ca-4097-8e49-1cc8b23faf17").build(),
ReferenceWithName.builder().name("jclouds-test").tenantId("1234567890").id("6319ecad-6bff-48b2-9b53-02ede8cb7588").build(),
ReferenceWithName.builder().name("jclouds-test").tenantId("1234567890").id("6ba4c788-661f-49ab-9bf8-5f10cbbb2f57").build(),
ReferenceWithName.builder().name("jclouds-test").tenantId("1234567890").id("74ed170b-5069-4353-ab38-9719766dc57e").build(),
ReferenceWithName.builder().name("wibble").tenantId("1234567890").id("b71fcac1-e864-4031-8c5b-edbecd9ece36").build(),
ReferenceWithName.builder().name("jclouds-test").tenantId("1234567890").id("c7681895-d84d-4650-9ca0-82c72036b855").build()
);
}
}

View File

@ -0,0 +1,47 @@
/**
* 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_0.internal;
import org.jclouds.apis.BaseApiLiveTest;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
import org.jclouds.openstack.neutron.v2_0.NeutronApi;
import org.testng.annotations.Test;
import java.util.Properties;
/**
* Tests behavior of {@code NeutronApi}
*
* @author Nick Livens
*/
@Test(groups = "live")
public class BaseNeutronApiLiveTest extends BaseApiLiveTest<NeutronApi> {
public BaseNeutronApiLiveTest() {
provider = "openstack-neutron";
}
@Override
protected Properties setupProperties() {
Properties props = super.setupProperties();
setIfTestSystemPropertyPresent(props, KeystoneProperties.CREDENTIAL_TYPE);
return props;
}
}

View File

@ -0,0 +1,67 @@
/**
* 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_0.internal;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.openstack.keystone.v2_0.internal.KeystoneFixture;
import org.jclouds.rest.internal.BaseRestApiExpectTest;
import javax.ws.rs.core.MediaType;
/**
* Base class for writing Neutron Expect tests
*
* @author Nick Livens
*/
public class BaseNeutronExpectTest<T> extends BaseRestApiExpectTest<T> {
protected HttpRequest keystoneAuthWithUsernameAndPassword;
protected HttpRequest keystoneAuthWithUsernameAndPasswordAndTenantName;
protected HttpRequest keystoneAuthWithAccessKeyAndSecretKeyAndTenantName;
protected String authToken;
protected HttpResponse responseWithKeystoneAccess;
protected HttpRequest keystoneAuthWithAccessKeyAndSecretKeyAndTenantId;
protected String identityWithTenantId;
protected String endpoint = "https://csnode.jclouds.org:9696/v2.0";
public BaseNeutronExpectTest() {
provider = "openstack-neutron";
keystoneAuthWithUsernameAndPassword = KeystoneFixture.INSTANCE.initialAuthWithUsernameAndPassword(identity,
credential);
keystoneAuthWithUsernameAndPasswordAndTenantName = KeystoneFixture.INSTANCE.initialAuthWithUsernameAndPasswordAndTenantName(identity,
credential);
keystoneAuthWithAccessKeyAndSecretKeyAndTenantName = KeystoneFixture.INSTANCE.initialAuthWithAccessKeyAndSecretKeyAndTenantName(identity,
credential);
keystoneAuthWithAccessKeyAndSecretKeyAndTenantId = KeystoneFixture.INSTANCE.initialAuthWithAccessKeyAndSecretKeyAndTenantId(identity,
credential);
authToken = KeystoneFixture.INSTANCE.getAuthToken();
responseWithKeystoneAccess = KeystoneFixture.INSTANCE.responseWithAccess();
// now, createContext arg will need tenant prefix
identityWithTenantId = KeystoneFixture.INSTANCE.getTenantId() + ":" + identity;
identity = KeystoneFixture.INSTANCE.getTenantName() + ":" + identity;
}
protected HttpRequest.Builder<?> authenticatedGET() {
return HttpRequest.builder()
.method("GET")
.addHeader("Accept", MediaType.APPLICATION_JSON)
.addHeader("X-Auth-Token", authToken);
}
}

View File

@ -0,0 +1,54 @@
/**
* 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_0.parse;
import org.jclouds.json.BaseItemParserTest;
import org.jclouds.openstack.neutron.v2_0.domain.Network;
import org.jclouds.openstack.neutron.v2_0.domain.NetworkType;
import org.jclouds.openstack.neutron.v2_0.domain.State;
import org.jclouds.rest.annotations.SelectJson;
import org.testng.annotations.Test;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
/**
* @author Nick Livens
*/
@Test(groups = "unit", testName = "ParseNetworkTest")
public class ParseNetworkTest extends BaseItemParserTest<Network> {
@Override
public String resource() {
return "/network.json";
}
@Override
@SelectJson("network")
@Consumes(MediaType.APPLICATION_JSON)
public Network expected() {
return Network.builder()
.networkType(NetworkType.LOCAL)
.state(State.ACTIVE)
.name("jclouds-wibble")
.tenantId("1234567890")
.id("624312ff-d14b-4ba3-9834-1c78d23d574d")
.build();
}
}

View File

@ -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.neutron.v2_0.parse;
import org.jclouds.json.BaseItemParserTest;
import org.jclouds.openstack.neutron.v2_0.domain.Port;
import org.jclouds.openstack.neutron.v2_0.domain.State;
import org.jclouds.rest.annotations.SelectJson;
import org.testng.annotations.Test;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
/**
* @author Nick Livens
*/
@Test(groups = "unit", testName = "ParsePortTest")
public class ParsePortTest extends BaseItemParserTest<Port> {
@Override
public String resource() {
return "/port.json";
}
@Override
@SelectJson("port")
@Consumes(MediaType.APPLICATION_JSON)
public Port expected() {
return Port.builder()
.state(State.ACTIVE)
.networkId("1234567890")
.name("jclouds-wibble")
.tenantId("1234567890")
.id("624312ff-d14b-4ba3-9834-1c78d23d574d")
.build();
}
}

View File

@ -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.neutron.v2_0.parse;
import org.jclouds.json.BaseItemParserTest;
import org.jclouds.openstack.neutron.v2_0.domain.Subnet;
import org.jclouds.rest.annotations.SelectJson;
import org.testng.annotations.Test;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
/**
* @author Nick Livens
*/
@Test(groups = "unit", testName = "ParseSubnetTest")
public class ParseSubnetTest extends BaseItemParserTest<Subnet> {
@Override
public String resource() {
return "/subnet.json";
}
@Override
@SelectJson("subnet")
@Consumes(MediaType.APPLICATION_JSON)
public Subnet expected() {
return Subnet.builder()
.ipVersion(4)
.cidr("10.0.3.0/24")
.networkId("1234567890")
.name("jclouds-wibble")
.tenantId("1234567890")
.id("624312ff-d14b-4ba3-9834-1c78d23d574d")
.build();
}
}

View File

@ -0,0 +1,62 @@
{"networks":[
{
"name":"jclouds-test",
"tenant_id":"1234567890",
"id":"16dba3bc-f3fa-4775-afdc-237e12c72f6a"
},
{
"name":"wibble",
"tenant_id":"1234567890",
"id":"1a104cf5-cb18-4d35-9407-2fd2646d9d0b"
},
{
"name":"jclouds-test",
"tenant_id":"1234567890",
"id":"31083ae2-420d-48b2-ac98-9f7a4fd8dbdc"
},
{
"name":"jclouds-test",
"tenant_id":"1234567890",
"id":"49c6d6fa-ff2a-459d-b975-75a8d31c9a89"
},
{
"name":"wibble",
"tenant_id":"1234567890",
"id":"5cb3d6f4-62cb-41c9-b964-ba7d9df79e4e"
},
{
"name":"jclouds-test",
"tenant_id":"1234567890",
"id":"5d51d012-3491-4db7-b1b5-6f254015015d"
},
{
"name":"wibble",
"tenant_id":"1234567890",
"id":"5f9cf7dc-22ca-4097-8e49-1cc8b23faf17"
},
{
"name":"jclouds-test",
"tenant_id":"1234567890",
"id":"6319ecad-6bff-48b2-9b53-02ede8cb7588"
},
{
"name":"jclouds-test",
"tenant_id":"1234567890",
"id":"6ba4c788-661f-49ab-9bf8-5f10cbbb2f57"
},
{
"name":"jclouds-test",
"tenant_id":"1234567890",
"id":"74ed170b-5069-4353-ab38-9719766dc57e"
},
{
"name":"wibble",
"tenant_id":"1234567890",
"id":"b71fcac1-e864-4031-8c5b-edbecd9ece36"
},
{
"name":"jclouds-test",
"tenant_id":"1234567890",
"id":"c7681895-d84d-4650-9ca0-82c72036b855"
}
]}

View File

@ -0,0 +1,86 @@
{"ports":[
{
"status":"ACTIVE",
"network_id":"1234567890",
"name":"jclouds-test",
"tenant_id":"1234567890",
"id":"16dba3bc-f3fa-4775-afdc-237e12c72f6a"
},
{
"status":"ACTIVE",
"network_id":"1234567890",
"name":"wibble",
"tenant_id":"1234567890",
"id":"1a104cf5-cb18-4d35-9407-2fd2646d9d0b"
},
{
"status":"ACTIVE",
"network_id":"1234567890",
"name":"jclouds-test",
"tenant_id":"1234567890",
"id":"31083ae2-420d-48b2-ac98-9f7a4fd8dbdc"
},
{
"status":"ACTIVE",
"network_id":"1234567890",
"name":"jclouds-test",
"tenant_id":"1234567890",
"id":"49c6d6fa-ff2a-459d-b975-75a8d31c9a89"
},
{
"status":"ACTIVE",
"network_id":"1234567890",
"name":"wibble",
"tenant_id":"1234567890",
"id":"5cb3d6f4-62cb-41c9-b964-ba7d9df79e4e"
},
{
"status":"ACTIVE",
"network_id":"1234567890",
"name":"jclouds-test",
"tenant_id":"1234567890",
"id":"5d51d012-3491-4db7-b1b5-6f254015015d"
},
{
"status":"ACTIVE",
"network_id":"1234567890",
"name":"wibble",
"tenant_id":"1234567890",
"id":"5f9cf7dc-22ca-4097-8e49-1cc8b23faf17"
},
{
"status":"ACTIVE",
"network_id":"1234567890",
"name":"jclouds-test",
"tenant_id":"1234567890",
"id":"6319ecad-6bff-48b2-9b53-02ede8cb7588"
},
{
"status":"ACTIVE",
"network_id":"1234567890",
"name":"jclouds-test",
"tenant_id":"1234567890",
"id":"6ba4c788-661f-49ab-9bf8-5f10cbbb2f57"
},
{
"status":"ACTIVE",
"network_id":"1234567890",
"name":"jclouds-test",
"tenant_id":"1234567890",
"id":"74ed170b-5069-4353-ab38-9719766dc57e"
},
{
"status":"ACTIVE",
"network_id":"1234567890",
"name":"wibble",
"tenant_id":"1234567890",
"id":"b71fcac1-e864-4031-8c5b-edbecd9ece36"
},
{
"status":"ACTIVE",
"network_id":"1234567890",
"name":"jclouds-test",
"tenant_id":"1234567890",
"id":"c7681895-d84d-4650-9ca0-82c72036b855"
}
]}

View File

@ -0,0 +1,98 @@
{"subnets":[
{
"ip_version":4,
"cidr":"10.0.3.0/24",
"network_id":"1234567890",
"name":"jclouds-test",
"tenant_id":"1234567890",
"id":"16dba3bc-f3fa-4775-afdc-237e12c72f6a"
},
{
"ip_version":4,
"cidr":"10.0.3.0/24",
"network_id":"1234567890",
"name":"wibble",
"tenant_id":"1234567890",
"id":"1a104cf5-cb18-4d35-9407-2fd2646d9d0b"
},
{
"ip_version":4,
"cidr":"10.0.3.0/24",
"network_id":"1234567890",
"name":"jclouds-test",
"tenant_id":"1234567890",
"id":"31083ae2-420d-48b2-ac98-9f7a4fd8dbdc"
},
{
"ip_version":4,
"cidr":"10.0.3.0/24",
"network_id":"1234567890",
"name":"jclouds-test",
"tenant_id":"1234567890",
"id":"49c6d6fa-ff2a-459d-b975-75a8d31c9a89"
},
{
"ip_version":4,
"cidr":"10.0.3.0/24",
"network_id":"1234567890",
"name":"wibble",
"tenant_id":"1234567890",
"id":"5cb3d6f4-62cb-41c9-b964-ba7d9df79e4e"
},
{
"ip_version":4,
"cidr":"10.0.3.0/24",
"network_id":"1234567890",
"name":"jclouds-test",
"tenant_id":"1234567890",
"id":"5d51d012-3491-4db7-b1b5-6f254015015d"
},
{
"ip_version":4,
"cidr":"10.0.3.0/24",
"network_id":"1234567890",
"name":"wibble",
"tenant_id":"1234567890",
"id":"5f9cf7dc-22ca-4097-8e49-1cc8b23faf17"
},
{
"ip_version":4,
"cidr":"10.0.3.0/24",
"network_id":"1234567890",
"name":"jclouds-test",
"tenant_id":"1234567890",
"id":"6319ecad-6bff-48b2-9b53-02ede8cb7588"
},
{
"ip_version":4,
"cidr":"10.0.3.0/24",
"network_id":"1234567890",
"name":"jclouds-test",
"tenant_id":"1234567890",
"id":"6ba4c788-661f-49ab-9bf8-5f10cbbb2f57"
},
{
"ip_version":4,
"cidr":"10.0.3.0/24",
"network_id":"1234567890",
"name":"jclouds-test",
"tenant_id":"1234567890",
"id":"74ed170b-5069-4353-ab38-9719766dc57e"
},
{
"ip_version":4,
"cidr":"10.0.3.0/24",
"network_id":"1234567890",
"name":"wibble",
"tenant_id":"1234567890",
"id":"b71fcac1-e864-4031-8c5b-edbecd9ece36"
},
{
"ip_version":4,
"cidr":"10.0.3.0/24",
"network_id":"1234567890",
"name":"jclouds-test",
"tenant_id":"1234567890",
"id":"c7681895-d84d-4650-9ca0-82c72036b855"
}
]}

View File

@ -0,0 +1,69 @@
<?xml version="1.0"?>
<!--
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.
-->
<configuration scan="false">
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>target/test-data/jclouds.log</file>
<encoder>
<Pattern>%d %-5p [%c] [%thread] %m%n</Pattern>
</encoder>
</appender>
<appender name="WIREFILE" class="ch.qos.logback.core.FileAppender">
<file>target/test-data/jclouds-wire.log</file>
<encoder>
<Pattern>%d %-5p [%c] [%thread] %m%n</Pattern>
</encoder>
</appender>
<appender name="BLOBSTOREFILE" class="ch.qos.logback.core.FileAppender">
<file>target/test-data/jclouds-blobstore.log</file>
<encoder>
<Pattern>%d %-5p [%c] [%thread] %m%n</Pattern>
</encoder>
</appender>
<root>
<level value="warn" />
</root>
<logger name="org.jclouds">
<level value="DEBUG" />
<appender-ref ref="FILE" />
</logger>
<logger name="jclouds.wire">
<level value="DEBUG" />
<appender-ref ref="WIREFILE" />
</logger>
<logger name="jclouds.headers">
<level value="DEBUG" />
<appender-ref ref="WIREFILE" />
</logger>
<logger name="jclouds.blobstore">
<level value="DEBUG" />
<appender-ref ref="BLOBSTOREFILE" />
</logger>
</configuration>

View File

@ -0,0 +1,7 @@
{"network":{
"provider:network_type":"local",
"status":"ACTIVE",
"name":"jclouds-wibble",
"tenant_id":"1234567890",
"id":"624312ff-d14b-4ba3-9834-1c78d23d574d"
}}

View File

@ -0,0 +1,7 @@
{"port":{
"status":"ACTIVE",
"network_id":"1234567890",
"name":"jclouds-wibble",
"tenant_id":"1234567890",
"id":"624312ff-d14b-4ba3-9834-1c78d23d574d"
}}

View File

@ -0,0 +1,8 @@
{"subnet":{
"ip_version":4,
"cidr":"10.0.3.0/24",
"network_id":"1234567890",
"name":"jclouds-wibble",
"tenant_id":"1234567890",
"id":"624312ff-d14b-4ba3-9834-1c78d23d574d"
}}