Getting a resource by its self link is easy. We already have the Resources
api [1] to do that, so you could just add there a method to get a subnet.
Once the method is there, you can inject that Resources api wherever you
need it (the compute service adapter, for example, has it already injected
[2]).

HTH!

I.

[1]
https://github.com/jclouds/jclouds/blob/master/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/Resources.java
[2]
https://github.com/jclouds/jclouds/blob/master/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java#L106

El 7 ago. 2016 6:16 p. m., "Andrea Turli" <andrea.tu...@gmail.com> escribió:

Thanks Nelson,

I guess the first step is to update the Network domain object to reflect
the latest reference

https://cloud.google.com/compute/docs/reference/latest/networks#resource

Then we can discuss how to use the subnetworks.

Andrea

Il dom 7 ago 2016 16:48 Nelson Araujo <nels...@google.com.invalid> ha
scritto:

> +cc: dev@jclouds.apache.org
>
>
> Hi,
>
> I'm implementing subnetworks for Google Cloud Platform, and your help with
> something that could be trivial.
>
> In our case the a network has subnetworks. So the obvious implementation is
> to add a collection to the Network object. As the API returns URI (and I
> don't know how to build them into other objects right at the @Delegate
> level) I'm making it return a List<URI>
>
> The caller now has that list and I would like to fetch their respective
> Subnetwork objects based on its selfLink. I could not figure out a way to
> do that. :-( That's when you come in :-)
>
> The "trick" is that the subnetwork API requires both project and region, so
> when we build the SubnetworkApi if I follow the pattern I need to first
> resolve those 2:
>
> GET https://www.googleapis.com/compute/v1/projects/*project*/regions/
> *region*/subnetworks
> <https://www.googleapis.com/compute/v1/projects/*project*/regions/*region*/subnetworks>
>
>
>
> This is the code I wrote for the client. Part 1 works well, as well as part
> 2. The question is inside part 2....
>
> GoogleComputeEngineApi api = compute.getContext().unwrapApi(
> > GoogleComputeEngineApi.class);
> > ==== Part 1 ====
> > System.out.println("Listing subnetworks in region us-central1...");
> > Iterator<ListPage<Subnetwork>> subnetworks = api.subnetworksInRegion("us-
> > central1").list();
> > while (subnetworks.hasNext()) {
> > for (Subnetwork subnetwork : subnetworks.next()) {
> >     System.out.printf("%s @ %s\n", subnetwork.name(),
> > subnetwork.region());
> >   }
> > }
> > ==== Part 2 ====
> > System.out.println("Listing networks in project...");
> > Iterator<ListPage<Network>> networks = api.networks().list();
> > while (networks.hasNext()) {
> > for (Network network : networks.next()) {
> >     System.out.printf("%-20s %s\n", network.name(),
> > network.type().toString());
> > for (URI subnet : network.subnetworks()) {
> >       System.out.printf(" subnetwork: %s\n", subnet);
> >       // HOW DO I GET THE SUBNETWORK OBJECT HERE?!?!?!?!?
> >       // (or how to build List<Subnetwork> instead of List<URI>?
> >     }
> >   }
> >
> > }
> >
> >
> Or would it be better to simply return List<Subnetwork> instead of
> List<URI>? And if you think that's the best approach how do I build the
> Subnetwork from inside the AutoValue here:
>
> @SerializedNames({ "id", "creationTimestamp", "selfLink", "name",
> "description", "IPv4Range", "gatewayIPv4", "autoCreateSubnetworks",
> "subnetworks"
> })
> public static Network create(String id, Date creationTimestamp, URI
> selfLink, String name, String description, String rangeIPv4,
>       String gatewayIPv4, String autoCreateSubnetworks, *Set<Subnetwork>
> subnetworks*) {
>
> return new AutoValue_Network(id, creationTimestamp, selfLink, name, type,
> description, rangeIPv4, gatewayIPv4,
>            subnetworks);
> }
> In this case because subnetworks is an array of URL it is expecting to be a
> List<String> (or List<URI>). I want to convert to a List<Subnetwork>.
>
> How do I do that?
>
>
> Thanks in advance for your help!!
> -- Nelson
>

Reply via email to