diff --git a/labs/google-compute/src/main/java/org/jclouds/googlecompute/GoogleComputeApi.java b/labs/google-compute/src/main/java/org/jclouds/googlecompute/GoogleComputeApi.java
index 258f4895d6..f9f05cc8f7 100644
--- a/labs/google-compute/src/main/java/org/jclouds/googlecompute/GoogleComputeApi.java
+++ b/labs/google-compute/src/main/java/org/jclouds/googlecompute/GoogleComputeApi.java
@@ -22,6 +22,7 @@ import com.google.common.annotations.Beta;
import org.jclouds.googlecompute.features.DiskApi;
import org.jclouds.googlecompute.features.KernelApi;
import org.jclouds.googlecompute.features.MachineTypeApi;
+import org.jclouds.googlecompute.features.NetworkApi;
import org.jclouds.googlecompute.features.OperationApi;
import org.jclouds.googlecompute.features.ProjectApi;
import org.jclouds.googlecompute.features.ZoneApi;
@@ -68,12 +69,14 @@ public interface GoogleComputeApi {
@Path("/projects/{project}")
MachineTypeApi getMachineTypeApiForProject(@PathParam("project") String projectName);
-
/**
- * Provides synchronous access to Project features
+ * Provides synchronous access to Network features
+ *
+ * @param projectName the name of the project
*/
@Delegate
- ProjectApi getProjectApi();
+ @Path("/projects/{project}")
+ NetworkApi getNetworkApiForProject(@PathParam("project") String projectName);
/**
* Provides synchronous access to Operation features
@@ -84,6 +87,12 @@ public interface GoogleComputeApi {
@Path("/projects/{project}")
OperationApi getOperationApiForProject(@PathParam("project") String projectName);
+ /**
+ * Provides synchronous access to Project features
+ */
+ @Delegate
+ ProjectApi getProjectApi();
+
/**
* Provides synchronous access to Zone features
*
diff --git a/labs/google-compute/src/main/java/org/jclouds/googlecompute/GoogleComputeAsyncApi.java b/labs/google-compute/src/main/java/org/jclouds/googlecompute/GoogleComputeAsyncApi.java
index 16d62ffb21..a11bea8c9b 100644
--- a/labs/google-compute/src/main/java/org/jclouds/googlecompute/GoogleComputeAsyncApi.java
+++ b/labs/google-compute/src/main/java/org/jclouds/googlecompute/GoogleComputeAsyncApi.java
@@ -22,6 +22,7 @@ import com.google.common.annotations.Beta;
import org.jclouds.googlecompute.features.DiskAsyncApi;
import org.jclouds.googlecompute.features.KernelAsyncApi;
import org.jclouds.googlecompute.features.MachineTypeAsyncApi;
+import org.jclouds.googlecompute.features.NetworkAsyncApi;
import org.jclouds.googlecompute.features.OperationAsyncApi;
import org.jclouds.googlecompute.features.ProjectAsyncApi;
import org.jclouds.googlecompute.features.ZoneAsyncApi;
@@ -54,8 +55,6 @@ public interface GoogleComputeAsyncApi {
*
* @param projectName the name of the project
*/
- @Delegate
- @Path("/projects/{project}")
KernelAsyncApi getKernelApiForProject(@PathParam("project") String projectName);
/**
@@ -68,10 +67,13 @@ public interface GoogleComputeAsyncApi {
MachineTypeAsyncApi getMachineTypeApiForProject(@PathParam("project") String projectName);
/**
- * Provides asynchronous access to Project features
+ * Provides asynchronous access to Network features
+ *
+ * @param projectName the name of the project
*/
@Delegate
- ProjectAsyncApi getProjectApi();
+ @Path("/projects/{project}")
+ NetworkAsyncApi getNetworkApiForProject(@PathParam("project") String projectName);
/**
* Provides asynchronous access to Operation features
@@ -82,6 +84,12 @@ public interface GoogleComputeAsyncApi {
@Path("/projects/{project}")
OperationAsyncApi getOperationApiForProject(@PathParam("project") String projectName);
+ /**
+ * Provides asynchronous access to Project features
+ */
+ @Delegate
+ ProjectAsyncApi getProjectApi();
+
/**
* Provides asynchronous access to Zone features
*
diff --git a/labs/google-compute/src/main/java/org/jclouds/googlecompute/config/GoogleComputeRestClientModule.java b/labs/google-compute/src/main/java/org/jclouds/googlecompute/config/GoogleComputeRestClientModule.java
index 126f5c4982..e7f3213baa 100644
--- a/labs/google-compute/src/main/java/org/jclouds/googlecompute/config/GoogleComputeRestClientModule.java
+++ b/labs/google-compute/src/main/java/org/jclouds/googlecompute/config/GoogleComputeRestClientModule.java
@@ -33,6 +33,8 @@ import org.jclouds.googlecompute.features.KernelApi;
import org.jclouds.googlecompute.features.KernelAsyncApi;
import org.jclouds.googlecompute.features.MachineTypeApi;
import org.jclouds.googlecompute.features.MachineTypeAsyncApi;
+import org.jclouds.googlecompute.features.NetworkApi;
+import org.jclouds.googlecompute.features.NetworkAsyncApi;
import org.jclouds.googlecompute.features.OperationApi;
import org.jclouds.googlecompute.features.OperationAsyncApi;
import org.jclouds.googlecompute.features.ProjectApi;
@@ -67,6 +69,7 @@ public class GoogleComputeRestClientModule extends RestClientModule
+ */
+@Beta
+public final class Network extends Resource {
+
+ private final String IPv4Range;
+ private final Optional gatewayIPv4;
+
+ @ConstructorProperties({
+ "id", "creationTimestamp", "selfLink", "name", "description", "IPv4Range",
+ "gatewayIPv4"
+ })
+ protected Network(String id, Date creationTimestamp, URI selfLink, String name, String description,
+ String IPv4Range, String gatewayIPv4) {
+ super(Kind.NETWORK, checkNotNull(id, "id of %s", name), fromNullable(creationTimestamp), checkNotNull(selfLink,
+ "selfLink of %s", name), checkNotNull(name, "name"), fromNullable(description));
+ this.IPv4Range = checkNotNull(IPv4Range);
+ this.gatewayIPv4 = fromNullable(gatewayIPv4);
+ }
+
+ /**
+ * @return Required; The range of internal addresses that are legal on this network. This range is a CIDR
+ * specification, for example: 192.168.0.0/16.
+ */
+ public String getIPv4Range() {
+ return IPv4Range;
+ }
+
+ /**
+ * This must be within the range specified by IPv4Range, and is typically the first usable address in that range.
+ * If not specified, the default value is the first usable address in IPv4Range.
+ *
+ * @return an optional address that is used for default routing to other networks.
+ */
+ public Optional getGatewayIPv4() {
+ return gatewayIPv4;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Objects.ToStringHelper string() {
+ return super.string()
+ .omitNullValues()
+ .add("IPv4Range", IPv4Range)
+ .add("gatewayIPv4", gatewayIPv4.orNull());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return string().toString();
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public Builder toBuilder() {
+ return new Builder().fromNetwork(this);
+ }
+
+ public static final class Builder extends Resource.Builder {
+
+ private String IPv4Range;
+ private String gatewayIPv4;
+
+ /**
+ * @see Network#getIPv4Range()
+ */
+ public Builder IPv4Range(String IPv4Range) {
+ this.IPv4Range = IPv4Range;
+ return this;
+ }
+
+ /**
+ * @see Network#getGatewayIPv4()
+ */
+ public Builder gatewayIPv4(String gatewayIPv4) {
+ this.gatewayIPv4 = gatewayIPv4;
+ return this;
+ }
+
+ @Override
+ protected Builder self() {
+ return this;
+ }
+
+ public Network build() {
+ return new Network(super.id, super.creationTimestamp, super.selfLink, super.name,
+ super.description, IPv4Range, gatewayIPv4);
+ }
+
+ public Builder fromNetwork(Network in) {
+ return super.fromResource(in);
+ }
+ }
+
+}
diff --git a/labs/google-compute/src/main/java/org/jclouds/googlecompute/features/NetworkApi.java b/labs/google-compute/src/main/java/org/jclouds/googlecompute/features/NetworkApi.java
new file mode 100644
index 0000000000..c1d717c842
--- /dev/null
+++ b/labs/google-compute/src/main/java/org/jclouds/googlecompute/features/NetworkApi.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to jclouds, Inc. (jclouds) under one or more
+ * contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. jclouds licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.jclouds.googlecompute.features;
+
+import org.jclouds.collect.PagedIterable;
+import org.jclouds.googlecompute.domain.ListPage;
+import org.jclouds.googlecompute.domain.Network;
+import org.jclouds.googlecompute.domain.Operation;
+import org.jclouds.googlecompute.options.ListOptions;
+import org.jclouds.javax.annotation.Nullable;
+
+/**
+ * Provides synchronous access to Networks via their REST API.
+ *
+ * @author David Alves
+ * @see NetworkAsyncApi
+ * @see
+ */
+public interface NetworkApi {
+
+ /**
+ * Returns the specified persistent network resource.
+ *
+ * @param networkName name of the persistent network resource to return.
+ * @return a Network resource.
+ */
+ Network get(String networkName);
+
+ /**
+ * Creates a persistent network resource in the specified project with the specified range.
+ *
+ * @param networkName the network name
+ * @param IPv4Range the range of the network to be inserted.
+ * @return an Operation resource. To check on the status of an operation, poll the Operations resource returned to
+ * you, and look for the status field.
+ */
+ Operation createInIPv4Range(String networkName, String IPv4Range);
+
+ /**
+ * Creates a persistent network resource in the specified project with the specified range and specified gateway.
+ *
+ * @param networkName the network name
+ * @param IPv4Range the range of the network to be inserted.
+ * @param gatewayIPv4 the range of the network to be inserted.
+ * @return an Operation resource. To check on the status of an operation, poll the Operations resource returned to
+ * you, and look for the status field.
+ */
+ Operation createInIPv4RangeWithGateway(String networkName, String IPv4Range, String gatewayIPv4);
+
+ /**
+ * Deletes the specified persistent network resource.
+ *
+ * @param networkName name of the persistent network resource to delete.
+ * @return an Operation resource. To check on the status of an operation, poll the Operations resource returned to
+ * you, and look for the status field.
+ */
+ Operation delete(String networkName);
+
+ /**
+ * @see NetworkApi#listAtMarker(String, org.jclouds.googlecompute.options.ListOptions)
+ */
+ ListPage listFirstPage();
+
+ /**
+ * @see NetworkApi#listAtMarker(String, org.jclouds.googlecompute.options.ListOptions)
+ */
+ ListPage listAtMarker(@Nullable String marker);
+
+ /**
+ * Retrieves the list of persistent network resources contained within the specified project.
+ * By default the list as a maximum size of 100, if no options are provided or ListOptions#getMaxResults() has not
+ * been set.
+ *
+ *
+ * @param marker marks the beginning of the next list page
+ * @param listOptions listing options
+ * @return a page of the list
+ * @see ListOptions
+ * @see org.jclouds.googlecompute.domain.ListPage
+ */
+ ListPage listAtMarker(@Nullable String marker, ListOptions listOptions);
+
+ /**
+ * @see NetworkApi#list(org.jclouds.googlecompute.options.ListOptions)
+ */
+ PagedIterable list();
+
+ /**
+ * A paged version of NetworkApi#list()
+ *
+ * @return a Paged, Fluent Iterable that is able to fetch additional pages when required
+ * @see PagedIterable
+ * @see NetworkApi#listAtMarker(String, org.jclouds.googlecompute.options.ListOptions)
+ */
+ PagedIterable list(@Nullable ListOptions listOptions);
+}
diff --git a/labs/google-compute/src/main/java/org/jclouds/googlecompute/features/NetworkAsyncApi.java b/labs/google-compute/src/main/java/org/jclouds/googlecompute/features/NetworkAsyncApi.java
new file mode 100644
index 0000000000..2c73ac2743
--- /dev/null
+++ b/labs/google-compute/src/main/java/org/jclouds/googlecompute/features/NetworkAsyncApi.java
@@ -0,0 +1,169 @@
+/*
+ * Licensed to jclouds, Inc. (jclouds) under one or more
+ * contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. jclouds licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.jclouds.googlecompute.features;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import org.jclouds.collect.PagedIterable;
+import org.jclouds.googlecompute.domain.ListPage;
+import org.jclouds.googlecompute.domain.Network;
+import org.jclouds.googlecompute.domain.Operation;
+import org.jclouds.googlecompute.functions.internal.ParseNetworks;
+import org.jclouds.googlecompute.options.ListOptions;
+import org.jclouds.javax.annotation.Nullable;
+import org.jclouds.oauth.v2.config.OAuthScopes;
+import org.jclouds.oauth.v2.filters.OAuthAuthenticator;
+import org.jclouds.rest.annotations.Fallback;
+import org.jclouds.rest.annotations.MapBinder;
+import org.jclouds.rest.annotations.PayloadParam;
+import org.jclouds.rest.annotations.RequestFilters;
+import org.jclouds.rest.annotations.ResponseParser;
+import org.jclouds.rest.annotations.SkipEncoding;
+import org.jclouds.rest.annotations.Transform;
+import org.jclouds.rest.binders.BindToJsonPayload;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+
+import static org.jclouds.Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404;
+import static org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
+import static org.jclouds.Fallbacks.NullOnNotFoundOr404;
+import static org.jclouds.googlecompute.GoogleComputeConstants.COMPUTE_READONLY_SCOPE;
+import static org.jclouds.googlecompute.GoogleComputeConstants.COMPUTE_SCOPE;
+
+/**
+ * Provides asynchronous access to Networks via their REST API.
+ *
+ * @author David Alves
+ * @see NetworkApi
+ */
+@SkipEncoding({'/', '='})
+@RequestFilters(OAuthAuthenticator.class)
+public interface NetworkAsyncApi {
+
+ /**
+ * @see NetworkApi#get(String)
+ */
+ @GET
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Path("/networks/{network}")
+ @OAuthScopes(COMPUTE_READONLY_SCOPE)
+ @Fallback(NullOnNotFoundOr404.class)
+ ListenableFuture get(@PathParam("network") String networkName);
+
+ /**
+ * @see NetworkApi#createInIPv4Range(String, String)
+ */
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/networks")
+ @OAuthScopes({COMPUTE_SCOPE})
+ @MapBinder(BindToJsonPayload.class)
+ ListenableFuture createInIPv4Range(@PayloadParam("name") String networkName,
+ @PayloadParam("IPv4Range") String IPv4Range);
+
+ /**
+ * @see NetworkApi#createInIPv4RangeWithGateway(String, String, String)
+ */
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/networks")
+ @OAuthScopes({COMPUTE_SCOPE})
+ @MapBinder(BindToJsonPayload.class)
+ ListenableFuture createInIPv4RangeWithGateway(@PayloadParam("name") String networkName,
+ @PayloadParam("IPv4Range") String IPv4Range,
+ @PayloadParam("gatewayIPv4") String gatewayIPv4);
+
+ /**
+ * @see NetworkApi#delete(String)
+ */
+ @DELETE
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Path("/networks/{network}")
+ @OAuthScopes(COMPUTE_SCOPE)
+ @Fallback(NullOnNotFoundOr404.class)
+ ListenableFuture delete(@PathParam("network") String networkName);
+
+ /**
+ * @see NetworkApi#listFirstPage()
+ */
+ @GET
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Path("/networks")
+ @OAuthScopes(COMPUTE_READONLY_SCOPE)
+ @ResponseParser(ParseNetworks.class)
+ @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ ListenableFuture> listFirstPage();
+
+ /**
+ * @see NetworkApi#listAtMarker(String)
+ */
+ @GET
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Path("/networks")
+ @OAuthScopes(COMPUTE_READONLY_SCOPE)
+ @ResponseParser(ParseNetworks.class)
+ @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ ListenableFuture> listAtMarker(@QueryParam("pageToken") @Nullable String marker);
+
+ /**
+ * @see NetworkApi#listAtMarker(String, org.jclouds.googlecompute.options.ListOptions)
+ */
+ @GET
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Path("/networks")
+ @OAuthScopes(COMPUTE_READONLY_SCOPE)
+ @ResponseParser(ParseNetworks.class)
+ @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ ListenableFuture> listAtMarker(@QueryParam("pageToken") @Nullable String marker,
+ ListOptions options);
+
+ /**
+ * @see NetworkApi#list()
+ */
+ @GET
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Path("/networks")
+ @OAuthScopes(COMPUTE_READONLY_SCOPE)
+ @ResponseParser(ParseNetworks.class)
+ @Transform(ParseNetworks.ToPagedIterable.class)
+ @Fallback(EmptyPagedIterableOnNotFoundOr404.class)
+ ListenableFuture extends PagedIterable> list();
+
+ /**
+ * @see NetworkApi#list(org.jclouds.googlecompute.options.ListOptions)
+ */
+ @GET
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Path("/networks")
+ @OAuthScopes(COMPUTE_READONLY_SCOPE)
+ @ResponseParser(ParseNetworks.class)
+ @Transform(ParseNetworks.ToPagedIterable.class)
+ @Fallback(EmptyPagedIterableOnNotFoundOr404.class)
+ ListenableFuture extends PagedIterable> list(ListOptions options);
+}
diff --git a/labs/google-compute/src/main/java/org/jclouds/googlecompute/functions/internal/ParseNetworks.java b/labs/google-compute/src/main/java/org/jclouds/googlecompute/functions/internal/ParseNetworks.java
new file mode 100644
index 0000000000..53c643273f
--- /dev/null
+++ b/labs/google-compute/src/main/java/org/jclouds/googlecompute/functions/internal/ParseNetworks.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to jclouds, Inc. (jclouds) under one or more
+ * contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. jclouds licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.jclouds.googlecompute.functions.internal;
+
+import com.google.common.base.Function;
+import com.google.inject.TypeLiteral;
+import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.googlecompute.GoogleComputeApi;
+import org.jclouds.googlecompute.domain.ListPage;
+import org.jclouds.googlecompute.domain.Network;
+import org.jclouds.googlecompute.options.ListOptions;
+import org.jclouds.http.functions.ParseJson;
+import org.jclouds.json.Json;
+
+import javax.inject.Inject;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * @author David Alves
+ */
+public class ParseNetworks extends ParseJson> {
+
+ @Inject
+ public ParseNetworks(Json json) {
+ super(json, new TypeLiteral>() {});
+ }
+
+ public static class ToPagedIterable extends BaseToPagedIterable {
+
+ private final GoogleComputeApi api;
+
+ @Inject
+ protected ToPagedIterable(GoogleComputeApi api) {
+ this.api = checkNotNull(api, "api");
+ }
+
+ @Override
+ protected Function