You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jclouds.apache.org by Shruti Mehra <me...@gmail.com> on 2013/08/07 10:18:37 UTC
Retrieving provider specific details using JClouds
Hi,
In our project we are trying to write a generic piece of code across cloud
vendors to fetch instance details. The current way to achieve this is by
making a context (the attributes to which might vary depending on the
provider) and then using the getComputeService(). The problem comes when
we need to access provider specific details. Is there a way in JClouds 1.6
and above, through which we can achieve this while keeping the code generic?
For Example:
ComputeServiceContext context =
ContextBuilder.newBuilder("aws-ec2").credentials("identifier",
"credentials") .buildView(ComputeServiceContext.class);
To get the list of nodes:
context.getComputeService().listNodes();
Here the nodes will be represented using NodeMetaData having standard
attributes which hold true for all the cloud providers. What if I wish to
access say aws-ec2 specific attributes without compromising on the generic
code which hold true across vendors?
--
Thanks and Regards,
Shruti Mehra
Re: Retrieving provider specific details using JClouds
Posted by Andrew Phillips <an...@apache.org>.
> I thought unwrapApi wasn't available on async-enabled services...
Sorry, yes, indeed. "unwrapApi" is only available on the current
1.7.0-SNAPSHOT.
Thanks for clarifying, abayer!
ap
Re: Retrieving provider specific details using JClouds
Posted by Andrew Bayer <an...@gmail.com>.
Actually, in 1.6, don't you still need to go the CONTEXT_TOKEN route? i.e.,
EC2Client ec2Client =
computeServiceContext.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi()
I thought unwrapApi wasn't available on async-enabled services...
A.
On Wed, Aug 7, 2013 at 6:43 AM, Andrew Phillips <an...@apache.org> wrote:
> Here the nodes will be represented using NodeMetaData having standard
>> attributes which hold true for all the cloud providers. What if I wish to
>> access say aws-ec2 specific attributes without compromising on the generic
>> code which hold true across vendors?
>>
>
> If you need to get access at AWS-specific APIs or classes, you can
> "unwrap" [1] the context to access the underlying API [2]:
>
> AWSEC2Api awsApi = context.unwrapApi(AWSEC2Api.**class);
>
> If you only use the API in places where provider-specific logic is
> required, the remainder of the code should remain generic. See this recent
> thread [3] for an example of testing for a specific backing provider before
> unwrapping.
>
> ap
>
> [1] http://javadocs.jclouds.**cloudbees.net/org/jclouds/**
> View.html#unwrapApi(java.lang.**Class)<http://javadocs.jclouds.cloudbees.net/org/jclouds/View.html#unwrapApi(java.lang.Class)>
> [2] https://github.com/jclouds/**jclouds/blob/master/providers/**
> aws-ec2/src/main/java/org/**jclouds/aws/ec2/AWSEC2Api.java<https://github.com/jclouds/jclouds/blob/master/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2Api.java>
> [3] http://apache.markmail.org/**thread/g24ahltkamzf6bpp<http://apache.markmail.org/thread/g24ahltkamzf6bpp>
>
Re: Retrieving provider specific details using JClouds
Posted by Shruti Mehra <me...@gmail.com>.
Thank you Andrew.
The unwrap() method works just fine. But I was wondering if JClouds has
provision for something on the following guidelines:
The nodes/instances that we receive from the generic jclouds call populates
the following fields
private final Status status;
private final String backendStatus;
private final int loginPort;
private final Set<String> publicAddresses;
private final Set<String> privateAddresses;
@Nullable
private final LoginCredentials credentials;
@Nullable
private final String group;
@Nullable
private final String imageId;
@Nullable
private final Hardware hardware;
@Nullable
private final OperatingSystem os;
@Nullable
private final String hostname;
Is there any provision in JClouds where the rest of the provider-specific
attributes for a particular instance/node are stored in key value pair
form?
Going by the unwrap() way would require us to be provider-aware and hence
losing out on having a generic code. On the other hand, having key-value
pair would just require skimming through the map, irrespective of any
provider. If only it exists :)
On Wed, Aug 7, 2013 at 7:13 PM, Andrew Phillips <an...@apache.org> wrote:
> Here the nodes will be represented using NodeMetaData having standard
>> attributes which hold true for all the cloud providers. What if I wish to
>> access say aws-ec2 specific attributes without compromising on the generic
>> code which hold true across vendors?
>>
>
> If you need to get access at AWS-specific APIs or classes, you can
> "unwrap" [1] the context to access the underlying API [2]:
>
> AWSEC2Api awsApi = context.unwrapApi(AWSEC2Api.**class);
>
> If you only use the API in places where provider-specific logic is
> required, the remainder of the code should remain generic. See this recent
> thread [3] for an example of testing for a specific backing provider before
> unwrapping.
>
> ap
>
> [1] http://javadocs.jclouds.**cloudbees.net/org/jclouds/**
> View.html#unwrapApi(java.lang.**Class)<http://javadocs.jclouds.cloudbees.net/org/jclouds/View.html#unwrapApi(java.lang.Class)>
> [2] https://github.com/jclouds/**jclouds/blob/master/providers/**
> aws-ec2/src/main/java/org/**jclouds/aws/ec2/AWSEC2Api.java<https://github.com/jclouds/jclouds/blob/master/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2Api.java>
> [3] http://apache.markmail.org/**thread/g24ahltkamzf6bpp<http://apache.markmail.org/thread/g24ahltkamzf6bpp>
>
--
Thanks and Regards,
Shruti Mehra
Re: Retrieving provider specific details using JClouds
Posted by Andrew Phillips <an...@apache.org>.
> Here the nodes will be represented using NodeMetaData having standard
> attributes which hold true for all the cloud providers. What if I wish to
> access say aws-ec2 specific attributes without compromising on the generic
> code which hold true across vendors?
If you need to get access at AWS-specific APIs or classes, you can
"unwrap" [1] the context to access the underlying API [2]:
AWSEC2Api awsApi = context.unwrapApi(AWSEC2Api.class);
If you only use the API in places where provider-specific logic is
required, the remainder of the code should remain generic. See this
recent thread [3] for an example of testing for a specific backing
provider before unwrapping.
ap
[1]
http://javadocs.jclouds.cloudbees.net/org/jclouds/View.html#unwrapApi(java.lang.Class)
[2]
https://github.com/jclouds/jclouds/blob/master/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2Api.java
[3] http://apache.markmail.org/thread/g24ahltkamzf6bpp