mirror of https://github.com/apache/jclouds.git
Remove deprecated neutron code
This commit is contained in:
parent
0128e91dc0
commit
83b104d9a0
|
@ -1,133 +0,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.
|
||||
*/
|
||||
|
||||
package org.jclouds.openstack.neutron.v2_0;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.location.Region;
|
||||
import org.jclouds.location.Zone;
|
||||
import org.jclouds.location.functions.RegionToEndpoint;
|
||||
import org.jclouds.location.functions.ZoneToEndpoint;
|
||||
import org.jclouds.openstack.neutron.v2_0.extensions.RouterApi;
|
||||
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 com.google.common.base.Optional;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
* Provides access to the OpenStack Networking (Neutron) v2 API.
|
||||
* <p/>
|
||||
*
|
||||
* @deprecated Please use {@link org.jclouds.openstack.neutron.v2.NeutronApi} instead. To be removed in jclouds 2.0.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface NeutronApi extends Closeable {
|
||||
|
||||
/**
|
||||
* @return the Region codes configured
|
||||
*/
|
||||
@Provides
|
||||
@Region
|
||||
Set<String> getConfiguredRegions();
|
||||
|
||||
/**
|
||||
* Provides access to Extension features.
|
||||
*/
|
||||
@Delegate
|
||||
ExtensionApi getExtensionApi(@EndpointParam(parser = RegionToEndpoint.class) String region);
|
||||
|
||||
/**
|
||||
* Provides access to Network features.
|
||||
*/
|
||||
@Delegate
|
||||
NetworkApi getNetworkApi(@EndpointParam(parser = RegionToEndpoint.class) String region);
|
||||
|
||||
/**
|
||||
* Provides access to Subnet features.
|
||||
*/
|
||||
@Delegate
|
||||
SubnetApi getSubnetApi(@EndpointParam(parser = RegionToEndpoint.class) String region);
|
||||
|
||||
/**
|
||||
* Provides access to Port features.
|
||||
*/
|
||||
@Delegate
|
||||
PortApi getPortApi(@EndpointParam(parser = RegionToEndpoint.class) String region);
|
||||
|
||||
/**
|
||||
* Provides access to Router features.
|
||||
*/
|
||||
@Delegate
|
||||
Optional<? extends RouterApi> getRouterApi(@EndpointParam(parser = RegionToEndpoint.class) String region);
|
||||
|
||||
/**
|
||||
* @return the Zone codes configured
|
||||
* @deprecated Please use {@link #getConfiguredRegions()} instead. To be removed in jclouds 2.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Provides
|
||||
@Zone
|
||||
Set<String> getConfiguredZones();
|
||||
|
||||
/**
|
||||
* Provides access to Extension features.
|
||||
* @deprecated Please use {@link #getExtensionApi(String)} instead. To be removed in jclouds 2.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
ExtensionApi getExtensionApiForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) String zone);
|
||||
|
||||
/**
|
||||
* Provides access to Network features.
|
||||
* @deprecated Please use {@link #getNetworkApi(String)} instead. To be removed in jclouds 2.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
NetworkApi getNetworkApiForZone(@EndpointParam(parser = ZoneToEndpoint.class) String zone);
|
||||
|
||||
/**
|
||||
* Provides access to Subnet features.
|
||||
* @deprecated Please use {@link #getSubnetApi(String)} instead. To be removed in jclouds 2.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
SubnetApi getSubnetApiForZone(@EndpointParam(parser = ZoneToEndpoint.class) String zone);
|
||||
|
||||
/**
|
||||
* Provides access to Port features.
|
||||
* @deprecated Please use {@link #getPortApi(String)} instead. To be removed in jclouds 2.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
PortApi getPortApiForZone(@EndpointParam(parser = ZoneToEndpoint.class) String zone);
|
||||
|
||||
/**
|
||||
* Provides access to Router features.
|
||||
* @deprecated Please use {@link #getRouterApi(String)} instead. To be removed in jclouds 2.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
Optional<? extends RouterApi> getRouterExtensionForZone(@EndpointParam(parser = ZoneToEndpoint.class) String zone);
|
||||
}
|
|
@ -1,104 +0,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.
|
||||
*/
|
||||
|
||||
package org.jclouds.openstack.neutron.v2_0;
|
||||
|
||||
import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE;
|
||||
import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.SERVICE_TYPE;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
|
||||
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 com.google.auto.service.AutoService;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
* Implementation of {@link org.jclouds.apis.ApiMetadata} for Neutron 2.0 API
|
||||
* @deprecated To be removed in jclouds 2.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@AutoService(ApiMetadata.class)
|
||||
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(CREDENTIAL_TYPE, CredentialTypes.PASSWORD_CREDENTIALS);
|
||||
properties.setProperty(SERVICE_TYPE, ServiceType.NETWORK);
|
||||
return properties;
|
||||
}
|
||||
|
||||
public static class Builder extends BaseHttpApiMetadata.Builder<NeutronApi, Builder> {
|
||||
|
||||
protected Builder() {
|
||||
super(NeutronApi.class);
|
||||
id("openstack-neutron-legacy")
|
||||
.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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,78 +0,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.
|
||||
*/
|
||||
package org.jclouds.openstack.neutron.v2_0.config;
|
||||
|
||||
import static org.jclouds.openstack.keystone.v2_0.config.KeystoneHttpApiModule.aliasBinder;
|
||||
|
||||
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.inject.Provides;
|
||||
|
||||
/**
|
||||
* Configures the Neutron connection.
|
||||
*/
|
||||
@ConfiguresHttpApi
|
||||
public class NeutronHttpApiModule extends HttpApiModule<NeutronApi> {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||
bind(ImplicitOptionalConverter.class).to(PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet.class);
|
||||
super.configure();
|
||||
aliasBinder(binder());
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
|
@ -1,125 +0,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.
|
||||
*/
|
||||
|
||||
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
|
||||
*
|
||||
* @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 abstract static 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,208 +0,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.
|
||||
*/
|
||||
|
||||
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
|
||||
*/
|
||||
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 abstract static 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,230 +0,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.
|
||||
*/
|
||||
|
||||
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
|
||||
*/
|
||||
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 abstract static 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,273 +0,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.
|
||||
*/
|
||||
|
||||
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
|
||||
*/
|
||||
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 abstract static 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,102 +0,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.
|
||||
*/
|
||||
|
||||
package org.jclouds.openstack.neutron.v2_0.domain;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
/**
|
||||
* Information on external gateway for the router
|
||||
*/
|
||||
public class ExternalGatewayInfo {
|
||||
|
||||
private final String networkId;
|
||||
|
||||
@ConstructorProperties({"network_id"})
|
||||
protected ExternalGatewayInfo(String networkId) {
|
||||
this.networkId = networkId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the id of the network which is used as external gateway for the router
|
||||
*/
|
||||
public String getNetworkId() {
|
||||
return networkId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(networkId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null || getClass() != obj.getClass()) return false;
|
||||
ExternalGatewayInfo that = ExternalGatewayInfo.class.cast(obj);
|
||||
return Objects.equal(this.networkId, that.networkId);
|
||||
}
|
||||
|
||||
protected Objects.ToStringHelper string() {
|
||||
return Objects.toStringHelper(this).add("networkId", networkId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return string().toString();
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new ConcreteBuilder();
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return new ConcreteBuilder().fromExternalGatewayInfo(this);
|
||||
}
|
||||
|
||||
public abstract static class Builder {
|
||||
protected abstract Builder self();
|
||||
|
||||
protected String networkId;
|
||||
|
||||
/**
|
||||
* @see ExternalGatewayInfo#getNetworkId()
|
||||
*/
|
||||
public Builder networkId(String networkId) {
|
||||
this.networkId = networkId;
|
||||
return self();
|
||||
}
|
||||
|
||||
public ExternalGatewayInfo build() {
|
||||
return new ExternalGatewayInfo(networkId);
|
||||
}
|
||||
|
||||
public Builder fromExternalGatewayInfo(ExternalGatewayInfo in) {
|
||||
return this.networkId(in.getNetworkId());
|
||||
}
|
||||
}
|
||||
|
||||
private static class ConcreteBuilder extends Builder {
|
||||
@Override
|
||||
protected ConcreteBuilder self() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,126 +0,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.
|
||||
*/
|
||||
|
||||
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
|
||||
*
|
||||
* @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 abstract static 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,120 +0,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.
|
||||
*/
|
||||
|
||||
package org.jclouds.openstack.neutron.v2_0.domain;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
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 abstract static 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,255 +0,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.
|
||||
*/
|
||||
|
||||
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
|
||||
*
|
||||
* @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 != null ? NetworkType.fromValue(networkType) : null;
|
||||
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 abstract static 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,39 +0,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.
|
||||
*/
|
||||
|
||||
package org.jclouds.openstack.neutron.v2_0.domain;
|
||||
|
||||
/**
|
||||
* The type of Network
|
||||
*/
|
||||
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) {
|
||||
return NetworkType.valueOf(value.toUpperCase());
|
||||
}
|
||||
}
|
|
@ -1,234 +0,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.
|
||||
*/
|
||||
|
||||
package org.jclouds.openstack.neutron.v2_0.domain;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* A Neutron port
|
||||
*
|
||||
* @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 = checkNotNull(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 abstract static 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,127 +0,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.
|
||||
*/
|
||||
|
||||
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
|
||||
*
|
||||
* @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 abstract static 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,109 +0,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.
|
||||
*/
|
||||
|
||||
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
|
||||
*
|
||||
* @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 abstract static 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,149 +0,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.
|
||||
*/
|
||||
|
||||
package org.jclouds.openstack.neutron.v2_0.domain;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
/**
|
||||
* A Neutron Router
|
||||
*
|
||||
* @see <a href="http://docs.openstack.org/api/openstack-network/2.0/content/router_ext_concepts.html">api doc</a>
|
||||
*/
|
||||
public class Router extends ReferenceWithName {
|
||||
|
||||
private final Boolean adminStateUp;
|
||||
private final State state;
|
||||
private final ExternalGatewayInfo externalGatewayInfo;
|
||||
|
||||
@ConstructorProperties({
|
||||
"id", "tenant_id", "name", "admin_state_up", "status", "external_gateway_info"
|
||||
})
|
||||
protected Router(String id, String tenantId, String name, Boolean adminStateUp, State state, ExternalGatewayInfo externalGatewayInfo) {
|
||||
super(id, tenantId, name);
|
||||
this.adminStateUp = adminStateUp;
|
||||
this.state = state;
|
||||
this.externalGatewayInfo = externalGatewayInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the administrative state of the router
|
||||
*/
|
||||
public Boolean getAdminStateUp() {
|
||||
return adminStateUp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the current state of the router
|
||||
*/
|
||||
public State getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the information on external gateway for the router
|
||||
*/
|
||||
public ExternalGatewayInfo getExternalGatewayInfo() {
|
||||
return externalGatewayInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(super.hashCode(), adminStateUp, state, externalGatewayInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null || getClass() != obj.getClass()) return false;
|
||||
Router that = Router.class.cast(obj);
|
||||
return super.equals(obj)
|
||||
&& Objects.equal(this.adminStateUp, that.adminStateUp)
|
||||
&& Objects.equal(this.state, that.state)
|
||||
&& Objects.equal(this.externalGatewayInfo, that.externalGatewayInfo);
|
||||
}
|
||||
|
||||
protected Objects.ToStringHelper string() {
|
||||
return super.string()
|
||||
.add("adminStateUp", adminStateUp).add("state", state).add("externalGatewayInfo", externalGatewayInfo != null ? externalGatewayInfo.toString() : "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return string().toString();
|
||||
}
|
||||
|
||||
public static Builder<?> builder() {
|
||||
return new ConcreteBuilder();
|
||||
}
|
||||
|
||||
public Builder<?> toBuilder() {
|
||||
return new ConcreteBuilder().fromRouter(this);
|
||||
}
|
||||
|
||||
public abstract static class Builder<T extends Builder<T>> extends ReferenceWithName.Builder<T> {
|
||||
|
||||
protected Boolean adminStateUp;
|
||||
protected State state;
|
||||
protected ExternalGatewayInfo externalGatewayInfo;
|
||||
|
||||
/**
|
||||
* @see Router#getAdminStateUp()
|
||||
*/
|
||||
public T adminStateUp(Boolean adminStateUp) {
|
||||
this.adminStateUp = adminStateUp;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Router#getState()
|
||||
*/
|
||||
public T state(State state) {
|
||||
this.state = state;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Router#getExternalGatewayInfo()
|
||||
*/
|
||||
public T externalGatewayInfo(ExternalGatewayInfo externalGatewayInfo) {
|
||||
this.externalGatewayInfo = externalGatewayInfo;
|
||||
return self();
|
||||
}
|
||||
|
||||
public Router build() {
|
||||
return new Router(id, tenantId, name, adminStateUp, state, externalGatewayInfo);
|
||||
}
|
||||
|
||||
public T fromRouter(Router in) {
|
||||
return super.fromReference(in)
|
||||
.adminStateUp(in.getAdminStateUp())
|
||||
.state(in.getState())
|
||||
.externalGatewayInfo(in.getExternalGatewayInfo());
|
||||
}
|
||||
}
|
||||
|
||||
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||
@Override
|
||||
protected ConcreteBuilder self() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,125 +0,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.
|
||||
*/
|
||||
|
||||
package org.jclouds.openstack.neutron.v2_0.domain;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
/**
|
||||
* A Neutron Router Interface
|
||||
*
|
||||
* @see <a href="http://docs.openstack.org/api/openstack-network/2.0/content/router_add_interface.html">api doc</a>
|
||||
*/
|
||||
public class RouterInterface {
|
||||
|
||||
private final String subnetId;
|
||||
private final String portId;
|
||||
|
||||
@ConstructorProperties({
|
||||
"subnet_id", "port_id"
|
||||
})
|
||||
protected RouterInterface(String subnetId, String portId) {
|
||||
this.subnetId = subnetId;
|
||||
this.portId = portId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the id of the subnet this router interface is associated with
|
||||
*/
|
||||
public String getSubnetId() {
|
||||
return subnetId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the id of the port this router interface is associated with
|
||||
*/
|
||||
public String getPortId() {
|
||||
return portId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(subnetId, portId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null || getClass() != obj.getClass()) return false;
|
||||
RouterInterface that = RouterInterface.class.cast(obj);
|
||||
return Objects.equal(this.subnetId, that.subnetId) && Objects.equal(this.portId, that.portId);
|
||||
}
|
||||
|
||||
protected Objects.ToStringHelper string() {
|
||||
return Objects.toStringHelper(this)
|
||||
.add("subnetId", subnetId).add("portId", portId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return string().toString();
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new ConcreteBuilder();
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return new ConcreteBuilder().fromRouterInterface(this);
|
||||
}
|
||||
|
||||
public abstract static class Builder {
|
||||
protected abstract Builder self();
|
||||
|
||||
protected String subnetId;
|
||||
protected String portId;
|
||||
|
||||
/**
|
||||
* @see RouterInterface#getSubnetId()
|
||||
*/
|
||||
public Builder subnetId(String subnetId) {
|
||||
this.subnetId = subnetId;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see RouterInterface#getPortId()
|
||||
*/
|
||||
public Builder portId(String portId) {
|
||||
this.portId = portId;
|
||||
return self();
|
||||
}
|
||||
|
||||
public RouterInterface build() {
|
||||
return new RouterInterface(subnetId, portId);
|
||||
}
|
||||
|
||||
public Builder fromRouterInterface(RouterInterface in) {
|
||||
return this.subnetId(in.getSubnetId()).portId(in.getPortId());
|
||||
}
|
||||
}
|
||||
|
||||
private static class ConcreteBuilder extends Builder {
|
||||
@Override
|
||||
protected ConcreteBuilder self() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,27 +0,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.
|
||||
*/
|
||||
|
||||
package org.jclouds.openstack.neutron.v2_0.domain;
|
||||
|
||||
/**
|
||||
* The possible state of an entity
|
||||
*
|
||||
* @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
|
||||
}
|
|
@ -1,264 +0,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.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* A Neutron subnet
|
||||
*
|
||||
* @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 = checkNotNull(networkId, "networkId");
|
||||
this.gatewayIp = gatewayIp;
|
||||
this.ipVersion = checkNotNull(ipVersion, "ipVersion");
|
||||
this.cidr = checkNotNull(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 abstract static 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,215 +0,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.
|
||||
*/
|
||||
|
||||
package org.jclouds.openstack.neutron.v2_0.extensions;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.Fallbacks;
|
||||
import org.jclouds.collect.PagedIterable;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.openstack.keystone.v2_0.KeystoneFallbacks.EmptyPaginatedCollectionOnNotFoundOr404;
|
||||
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.Router;
|
||||
import org.jclouds.openstack.neutron.v2_0.domain.RouterInterface;
|
||||
import org.jclouds.openstack.neutron.v2_0.functions.ParseRouterDetails;
|
||||
import org.jclouds.openstack.neutron.v2_0.functions.ParseRouters;
|
||||
import org.jclouds.openstack.neutron.v2_0.options.CreateRouterOptions;
|
||||
import org.jclouds.openstack.neutron.v2_0.options.EmptyOptions;
|
||||
import org.jclouds.openstack.neutron.v2_0.options.UpdateRouterOptions;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Provides access to Router operations for the OpenStack Networking (Neutron) v2 API.
|
||||
* <p/>
|
||||
* A logical entity for forwarding packets across internal subnets and NATting them on external
|
||||
* networks through an appropriate external gateway.
|
||||
*
|
||||
* @deprecated Please use {@link org.jclouds.openstack.neutron.v2.extensions.RouterApi} instead.
|
||||
* To be removed in jclouds 2.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Path("/v2.0/routers")
|
||||
@RequestFilters(AuthenticateRequest.class)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public interface RouterApi {
|
||||
|
||||
/**
|
||||
* Returns the list of all routers currently defined in Neutron for the current tenant. The list provides the unique
|
||||
* identifier of each router configured for the tenant
|
||||
*
|
||||
* @return the list of all router references configured for the tenant.
|
||||
*/
|
||||
@Named("router:list")
|
||||
@GET
|
||||
@ResponseParser(ParseRouters.class)
|
||||
@Transform(ParseRouters.ToPagedIterable.class)
|
||||
@Fallback(Fallbacks.EmptyPagedIterableOnNotFoundOr404.class)
|
||||
@QueryParams(keys = {"fields", "fields", "fields"}, values = {"id", "tenant_id", "name"})
|
||||
PagedIterable<? extends ReferenceWithName> list();
|
||||
|
||||
/**
|
||||
* @see <a href="http://docs.openstack.org/api/openstack-network/2.0/content/pagination.html">api doc</a>
|
||||
*/
|
||||
@Named("router:list")
|
||||
@GET
|
||||
@ResponseParser(ParseRouters.class)
|
||||
@Fallback(EmptyPaginatedCollectionOnNotFoundOr404.class)
|
||||
@QueryParams(keys = {"fields", "fields", "fields"}, values = {"id", "tenant_id", "name"})
|
||||
PagedIterable<? extends ReferenceWithName> list(PaginationOptions options);
|
||||
|
||||
/**
|
||||
* Returns all routers currently defined in Neutron for the current tenant.
|
||||
*
|
||||
* @return the list of all routers configured for the tenant
|
||||
*/
|
||||
@Named("router:list")
|
||||
@GET
|
||||
@ResponseParser(ParseRouterDetails.class)
|
||||
@Transform(ParseRouterDetails.ToPagedIterable.class)
|
||||
@Fallback(Fallbacks.EmptyPagedIterableOnNotFoundOr404.class)
|
||||
PagedIterable<? extends Router> listInDetail();
|
||||
|
||||
/**
|
||||
* @see <a href="http://docs.openstack.org/api/openstack-network/2.0/content/pagination.html">api doc</a>
|
||||
*/
|
||||
@Named("router:list")
|
||||
@GET
|
||||
@ResponseParser(ParseRouterDetails.class)
|
||||
@Fallback(EmptyPaginatedCollectionOnNotFoundOr404.class)
|
||||
PagedIterable<? extends Router> listInDetail(PaginationOptions options);
|
||||
|
||||
/**
|
||||
* Returns the specific router.
|
||||
*
|
||||
* @param id the id of the router to return
|
||||
* @return Router or null if not found
|
||||
*/
|
||||
@Named("router:get")
|
||||
@GET
|
||||
@Path("/{id}")
|
||||
@SelectJson("router")
|
||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
||||
@Nullable
|
||||
Router get(@PathParam("id") String id);
|
||||
|
||||
/**
|
||||
* Create a new router
|
||||
*
|
||||
* @param options optional arguments
|
||||
* @return the newly created router
|
||||
*/
|
||||
@Named("router:create")
|
||||
@POST
|
||||
@SelectJson("router")
|
||||
@MapBinder(CreateRouterOptions.class)
|
||||
Router create(CreateRouterOptions... options);
|
||||
|
||||
/**
|
||||
* Update a router
|
||||
*
|
||||
* @param id the id of the router to update
|
||||
* @param options the attributes to update
|
||||
* @return true if update successful, false if not
|
||||
*/
|
||||
@Named("router:update")
|
||||
@PUT
|
||||
@Path("/{id}")
|
||||
@MapBinder(UpdateRouterOptions.class)
|
||||
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
|
||||
boolean update(@PathParam("id") String id, UpdateRouterOptions... options);
|
||||
|
||||
/**
|
||||
* Deletes the specified router
|
||||
*
|
||||
* @param id the id of the router to delete
|
||||
* @return true if delete successful, false if not
|
||||
*/
|
||||
@Named("router:delete")
|
||||
@DELETE
|
||||
@Path("/{id}")
|
||||
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
|
||||
boolean delete(@PathParam("id") String id);
|
||||
|
||||
/**
|
||||
* Add a interface to a router to connect to the specified subnet
|
||||
*
|
||||
* @param routerId the id of the router to create the interface at
|
||||
* @param subnetId the id of the subnet to connect with the interface
|
||||
* @return the newly-created router interface
|
||||
*/
|
||||
@Named("router:addInterfaceForSubnet")
|
||||
@PUT
|
||||
@Path("/{id}/add_router_interface")
|
||||
@MapBinder(EmptyOptions.class)
|
||||
RouterInterface addInterfaceForSubnet(@PathParam("id") String routerId, @PayloadParam("subnet_id") String subnetId);
|
||||
|
||||
/**
|
||||
* Add a interface to a router to connect to the specified port
|
||||
*
|
||||
* @param routerId the id of the router to create the interface at
|
||||
* @param portId the id of the port to connect with the interface
|
||||
* @return the newly-created router interface
|
||||
*/
|
||||
@Named("router:addInterfaceForPort")
|
||||
@PUT
|
||||
@Path("{id}/add_router_interface")
|
||||
@MapBinder(EmptyOptions.class)
|
||||
RouterInterface addInterfaceForPort(@PathParam("id") String routerId, @PayloadParam("port_id") String portId);
|
||||
|
||||
/**
|
||||
* Remove the interface where the specified subnet is connected to
|
||||
*
|
||||
* @param routerId the id of the router to remove the interface from
|
||||
* @param subnetId the id of the subnet to disconnect from the interface
|
||||
*/
|
||||
@Named("router:removeInterfaceForSubnet")
|
||||
@PUT
|
||||
@Path("/{id}/remove_router_interface")
|
||||
@MapBinder(EmptyOptions.class)
|
||||
boolean removeInterfaceForSubnet(@PathParam("id") String routerId, @PayloadParam("subnet_id") String subnetId);
|
||||
|
||||
/**
|
||||
* Remove the interface where the specified port is connected to
|
||||
*
|
||||
* @param routerId the id of the router to remove the interface from
|
||||
* @param portId the id of the port to disconnect from the interface
|
||||
*/
|
||||
@Named("router:removeInterfaceForPort")
|
||||
@PUT
|
||||
@Path("{id}/remove_router_interface")
|
||||
@MapBinder(EmptyOptions.class)
|
||||
boolean removeInterfaceForPort(@PathParam("id") String routerId, @PayloadParam("port_id") String portId);
|
||||
|
||||
}
|
|
@ -1,179 +0,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.
|
||||
*/
|
||||
|
||||
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.javax.annotation.Nullable;
|
||||
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 access to Network operations for the OpenStack Networking (Neutron) v2 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.
|
||||
*
|
||||
* @see <a href=
|
||||
* "http://docs.openstack.org/api/openstack-network/2.0/content/Networks.html">api doc</a>
|
||||
* @deprecated Please use {@link org.jclouds.openstack.neutron.v2.features.NetworkApi} instead.
|
||||
* To be removed in jclouds 2.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@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();
|
||||
|
||||
/**
|
||||
* @see <a href="http://docs.openstack.org/api/openstack-network/2.0/content/pagination.html">api doc</a>
|
||||
*/
|
||||
@Named("network:list")
|
||||
@GET
|
||||
@ResponseParser(ParseNetworks.class)
|
||||
@Fallback(EmptyPaginatedCollectionOnNotFoundOr404.class)
|
||||
@QueryParams(keys = {"fields", "fields", "fields"}, values = {"id", "tenant_id", "name"})
|
||||
PagedIterable<? 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();
|
||||
|
||||
/**
|
||||
* @see <a href="http://docs.openstack.org/api/openstack-network/2.0/content/pagination.html">api doc</a>
|
||||
*/
|
||||
@Named("network:list")
|
||||
@GET
|
||||
@ResponseParser(ParseNetworkDetails.class)
|
||||
@Fallback(EmptyPaginatedCollectionOnNotFoundOr404.class)
|
||||
PagedIterable<? 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)
|
||||
@Nullable
|
||||
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);
|
||||
}
|
|
@ -1,183 +0,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.
|
||||
*/
|
||||
|
||||
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.javax.annotation.Nullable;
|
||||
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 access to Port operations for the OpenStack Networking (Neutron) v2 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.
|
||||
|
||||
* @see <a href=
|
||||
* "http://docs.openstack.org/api/openstack-network/2.0/content/Ports.html">api doc</a>
|
||||
* @deprecated Please use {@link org.jclouds.openstack.neutron.v2.features.PortApi} instead.
|
||||
* To be removed in jclouds 2.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@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();
|
||||
|
||||
/**
|
||||
* @see <a href="http://docs.openstack.org/api/openstack-network/2.0/content/pagination.html">api doc</a>
|
||||
*/
|
||||
@Named("port:list")
|
||||
@GET
|
||||
@ResponseParser(ParsePorts.class)
|
||||
@Fallback(EmptyPaginatedCollectionOnNotFoundOr404.class)
|
||||
@QueryParams(keys = {"fields", "fields", "fields"}, values = {"id", "tenant_id", "name"})
|
||||
PagedIterable<? 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();
|
||||
|
||||
/**
|
||||
* @see <a href="http://docs.openstack.org/api/openstack-network/2.0/content/pagination.html">api doc</a>
|
||||
*/
|
||||
@Named("port:list")
|
||||
@GET
|
||||
@ResponseParser(ParsePortDetails.class)
|
||||
@Fallback(EmptyPaginatedCollectionOnNotFoundOr404.class)
|
||||
PagedIterable<? 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)
|
||||
@Nullable
|
||||
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);
|
||||
}
|
|
@ -1,182 +0,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.
|
||||
*/
|
||||
|
||||
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.javax.annotation.Nullable;
|
||||
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 access to Subnet operations for the OpenStack Networking (Neutron) v2 API.
|
||||
*
|
||||
|
||||
* @see <a href=
|
||||
* "http://docs.openstack.org/api/openstack-network/2.0/content/Subnets.html">api doc</a>
|
||||
* @deprecated Please use {@link org.jclouds.openstack.neutron.v2.features.SubnetApi} instead.
|
||||
* To be removed in jclouds 2.0.
|
||||
*/
|
||||
@Deprecated
|
||||
@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();
|
||||
|
||||
/**
|
||||
* @see <a href="http://docs.openstack.org/api/openstack-network/2.0/content/pagination.html">api doc</a>
|
||||
*/
|
||||
@Named("subnet:list")
|
||||
@GET
|
||||
@ResponseParser(ParseSubnets.class)
|
||||
@Fallback(EmptyPaginatedCollectionOnNotFoundOr404.class)
|
||||
@QueryParams(keys = {"fields", "fields", "fields"}, values = {"id", "tenant_id", "name"})
|
||||
PagedIterable<? 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();
|
||||
|
||||
/**
|
||||
* @see <a href="http://docs.openstack.org/api/openstack-network/2.0/content/pagination.html">api doc</a>
|
||||
*/
|
||||
@Named("subnet:list")
|
||||
@GET
|
||||
@ResponseParser(ParseSubnetDetails.class)
|
||||
@Fallback(EmptyPaginatedCollectionOnNotFoundOr404.class)
|
||||
PagedIterable<? 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)
|
||||
@Nullable
|
||||
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);
|
||||
}
|
|
@ -1,93 +0,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.
|
||||
*/
|
||||
package org.jclouds.openstack.neutron.v2_0.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
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.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 org.jclouds.openstack.v2_0.domain.PaginatedCollection;
|
||||
import org.jclouds.openstack.v2_0.options.PaginationOptions;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
*/
|
||||
@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> networksLinks) {
|
||||
super(networks, networksLinks);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@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) {
|
||||
PaginationOptions paginationOptions = PaginationOptions.class.cast(input);
|
||||
return IterableWithMarker.class.cast(networkApi.listInDetail(paginationOptions));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "listNetworksInDetail()";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,93 +0,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.
|
||||
*/
|
||||
package org.jclouds.openstack.neutron.v2_0.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
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.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 org.jclouds.openstack.v2_0.domain.PaginatedCollection;
|
||||
import org.jclouds.openstack.v2_0.options.PaginationOptions;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
*/
|
||||
@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> networksLinks) {
|
||||
super(networks, networksLinks);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@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) {
|
||||
PaginationOptions paginationOptions = PaginationOptions.class.cast(input);
|
||||
return IterableWithMarker.class.cast(networkApi.list(paginationOptions));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "listNetworks()";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,94 +0,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.
|
||||
*/
|
||||
package org.jclouds.openstack.neutron.v2_0.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
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.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 org.jclouds.openstack.v2_0.domain.PaginatedCollection;
|
||||
import org.jclouds.openstack.v2_0.options.PaginationOptions;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
*/
|
||||
@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> portsLinks) {
|
||||
super(ports, portsLinks);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@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) {
|
||||
PaginationOptions paginationOptions = PaginationOptions.class.cast(input);
|
||||
return IterableWithMarker.class.cast(portApi.listInDetail(paginationOptions));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "listPortsInDetail()";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,93 +0,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.
|
||||
*/
|
||||
package org.jclouds.openstack.neutron.v2_0.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
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.neutron.v2_0.NeutronApi;
|
||||
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.ParsePorts.Ports;
|
||||
import org.jclouds.openstack.v2_0.domain.Link;
|
||||
import org.jclouds.openstack.v2_0.domain.PaginatedCollection;
|
||||
import org.jclouds.openstack.v2_0.options.PaginationOptions;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
*/
|
||||
@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> portsLinks) {
|
||||
super(ports, portsLinks);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@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) {
|
||||
PaginationOptions paginationOptions = PaginationOptions.class.cast(input);
|
||||
return IterableWithMarker.class.cast(portApi.list(paginationOptions));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "listPorts()";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,93 +0,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.
|
||||
*/
|
||||
|
||||
package org.jclouds.openstack.neutron.v2_0.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.openstack.v2_0.options.PaginationOptions.Builder.marker;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
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.neutron.v2_0.NeutronApi;
|
||||
import org.jclouds.openstack.neutron.v2_0.domain.Router;
|
||||
import org.jclouds.openstack.neutron.v2_0.extensions.RouterApi;
|
||||
import org.jclouds.openstack.neutron.v2_0.functions.ParseRouterDetails.Routers;
|
||||
import org.jclouds.openstack.v2_0.domain.Link;
|
||||
import org.jclouds.openstack.v2_0.domain.PaginatedCollection;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
*/
|
||||
@Beta
|
||||
@Singleton
|
||||
public class ParseRouterDetails extends ParseJson<Routers> {
|
||||
static class Routers extends PaginatedCollection<Router> {
|
||||
|
||||
@ConstructorProperties({ "routers", "routers_links" })
|
||||
protected Routers(Iterable<Router> routers, Iterable<Link> routersLinks) {
|
||||
super(routers, routersLinks);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Inject
|
||||
public ParseRouterDetails(Json json) {
|
||||
super(json, TypeLiteral.get(Routers.class));
|
||||
}
|
||||
|
||||
public static class ToPagedIterable extends Arg0ToPagedIterable.FromCaller<Router, ToPagedIterable> {
|
||||
|
||||
private final NeutronApi api;
|
||||
|
||||
@Inject
|
||||
protected ToPagedIterable(NeutronApi api) {
|
||||
this.api = checkNotNull(api, "api");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Function<Object, IterableWithMarker<Router>> markerToNextForArg0(Optional<Object> arg0) {
|
||||
String zone = arg0.isPresent() ? arg0.get().toString() : null;
|
||||
final RouterApi routerApi = api.getRouterExtensionForZone(zone).get();
|
||||
return new Function<Object, IterableWithMarker<Router>>() {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public IterableWithMarker<Router> apply(Object input) {
|
||||
return IterableWithMarker.class.cast(routerApi.listInDetail(marker(input.toString())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "listRoutersInDetail()";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,93 +0,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.
|
||||
*/
|
||||
|
||||
package org.jclouds.openstack.neutron.v2_0.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.openstack.v2_0.options.PaginationOptions.Builder.marker;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
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.neutron.v2_0.NeutronApi;
|
||||
import org.jclouds.openstack.neutron.v2_0.domain.ReferenceWithName;
|
||||
import org.jclouds.openstack.neutron.v2_0.extensions.RouterApi;
|
||||
import org.jclouds.openstack.neutron.v2_0.functions.ParseRouters.Routers;
|
||||
import org.jclouds.openstack.v2_0.domain.Link;
|
||||
import org.jclouds.openstack.v2_0.domain.PaginatedCollection;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
*/
|
||||
@Beta
|
||||
@Singleton
|
||||
public class ParseRouters extends ParseJson<Routers> {
|
||||
static class Routers extends PaginatedCollection<ReferenceWithName> {
|
||||
|
||||
@ConstructorProperties({ "routers", "routers_links" })
|
||||
protected Routers(Iterable<ReferenceWithName> routers, Iterable<Link> routersLinks) {
|
||||
super(routers, routersLinks);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Inject
|
||||
public ParseRouters(Json json) {
|
||||
super(json, TypeLiteral.get(Routers.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 RouterApi routerApi = api.getRouterExtensionForZone(zone).get();
|
||||
return new Function<Object, IterableWithMarker<ReferenceWithName>>() {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public IterableWithMarker<ReferenceWithName> apply(Object input) {
|
||||
return IterableWithMarker.class.cast(routerApi.list(marker(input.toString())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "listRouters()";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,93 +0,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.
|
||||
*/
|
||||
package org.jclouds.openstack.neutron.v2_0.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
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.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 org.jclouds.openstack.v2_0.domain.PaginatedCollection;
|
||||
import org.jclouds.openstack.v2_0.options.PaginationOptions;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
*/
|
||||
@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> subnetsLinks) {
|
||||
super(subnets, subnetsLinks);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@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) {
|
||||
PaginationOptions paginationOptions = PaginationOptions.class.cast(input);
|
||||
return IterableWithMarker.class.cast(subnetApi.listInDetail(paginationOptions));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "listSubnetsInDetail()";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,93 +0,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.
|
||||
*/
|
||||
package org.jclouds.openstack.neutron.v2_0.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
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.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 org.jclouds.openstack.v2_0.domain.PaginatedCollection;
|
||||
import org.jclouds.openstack.v2_0.options.PaginationOptions;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
*/
|
||||
@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> subnetsLinks) {
|
||||
super(subnets, subnetsLinks);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@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) {
|
||||
PaginationOptions paginationOptions = PaginationOptions.class.cast(input);
|
||||
return IterableWithMarker.class.cast(subnetApi.list(paginationOptions));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "listSubnets()";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,59 +0,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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
}
|
|
@ -1,138 +0,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.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
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 abstract static 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,240 +0,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.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
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 abstract static 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,133 +0,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.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
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 abstract static 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);
|
||||
}
|
||||
}
|
|
@ -1,241 +0,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.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
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 abstract static 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);
|
||||
}
|
||||
}
|
|
@ -1,164 +0,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.
|
||||
*/
|
||||
|
||||
package org.jclouds.openstack.neutron.v2_0.options;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.openstack.neutron.v2_0.domain.ExternalGatewayInfo;
|
||||
import org.jclouds.rest.MapBinder;
|
||||
import org.jclouds.rest.binders.BindToJsonPayload;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Map;
|
||||
|
||||
public class CreateRouterOptions implements MapBinder {
|
||||
|
||||
@Inject
|
||||
private BindToJsonPayload jsonBinder;
|
||||
|
||||
public static Builder<?> builder() {
|
||||
return new ConcreteBuilder();
|
||||
}
|
||||
|
||||
public Builder<?> toBuilder() {
|
||||
return new ConcreteBuilder().fromCreateRouterOptions(this);
|
||||
}
|
||||
|
||||
public abstract static class Builder<T extends Builder<T>> {
|
||||
protected abstract T self();
|
||||
|
||||
protected String name;
|
||||
protected Boolean adminStateUp;
|
||||
protected ExternalGatewayInfo externalGatewayInfo;
|
||||
|
||||
/**
|
||||
* @see CreateRouterOptions#getName()
|
||||
*/
|
||||
public T name(String name) {
|
||||
this.name = name;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CreateRouterOptions#getAdminStateUp()
|
||||
*/
|
||||
public T adminStateUp(Boolean adminStateUp) {
|
||||
this.adminStateUp = adminStateUp;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CreateRouterOptions#getExternalGatewayInfo()
|
||||
*/
|
||||
public T externalGatewayInfo(ExternalGatewayInfo externalGatewayInfo) {
|
||||
this.externalGatewayInfo = externalGatewayInfo;
|
||||
return self();
|
||||
}
|
||||
|
||||
public CreateRouterOptions build() {
|
||||
return new CreateRouterOptions(name, adminStateUp, externalGatewayInfo);
|
||||
}
|
||||
|
||||
public T fromCreateRouterOptions(CreateRouterOptions options) {
|
||||
return this.name(options.getName())
|
||||
.adminStateUp(options.getAdminStateUp())
|
||||
.externalGatewayInfo(options.getExternalGatewayInfo());
|
||||
}
|
||||
}
|
||||
|
||||
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||
@Override
|
||||
protected ConcreteBuilder self() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
protected static class CreateRouterRequest {
|
||||
protected String name;
|
||||
protected Boolean admin_state_up;
|
||||
protected ExternalGatewayInfo external_gateway_info;
|
||||
|
||||
protected CreateRouterRequest() {
|
||||
}
|
||||
|
||||
protected static final class ExternalGatewayInfo {
|
||||
protected String network_id;
|
||||
|
||||
protected ExternalGatewayInfo(String network_id) {
|
||||
this.network_id = network_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected String name;
|
||||
protected Boolean adminStateUp;
|
||||
protected ExternalGatewayInfo externalGatewayInfo;
|
||||
|
||||
protected CreateRouterOptions() {
|
||||
this.name = null;
|
||||
this.adminStateUp = null;
|
||||
this.externalGatewayInfo = null;
|
||||
}
|
||||
|
||||
public CreateRouterOptions(String name, Boolean adminStateUp, ExternalGatewayInfo externalGatewayInfo) {
|
||||
this.name = name;
|
||||
this.adminStateUp = adminStateUp;
|
||||
this.externalGatewayInfo = externalGatewayInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name for the router
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the administrative state of the router
|
||||
*/
|
||||
public Boolean getAdminStateUp() {
|
||||
return adminStateUp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the external gateway info for the router
|
||||
*/
|
||||
public ExternalGatewayInfo getExternalGatewayInfo() {
|
||||
return externalGatewayInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
|
||||
CreateRouterRequest createRouterRequest = new CreateRouterRequest();
|
||||
|
||||
if (this.name != null)
|
||||
createRouterRequest.name = this.name;
|
||||
if (this.adminStateUp != null)
|
||||
createRouterRequest.admin_state_up = this.adminStateUp;
|
||||
if (this.externalGatewayInfo != null)
|
||||
createRouterRequest.external_gateway_info = new CreateRouterRequest.ExternalGatewayInfo(this.externalGatewayInfo.getNetworkId());
|
||||
|
||||
return bindToRequest(request, ImmutableMap.of("router", createRouterRequest));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
||||
return jsonBinder.bindToRequest(request, input);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,139 +0,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.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
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 abstract static 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,256 +0,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.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
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 abstract static 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,45 +0,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.
|
||||
*/
|
||||
|
||||
package org.jclouds.openstack.neutron.v2_0.options;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.MapBinder;
|
||||
import org.jclouds.rest.binders.BindToJsonPayload;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class is used for methods who don't need a wrapper around their JSON body
|
||||
*/
|
||||
public class EmptyOptions implements MapBinder {
|
||||
|
||||
@Inject
|
||||
private BindToJsonPayload jsonBinder;
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
|
||||
return bindToRequest(request, (Object) postParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
||||
return jsonBinder.bindToRequest(request, input);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,128 +0,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.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
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 abstract static 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,215 +0,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.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
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 abstract static 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,164 +0,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.
|
||||
*/
|
||||
|
||||
package org.jclouds.openstack.neutron.v2_0.options;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.openstack.neutron.v2_0.domain.ExternalGatewayInfo;
|
||||
import org.jclouds.rest.MapBinder;
|
||||
import org.jclouds.rest.binders.BindToJsonPayload;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Map;
|
||||
|
||||
public class UpdateRouterOptions implements MapBinder {
|
||||
|
||||
@Inject
|
||||
private BindToJsonPayload jsonBinder;
|
||||
|
||||
public static Builder<?> builder() {
|
||||
return new ConcreteBuilder();
|
||||
}
|
||||
|
||||
public Builder<?> toBuilder() {
|
||||
return new ConcreteBuilder().fromUpdateRouterOptions(this);
|
||||
}
|
||||
|
||||
public abstract static class Builder<T extends Builder<T>> {
|
||||
protected abstract T self();
|
||||
|
||||
protected String name;
|
||||
protected Boolean adminStateUp;
|
||||
protected ExternalGatewayInfo externalGatewayInfo;
|
||||
|
||||
/**
|
||||
* @see UpdateRouterOptions#getName()
|
||||
*/
|
||||
public T name(String name) {
|
||||
this.name = name;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see UpdateRouterOptions#getAdminStateUp()
|
||||
*/
|
||||
public T adminStateUp(Boolean adminStateUp) {
|
||||
this.adminStateUp = adminStateUp;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see UpdateRouterOptions#getExternalGatewayInfo()
|
||||
*/
|
||||
public T externalGatewayInfo(ExternalGatewayInfo externalGatewayInfo) {
|
||||
this.externalGatewayInfo = externalGatewayInfo;
|
||||
return self();
|
||||
}
|
||||
|
||||
public UpdateRouterOptions build() {
|
||||
return new UpdateRouterOptions(name, adminStateUp, externalGatewayInfo);
|
||||
}
|
||||
|
||||
public T fromUpdateRouterOptions(UpdateRouterOptions options) {
|
||||
return this.name(options.getName())
|
||||
.adminStateUp(options.getAdminStateUp())
|
||||
.externalGatewayInfo(options.getExternalGatewayInfo());
|
||||
}
|
||||
}
|
||||
|
||||
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||
@Override
|
||||
protected ConcreteBuilder self() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
protected static class UpdateRouterRequest {
|
||||
protected String name;
|
||||
protected Boolean admin_state_up;
|
||||
protected ExternalGatewayInfo external_gateway_info;
|
||||
|
||||
protected UpdateRouterRequest() {
|
||||
}
|
||||
|
||||
protected static final class ExternalGatewayInfo {
|
||||
protected String network_id;
|
||||
|
||||
protected ExternalGatewayInfo(String network_id) {
|
||||
this.network_id = network_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected String name;
|
||||
protected Boolean adminStateUp;
|
||||
protected ExternalGatewayInfo externalGatewayInfo;
|
||||
|
||||
protected UpdateRouterOptions() {
|
||||
this.name = null;
|
||||
this.adminStateUp = null;
|
||||
this.externalGatewayInfo = null;
|
||||
}
|
||||
|
||||
public UpdateRouterOptions(String name, Boolean adminStateUp, ExternalGatewayInfo externalGatewayInfo) {
|
||||
this.name = name;
|
||||
this.adminStateUp = adminStateUp;
|
||||
this.externalGatewayInfo = externalGatewayInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the new name for the router
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the new administrative state for the router
|
||||
*/
|
||||
public Boolean getAdminStateUp() {
|
||||
return adminStateUp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the new information on external gateway for the router
|
||||
*/
|
||||
public ExternalGatewayInfo getExternalGatewayInfo() {
|
||||
return externalGatewayInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
|
||||
UpdateRouterRequest updateRouterRequest = new UpdateRouterRequest();
|
||||
|
||||
if (this.name != null)
|
||||
updateRouterRequest.name = this.name;
|
||||
if (this.adminStateUp != null)
|
||||
updateRouterRequest.admin_state_up = this.adminStateUp;
|
||||
if (this.externalGatewayInfo != null)
|
||||
updateRouterRequest.external_gateway_info = new UpdateRouterRequest.ExternalGatewayInfo(this.externalGatewayInfo.getNetworkId());
|
||||
|
||||
return bindToRequest(request, ImmutableMap.of("router", updateRouterRequest));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
||||
return jsonBinder.bindToRequest(request, input);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,215 +0,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.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
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 abstract static 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,31 +0,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.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
@Test(groups = "unit", testName = "NeutronApiMetadataTest")
|
||||
public class NeutronApiMetadataTest extends BaseApiMetadataTest {
|
||||
public NeutronApiMetadataTest() {
|
||||
super(new NeutronApiMetadata(), ImmutableSet.<TypeToken<? extends View>>of());
|
||||
}
|
||||
}
|
|
@ -1,295 +0,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.
|
||||
*/
|
||||
|
||||
package org.jclouds.openstack.neutron.v2_0.extensions;
|
||||
|
||||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.openstack.neutron.v2_0.domain.ExternalGatewayInfo;
|
||||
import org.jclouds.openstack.neutron.v2_0.domain.ReferenceWithName;
|
||||
import org.jclouds.openstack.neutron.v2_0.domain.Router;
|
||||
import org.jclouds.openstack.neutron.v2_0.domain.RouterInterface;
|
||||
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.CreateRouterOptions;
|
||||
import org.jclouds.openstack.neutron.v2_0.options.UpdateRouterOptions;
|
||||
import org.jclouds.openstack.neutron.v2_0.parse.ParseRouterTest;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Tests parsing and Guice wiring of RouterApi
|
||||
*
|
||||
*/
|
||||
@Test(groups = "unit", testName = "RouterApiExpectTest")
|
||||
public class RouterApiExpectTest extends BaseNeutronApiExpectTest {
|
||||
|
||||
private static final String ZONE = "region-a.geo-1";
|
||||
|
||||
public void testListReferencesReturns2xx() {
|
||||
RouterApi api = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint + "/routers").addQueryParam("fields", "id", "tenant_id", "name").build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/list_routers.json", APPLICATION_JSON)).build())
|
||||
.getRouterExtensionForZone(ZONE).get();
|
||||
|
||||
Set<? extends ReferenceWithName> references = api.list().concat().toSet();
|
||||
assertEquals(references, listOfReferencesWithNames());
|
||||
}
|
||||
|
||||
public void testListReferencesReturns4xx() {
|
||||
RouterApi api = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint + "/routers").addQueryParam("fields", "id", "tenant_id", "name").build(),
|
||||
HttpResponse.builder().statusCode(404).build())
|
||||
.getRouterExtensionForZone(ZONE).get();
|
||||
|
||||
assertTrue(api.list().concat().isEmpty());
|
||||
}
|
||||
|
||||
public void testListReturns2xx() {
|
||||
RouterApi api = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint + "/routers").build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/list_routers.json", APPLICATION_JSON)).build())
|
||||
.getRouterExtensionForZone(ZONE).get();
|
||||
|
||||
Set<? extends Router> routers = api.listInDetail().concat().toSet();
|
||||
assertEquals(routers, listOfRouters());
|
||||
}
|
||||
|
||||
public void testListReturns4xx() {
|
||||
RouterApi api = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint + "/routers").build(),
|
||||
HttpResponse.builder().statusCode(404).build())
|
||||
.getRouterExtensionForZone(ZONE).get();
|
||||
|
||||
assertTrue(api.listInDetail().concat().isEmpty());
|
||||
}
|
||||
|
||||
public void testGetReturns2xx() {
|
||||
RouterApi api = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint + "/routers/16dba3bc-f3fa-4775-afdc-237e12c72f6a").build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResourceWithContentType("/router.json", APPLICATION_JSON)).build())
|
||||
.getRouterExtensionForZone(ZONE).get();
|
||||
|
||||
Router router = api.get("16dba3bc-f3fa-4775-afdc-237e12c72f6a");
|
||||
assertEquals(router, new ParseRouterTest().expected());
|
||||
}
|
||||
|
||||
public void testGetReturns4xx() {
|
||||
RouterApi api = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint + "/routers/16dba3bc-f3fa-4775-afdc-237e12c72f6a").build(),
|
||||
HttpResponse.builder().statusCode(404).build())
|
||||
.getRouterExtensionForZone(ZONE).get();
|
||||
|
||||
assertNull(api.get("16dba3bc-f3fa-4775-afdc-237e12c72f6a"));
|
||||
}
|
||||
|
||||
public void testCreateReturns2xx() {
|
||||
RouterApi api = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint + "/routers").method("POST")
|
||||
.payload(payloadFromStringWithContentType("{\"router\":{\"name\":\"test\",\"external_gateway_info\":{\"network_id\":\"1234567890\"}}}", MediaType.APPLICATION_JSON)).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromStringWithContentType("{\"router\":{\"id\":\"12345\",\"tenant_id\":\"6789\",\"external_gateway_info\":{\"network_id\":\"1234567890\"}}}", APPLICATION_JSON)).build())
|
||||
.getRouterExtensionForZone(ZONE).get();
|
||||
|
||||
Router router = api.create(CreateRouterOptions.builder().name("test").externalGatewayInfo(ExternalGatewayInfo.builder().networkId("1234567890").build()).build());
|
||||
assertEquals(router, Router.builder().id("12345").tenantId("6789").externalGatewayInfo(ExternalGatewayInfo.builder().networkId("1234567890").build()).build());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = AuthorizationException.class)
|
||||
public void testCreateReturns4xx() {
|
||||
RouterApi api = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint + "/routers").method("POST")
|
||||
.payload(payloadFromStringWithContentType("{\"router\":{\"name\":\"another-test\",\"external_gateway_info\":{\"network_id\":\"1234567890\"}}}", MediaType.APPLICATION_JSON)).build(),
|
||||
HttpResponse.builder().statusCode(401).build())
|
||||
.getRouterExtensionForZone(ZONE).get();
|
||||
|
||||
api.create(CreateRouterOptions.builder().name("another-test").externalGatewayInfo(ExternalGatewayInfo.builder().networkId("1234567890").build()).build());
|
||||
}
|
||||
|
||||
public void testUpdateReturns2xx() {
|
||||
RouterApi api = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint + "/routers/12345").method("PUT")
|
||||
.payload(payloadFromStringWithContentType("{\"router\":{\"name\":\"another-test\",\"admin_state_up\":true}}", MediaType.APPLICATION_JSON)).build(),
|
||||
HttpResponse.builder().statusCode(200).build())
|
||||
.getRouterExtensionForZone(ZONE).get();
|
||||
|
||||
assertTrue(api.update("12345", UpdateRouterOptions.builder().name("another-test").adminStateUp(true).build()));
|
||||
}
|
||||
|
||||
public void testUpdateReturns4xx() {
|
||||
RouterApi api = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint + "/routers/12345").method("PUT")
|
||||
.payload(payloadFromStringWithContentType("{\"router\":{\"name\":\"another-test\",\"admin_state_up\":true}}", MediaType.APPLICATION_JSON)).build(),
|
||||
HttpResponse.builder().statusCode(404).build())
|
||||
.getRouterExtensionForZone(ZONE).get();
|
||||
|
||||
assertFalse(api.update("12345", UpdateRouterOptions.builder().name("another-test").adminStateUp(true).build()));
|
||||
}
|
||||
|
||||
public void testDeleteReturns2xx() {
|
||||
RouterApi api = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint + "/routers/12345").method("DELETE").build(),
|
||||
HttpResponse.builder().statusCode(200).build())
|
||||
.getRouterExtensionForZone(ZONE).get();
|
||||
|
||||
assertTrue(api.delete("12345"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = AuthorizationException.class)
|
||||
public void testDeleteReturns4xx() {
|
||||
RouterApi api = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint + "/routers/12345").method("DELETE").build(),
|
||||
HttpResponse.builder().statusCode(403).build())
|
||||
.getRouterExtensionForZone(ZONE).get();
|
||||
|
||||
api.delete("12345");
|
||||
}
|
||||
|
||||
public void testAddInterfaceForSubnetReturns2xx() {
|
||||
RouterApi api = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint + "/routers/12345/add_router_interface").method("PUT")
|
||||
.payload(payloadFromStringWithContentType("{\"subnet_id\":\"1234567890\"}", MediaType.APPLICATION_JSON)).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromStringWithContentType("{\"subnet_id\":\"1234567890\",\"port_id\":\"987654321\"}", MediaType.APPLICATION_JSON)).build())
|
||||
.getRouterExtensionForZone(ZONE).get();
|
||||
|
||||
RouterInterface routerInterface = api.addInterfaceForSubnet("12345", "1234567890");
|
||||
assertEquals(routerInterface, RouterInterface.builder().subnetId("1234567890").portId("987654321").build());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = AuthorizationException.class)
|
||||
public void testAddInterfaceForSubnetReturns4xx() {
|
||||
RouterApi api = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint + "/routers/12345/add_router_interface").method("PUT")
|
||||
.payload(payloadFromStringWithContentType("{\"subnet_id\":\"1234567890\"}", MediaType.APPLICATION_JSON)).build(),
|
||||
HttpResponse.builder().statusCode(403).build())
|
||||
.getRouterExtensionForZone(ZONE).get();
|
||||
|
||||
api.addInterfaceForSubnet("12345", "1234567890");
|
||||
}
|
||||
|
||||
public void testAddInterfaceForPortReturns2xx() {
|
||||
RouterApi api = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint + "/routers/12345/add_router_interface").method("PUT")
|
||||
.payload(payloadFromStringWithContentType("{\"port_id\":\"987654321\"}", MediaType.APPLICATION_JSON)).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromStringWithContentType("{\"subnet_id\":\"1234567890\",\"port_id\":\"987654321\"}", MediaType.APPLICATION_JSON)).build())
|
||||
.getRouterExtensionForZone(ZONE).get();
|
||||
|
||||
RouterInterface routerInterface = api.addInterfaceForPort("12345", "987654321");
|
||||
assertEquals(routerInterface, RouterInterface.builder().subnetId("1234567890").portId("987654321").build());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = AuthorizationException.class)
|
||||
public void testAddInterfaceForPortReturns4xx() {
|
||||
RouterApi api = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint + "/routers/12345/add_router_interface").method("PUT")
|
||||
.payload(payloadFromStringWithContentType("{\"port_id\":\"1234567890\"}", MediaType.APPLICATION_JSON)).build(),
|
||||
HttpResponse.builder().statusCode(403).build())
|
||||
.getRouterExtensionForZone(ZONE).get();
|
||||
|
||||
api.addInterfaceForPort("12345", "1234567890");
|
||||
}
|
||||
|
||||
public void testRemoveInterfaceForSubnetReturns2xx() {
|
||||
RouterApi api = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint + "/routers/12345/remove_router_interface").method("PUT")
|
||||
.payload(payloadFromStringWithContentType("{\"subnet_id\":\"1234567890\"}", MediaType.APPLICATION_JSON)).build(),
|
||||
HttpResponse.builder().statusCode(200).build())
|
||||
.getRouterExtensionForZone(ZONE).get();
|
||||
|
||||
api.removeInterfaceForSubnet("12345", "1234567890");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = AuthorizationException.class)
|
||||
public void testRemoveInterfaceForSubnetReturns4xx() {
|
||||
RouterApi api = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint + "/routers/12345/remove_router_interface").method("PUT")
|
||||
.payload(payloadFromStringWithContentType("{\"subnet_id\":\"1234567890\"}", MediaType.APPLICATION_JSON)).build(),
|
||||
HttpResponse.builder().statusCode(403).build())
|
||||
.getRouterExtensionForZone(ZONE).get();
|
||||
|
||||
api.removeInterfaceForSubnet("12345", "1234567890");
|
||||
}
|
||||
|
||||
public void testRemoveInterfaceForPortReturns2xx() {
|
||||
RouterApi api = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint + "/routers/12345/remove_router_interface").method("PUT")
|
||||
.payload(payloadFromStringWithContentType("{\"port_id\":\"1234567890\"}", MediaType.APPLICATION_JSON)).build(),
|
||||
HttpResponse.builder().statusCode(200).build())
|
||||
.getRouterExtensionForZone(ZONE).get();
|
||||
|
||||
api.removeInterfaceForPort("12345", "1234567890");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = AuthorizationException.class)
|
||||
public void testRemoveInterfaceForPortReturns4xx() {
|
||||
RouterApi api = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
|
||||
authenticatedGET().endpoint(endpoint + "/routers/12345/remove_router_interface").method("PUT")
|
||||
.payload(payloadFromStringWithContentType("{\"port_id\":\"1234567890\"}", MediaType.APPLICATION_JSON)).build(),
|
||||
HttpResponse.builder().statusCode(403).build())
|
||||
.getRouterExtensionForZone(ZONE).get();
|
||||
|
||||
api.removeInterfaceForPort("12345", "1234567890");
|
||||
}
|
||||
|
||||
protected Set<Router> listOfRouters() {
|
||||
return ImmutableSet.of(
|
||||
Router.builder().state(State.ACTIVE).name("jclouds-test").tenantId("1234567890").id("16dba3bc-f3fa-4775-afdc-237e12c72f6a").build(),
|
||||
Router.builder().state(State.ACTIVE).name("wibble").tenantId("1234567890").id("1a104cf5-cb18-4d35-9407-2fd2646d9d0b").build(),
|
||||
Router.builder().state(State.ACTIVE).name("jclouds-test").tenantId("1234567890").id("31083ae2-420d-48b2-ac98-9f7a4fd8dbdc").build(),
|
||||
Router.builder().state(State.ACTIVE).name("jclouds-test").tenantId("1234567890").id("49c6d6fa-ff2a-459d-b975-75a8d31c9a89").build(),
|
||||
Router.builder().state(State.ACTIVE).name("wibble").tenantId("1234567890").id("5cb3d6f4-62cb-41c9-b964-ba7d9df79e4e").build(),
|
||||
Router.builder().state(State.ACTIVE).name("jclouds-test").tenantId("1234567890").id("5d51d012-3491-4db7-b1b5-6f254015015d").build(),
|
||||
Router.builder().state(State.ACTIVE).name("wibble").tenantId("1234567890").id("5f9cf7dc-22ca-4097-8e49-1cc8b23faf17").build(),
|
||||
Router.builder().state(State.ACTIVE).name("jclouds-test").tenantId("1234567890").id("6319ecad-6bff-48b2-9b53-02ede8cb7588").build(),
|
||||
Router.builder().state(State.ACTIVE).name("jclouds-test").tenantId("1234567890").id("6ba4c788-661f-49ab-9bf8-5f10cbbb2f57").build(),
|
||||
Router.builder().state(State.ACTIVE).name("jclouds-test").tenantId("1234567890").id("74ed170b-5069-4353-ab38-9719766dc57e").build(),
|
||||
Router.builder().state(State.ACTIVE).name("wibble").tenantId("1234567890").id("b71fcac1-e864-4031-8c5b-edbecd9ece36").build(),
|
||||
Router.builder().state(State.ACTIVE).name("jclouds-test").tenantId("1234567890").id("c7681895-d84d-4650-9ca0-82c72036b855").build()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,190 +0,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.
|
||||
*/
|
||||
|
||||
package org.jclouds.openstack.neutron.v2_0.extensions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.openstack.neutron.v2_0.domain.ExternalGatewayInfo;
|
||||
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.Port;
|
||||
import org.jclouds.openstack.neutron.v2_0.domain.ReferenceWithName;
|
||||
import org.jclouds.openstack.neutron.v2_0.domain.Router;
|
||||
import org.jclouds.openstack.neutron.v2_0.domain.RouterInterface;
|
||||
import org.jclouds.openstack.neutron.v2_0.domain.Subnet;
|
||||
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.neutron.v2_0.internal.BaseNeutronApiLiveTest;
|
||||
import org.jclouds.openstack.neutron.v2_0.options.CreateNetworkOptions;
|
||||
import org.jclouds.openstack.neutron.v2_0.options.CreateRouterOptions;
|
||||
import org.jclouds.openstack.neutron.v2_0.options.UpdateRouterOptions;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Tests parsing and Guice wiring of RouterApi
|
||||
*
|
||||
*/
|
||||
@Test(groups = "live", testName = "RouterApiLiveTest")
|
||||
public class RouterApiLiveTest extends BaseNeutronApiLiveTest {
|
||||
|
||||
public void testGetAndListRouters() {
|
||||
for (String zone : api.getConfiguredZones()) {
|
||||
Set<? extends ReferenceWithName> references = api.getRouterExtensionForZone(zone).get().list().concat().toSet();
|
||||
Set<? extends Router> routers = api.getRouterExtensionForZone(zone).get().listInDetail().concat().toSet();
|
||||
|
||||
assertNotNull(references);
|
||||
assertNotNull(routers);
|
||||
assertEquals(references.size(), routers.size());
|
||||
|
||||
for (Router router : routers) {
|
||||
assertNotNull(router.getName());
|
||||
assertTrue(references.contains(ReferenceWithName.builder().id(router.getId()).tenantId(router.getTenantId()).name(router.getName()).build()));
|
||||
|
||||
Router retrievedRouter = api.getRouterExtensionForZone(zone).get().get(router.getId());
|
||||
assertEquals(router, retrievedRouter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testCreateUpdateAndDeleteRouter() {
|
||||
for (String zone : api.getConfiguredZones()) {
|
||||
RouterApi routerApi = api.getRouterExtensionForZone(zone).get();
|
||||
NetworkApi networkApi = api.getNetworkApiForZone(zone);
|
||||
SubnetApi subnetApi = api.getSubnetApiForZone(zone);
|
||||
|
||||
Network network = networkApi.create(CreateNetworkOptions.builder().name("jclouds-network-test").external(true).networkType(NetworkType.LOCAL).build());
|
||||
assertNotNull(network);
|
||||
|
||||
Subnet subnet = subnetApi.create(network.getId(), 4, "192.168.0.0/16");
|
||||
assertNotNull(subnet);
|
||||
|
||||
Router ref = routerApi.create(CreateRouterOptions.builder().name("jclouds-router-test")
|
||||
.externalGatewayInfo(ExternalGatewayInfo.builder().networkId(network.getId()).build()).build());
|
||||
assertNotNull(ref);
|
||||
|
||||
Router router = routerApi.get(ref.getId());
|
||||
|
||||
assertEquals(router.getId(), ref.getId());
|
||||
assertEquals(router.getName(), "jclouds-router-test");
|
||||
assertEquals(router.getExternalGatewayInfo().getNetworkId(), network.getId());
|
||||
assertTrue(routerApi.update(router.getId(), UpdateRouterOptions.builder().name("jclouds-router-test-rename").build()));
|
||||
|
||||
router = routerApi.get(ref.getId());
|
||||
|
||||
assertEquals(router.getId(), ref.getId());
|
||||
assertEquals(router.getName(), "jclouds-router-test-rename");
|
||||
|
||||
ReferenceWithName ref2 = routerApi.create(CreateRouterOptions.builder().name("jclouds-router-test2")
|
||||
.externalGatewayInfo(ExternalGatewayInfo.builder().networkId(network.getId()).build()).build());
|
||||
assertNotNull(ref2);
|
||||
|
||||
assertTrue(routerApi.delete(ref.getId()));
|
||||
assertTrue(routerApi.delete(ref2.getId()));
|
||||
assertTrue(subnetApi.delete(subnet.getId()));
|
||||
assertTrue(networkApi.delete(network.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
public void testCreateAndDeleteRouterInterfaceForSubnet() {
|
||||
for (String zone : api.getConfiguredZones()) {
|
||||
RouterApi routerApi = api.getRouterExtensionForZone(zone).get();
|
||||
NetworkApi networkApi = api.getNetworkApiForZone(zone);
|
||||
SubnetApi subnetApi = api.getSubnetApiForZone(zone);
|
||||
|
||||
Network network = networkApi.create(CreateNetworkOptions.builder().name("jclouds-network-test").external(true).networkType(NetworkType.LOCAL).build());
|
||||
assertNotNull(network);
|
||||
|
||||
Subnet subnet = subnetApi.create(network.getId(), 4, "192.168.0.0/16");
|
||||
assertNotNull(subnet);
|
||||
|
||||
Network network2 = networkApi.create(CreateNetworkOptions.builder().name("jclouds-network-test2").external(true).networkType(NetworkType.LOCAL).build());
|
||||
assertNotNull(network2);
|
||||
|
||||
Subnet subnet2 = subnetApi.create(network2.getId(), 4, "192.169.0.0/16");
|
||||
assertNotNull(subnet2);
|
||||
|
||||
Router router = routerApi.create(CreateRouterOptions.builder().name("jclouds-router-test").build());
|
||||
assertNotNull(router);
|
||||
|
||||
RouterInterface routerInterface = routerApi.addInterfaceForSubnet(router.getId(), subnet.getId());
|
||||
assertNotNull(routerInterface);
|
||||
|
||||
RouterInterface routerInterface2 = routerApi.addInterfaceForSubnet(router.getId(), subnet2.getId());
|
||||
assertNotNull(routerInterface2);
|
||||
|
||||
assertTrue(routerApi.removeInterfaceForSubnet(router.getId(), subnet.getId()));
|
||||
assertTrue(routerApi.removeInterfaceForSubnet(router.getId(), subnet2.getId()));
|
||||
assertTrue(routerApi.delete(router.getId()));
|
||||
assertTrue(subnetApi.delete(subnet.getId()));
|
||||
assertTrue(networkApi.delete(network.getId()));
|
||||
assertTrue(subnetApi.delete(subnet2.getId()));
|
||||
assertTrue(networkApi.delete(network2.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
public void testCreateAndDeleteRouterInterfaceForPort() {
|
||||
for (String zone : api.getConfiguredZones()) {
|
||||
RouterApi routerApi = api.getRouterExtensionForZone(zone).get();
|
||||
NetworkApi networkApi = api.getNetworkApiForZone(zone);
|
||||
SubnetApi subnetApi = api.getSubnetApiForZone(zone);
|
||||
PortApi portApi = api.getPortApiForZone(zone);
|
||||
|
||||
Network network = networkApi.create(CreateNetworkOptions.builder().name("jclouds-network-test").external(true).networkType(NetworkType.LOCAL).build());
|
||||
assertNotNull(network);
|
||||
|
||||
Subnet subnet = subnetApi.create(network.getId(), 4, "192.168.0.0/16");
|
||||
assertNotNull(subnet);
|
||||
|
||||
Network network2 = networkApi.create(CreateNetworkOptions.builder().name("jclouds-network-test2").external(true).networkType(NetworkType.LOCAL).build());
|
||||
assertNotNull(network2);
|
||||
|
||||
Subnet subnet2 = subnetApi.create(network2.getId(), 4, "192.169.0.0/16");
|
||||
assertNotNull(subnet2);
|
||||
|
||||
Port port = portApi.create(network.getId());
|
||||
assertNotNull(port);
|
||||
|
||||
Port port2 = portApi.create(network2.getId());
|
||||
assertNotNull(port2);
|
||||
|
||||
Router router = routerApi.create(CreateRouterOptions.builder().name("jclouds-router-test").build());
|
||||
assertNotNull(router);
|
||||
|
||||
RouterInterface routerInterface = routerApi.addInterfaceForPort(router.getId(), port.getId());
|
||||
assertNotNull(routerInterface);
|
||||
|
||||
RouterInterface routerInterface2 = routerApi.addInterfaceForPort(router.getId(), port2.getId());
|
||||
assertNotNull(routerInterface2);
|
||||
|
||||
assertTrue(routerApi.removeInterfaceForPort(router.getId(), port.getId()));
|
||||
assertTrue(routerApi.removeInterfaceForPort(router.getId(), port2.getId()));
|
||||
assertTrue(routerApi.delete(router.getId()));
|
||||
assertTrue(subnetApi.delete(subnet.getId()));
|
||||
assertTrue(networkApi.delete(network.getId()));
|
||||
assertTrue(subnetApi.delete(subnet2.getId()));
|
||||
assertTrue(networkApi.delete(network2.getId()));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,245 +0,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.
|
||||
*/
|
||||
package org.jclouds.openstack.neutron.v2_0.features;
|
||||
|
||||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
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 com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Tests parsing and Guice wiring of NetworkApi
|
||||
*
|
||||
*/
|
||||
@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()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,121 +0,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.
|
||||
*/
|
||||
package org.jclouds.openstack.neutron.v2_0.features;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
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 org.jclouds.openstack.neutron.v2_0.util.PredicateUtil;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
* Tests parsing and Guice wiring of NetworkApi
|
||||
*
|
||||
*/
|
||||
@Test(groups = "live", testName = "NetworkApiLiveTest", singleThreaded = true)
|
||||
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) {
|
||||
Predicate<Network> idEqualsPredicate = PredicateUtil.createIdEqualsPredicate(net.getId());
|
||||
assertEquals(1, Sets.filter(existingNets, idEqualsPredicate).size());
|
||||
assertTrue(networkApi.delete(net.getId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,245 +0,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.
|
||||
*/
|
||||
package org.jclouds.openstack.neutron.v2_0.features;
|
||||
|
||||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
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 com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Tests parsing and Guice wiring of PortApi
|
||||
*
|
||||
*/
|
||||
@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()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,157 +0,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.
|
||||
*/
|
||||
package org.jclouds.openstack.neutron.v2_0.features;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.openstack.neutron.v2_0.domain.BulkPort;
|
||||
import org.jclouds.openstack.neutron.v2_0.domain.IP;
|
||||
import org.jclouds.openstack.neutron.v2_0.domain.NetworkType;
|
||||
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.internal.BaseNeutronApiLiveTest;
|
||||
import org.jclouds.openstack.neutron.v2_0.options.CreateNetworkOptions;
|
||||
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.CreateSubnetOptions;
|
||||
import org.jclouds.openstack.neutron.v2_0.options.UpdatePortOptions;
|
||||
import org.jclouds.openstack.neutron.v2_0.util.PredicateUtil;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
* Tests PortApi in combination with the Network & SubnetApi
|
||||
*
|
||||
*/
|
||||
@Test(groups = "live", testName = "PortApiLiveTest", singleThreaded = true)
|
||||
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) {
|
||||
Predicate<Port> idEqualsPredicate = PredicateUtil.createIdEqualsPredicate(port.getId());
|
||||
assertEquals(1, Sets.filter(existingPorts, idEqualsPredicate).size());
|
||||
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()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,253 +0,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.
|
||||
*/
|
||||
package org.jclouds.openstack.neutron.v2_0.features;
|
||||
|
||||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
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 com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Tests parsing and Guice wiring of SubnetApi
|
||||
*/
|
||||
@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()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,139 +0,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.
|
||||
*/
|
||||
package org.jclouds.openstack.neutron.v2_0.features;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.openstack.neutron.v2_0.domain.AllocationPool;
|
||||
import org.jclouds.openstack.neutron.v2_0.domain.BulkSubnet;
|
||||
import org.jclouds.openstack.neutron.v2_0.domain.HostRoute;
|
||||
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.domain.Subnet;
|
||||
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 org.jclouds.openstack.neutron.v2_0.util.PredicateUtil;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
* Tests subnet api in combination with the network api
|
||||
*
|
||||
*/
|
||||
@Test(groups = "live", testName = "SubnetApiLiveTest", singleThreaded = true)
|
||||
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) {
|
||||
Predicate<Subnet> idEqualsPredicate = PredicateUtil.createIdEqualsPredicate(net.getId());
|
||||
assertEquals(1, Sets.filter(existingSubnets, idEqualsPredicate).size());
|
||||
assertTrue(subnetApi.delete(net.getId()));
|
||||
}
|
||||
assertTrue(networkApi.delete(networkId));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,66 +0,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.
|
||||
*/
|
||||
|
||||
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
|
||||
*/
|
||||
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()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,44 +0,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.
|
||||
*/
|
||||
|
||||
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}
|
||||
*/
|
||||
@Test(groups = "live")
|
||||
public class BaseNeutronApiLiveTest extends BaseApiLiveTest<NeutronApi> {
|
||||
|
||||
public BaseNeutronApiLiveTest() {
|
||||
provider = "openstack-neutron-legacy";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Properties setupProperties() {
|
||||
Properties props = super.setupProperties();
|
||||
setIfTestSystemPropertyPresent(props, KeystoneProperties.CREDENTIAL_TYPE);
|
||||
return props;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,64 +0,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.
|
||||
*/
|
||||
|
||||
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
|
||||
*/
|
||||
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-legacy";
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -1,50 +0,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.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
|
@ -1,49 +0,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.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
|
@ -1,51 +0,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.
|
||||
*/
|
||||
|
||||
package org.jclouds.openstack.neutron.v2_0.parse;
|
||||
|
||||
import org.jclouds.json.BaseItemParserTest;
|
||||
import org.jclouds.openstack.neutron.v2_0.domain.ExternalGatewayInfo;
|
||||
import org.jclouds.openstack.neutron.v2_0.domain.Router;
|
||||
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;
|
||||
|
||||
@Test(groups = "unit", testName = "ParseRouterTest")
|
||||
public class ParseRouterTest extends BaseItemParserTest<Router> {
|
||||
|
||||
@Override
|
||||
public String resource() {
|
||||
return "/router.json";
|
||||
}
|
||||
|
||||
@Override
|
||||
@SelectJson("router")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Router expected() {
|
||||
return Router.builder()
|
||||
.externalGatewayInfo(ExternalGatewayInfo.builder().networkId("624312ff-d14b-4ba3-9834-1c78d23d574d").build())
|
||||
.state(State.ACTIVE)
|
||||
.name("jclouds-wibble")
|
||||
.tenantId("1234567890")
|
||||
.id("16dba3bc-f3fa-4775-afdc-237e12c72f6a")
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,49 +0,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.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
|
@ -1,39 +0,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.
|
||||
*/
|
||||
|
||||
package org.jclouds.openstack.neutron.v2_0.util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class ClassUtil {
|
||||
|
||||
public static Field findField(Class clazz, String fieldName) {
|
||||
Field fieldToFind = null;
|
||||
if (clazz.getSuperclass() != null)
|
||||
fieldToFind = findField(clazz.getSuperclass(), fieldName);
|
||||
|
||||
if (fieldToFind != null)
|
||||
return fieldToFind;
|
||||
|
||||
for (Field field : clazz.getDeclaredFields()) {
|
||||
if (field.getName().equals(fieldName))
|
||||
return field;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,47 +0,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.
|
||||
*/
|
||||
|
||||
package org.jclouds.openstack.neutron.v2_0.util;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class PredicateUtil {
|
||||
|
||||
public static <T> Predicate<T> createIdEqualsPredicate(final String id) {
|
||||
return new Predicate<T>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable T input) {
|
||||
if (input == null) return false;
|
||||
|
||||
try {
|
||||
Class clazz = input.getClass();
|
||||
Field field = ClassUtil.findField(clazz, "id");
|
||||
field.setAccessible(true);
|
||||
String value = (String) field.get(input);
|
||||
field.setAccessible(false);
|
||||
return value != null && value.equals(id);
|
||||
} catch (IllegalAccessException iae) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue