You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jclouds.apache.org by David Bosschaert <da...@gmail.com> on 2014/07/17 16:33:13 UTC

Question about node tags

Hi all,

I'm using jclouds (currently with EC2) and was wondering about the
ability to add tags to my compute nodes which I can then later
inspect. I tried the following, but that didn't work:

  TemplateBuilder templateBuilder = compute.templateBuilder();
  templateBuilder.hardwareId(InstanceType.T1_MICRO)
    .osFamily(OsFamily.AMZN_LINUX)
    .locationId(locationId)
    .options(TemplateOptions.Builder.tags(Arrays.asList("tag1", "tag2")))
    .options(TemplateOptions.Builder.inboundPorts(22, 8080))
    .options(TemplateOptions.Builder.runScript(AdminAccess.standard()));
  compute.createNodesInGroup("mygroup", 1, templateBuilder.build())

I would like to be able to read the tags from my nodes later, e.g.:
  for(ComputeMetadata node : compute.listNodes()) {
    Set<String> tags = node.getTags();
    if (!tags.contains("tag1"))
      continue;
  }

The node launches fine, but I find that the 'tags' I get from
node.getTags() never contains the tags I set on it...
Am I doing this wrong? Or is there another way to attach metadata to a node?

Thanks,

David

Re: Question about node tags

Posted by Vineet Saini <sw...@gmail.com>.
Another thing I found that in order to add with AWS EC2, which take tags as
key/value, you can use userMetaData(Map<String,String>).

template.getOptions().userMetadata(Map<String,String> tags);


On Tue, Jul 22, 2014 at 11:17 AM, Andrew Phillips <an...@apache.org>
wrote:

> It's working now - with my VPN off :)
>>
>
> Glad to hear! "VPN considered harmful" ;-)
>
> ap
>

Re: Question about node tags

Posted by Andrew Phillips <an...@apache.org>.
> It's working now - with my VPN off :)

Glad to hear! "VPN considered harmful" ;-)

ap

Re: Question about node tags

Posted by David Bosschaert <da...@gmail.com>.
Thanks Andrew!

Your response made me look at my stuff again and it turned out that it
actually does work as expected.
The problem I was facing when I wrote my email was caused by a VPN
that I was connected to which sent through certain network bits but
not everything. With it I was able to initiate EC2 image creation, but
for some reason the VPN prevented it from completing the image, which
caused things like name and tags not properly being set on it.

It's working now - with my VPN off :)

Cheers,

David

On 18 July 2014 12:11, Andrew Phillips <an...@apache.org> wrote:
> Hi David
>
>
>> The node launches fine, but I find that the 'tags' I get from
>> node.getTags() never contains the tags I set on it...
>> Am I doing this wrong? Or is there another way to attach metadata to a
>> node?
>
>
> I'm not the expert here, but from the looks of the appropriate live test
> [1], it appears that tags and user metadata are only expected to be set if
> the Tag API [2] is present for the particular EC2 provider you're talking
> to.
>
> For AWS EC2, that should probably be the case, but we can at least check to
> see if things are working as expected there. Somewhere in your test code,
> you could see if:
>
> myComputeServiceContext.unwrapApi(EC2Api.class).getTagApi().isPresent()
>
> is true or not. If it *is* present, we'd then need to see why the tags
> aren't being set, but as an immediate workaround you could at least try to
> use the Tag API to manipulate the tags directly.
>
> Regards
>
> ap
>
> [1]
> https://github.com/jclouds/jclouds/blob/master/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2ComputeServiceLiveTest.java#L91
> [2]
> http://javadocs.jclouds.cloudbees.net/org/jclouds/ec2/features/TagApi.html

Re: Question about node tags

Posted by Andrew Phillips <an...@apache.org>.
Hi David

> The node launches fine, but I find that the 'tags' I get from
> node.getTags() never contains the tags I set on it...
> Am I doing this wrong? Or is there another way to attach metadata to a node?

I'm not the expert here, but from the looks of the appropriate live  
test [1], it appears that tags and user metadata are only expected to  
be set if the Tag API [2] is present for the particular EC2 provider  
you're talking to.

For AWS EC2, that should probably be the case, but we can at least  
check to see if things are working as expected there. Somewhere in  
your test code, you could see if:

myComputeServiceContext.unwrapApi(EC2Api.class).getTagApi().isPresent()

is true or not. If it *is* present, we'd then need to see why the tags  
aren't being set, but as an immediate workaround you could at least  
try to use the Tag API to manipulate the tags directly.

Regards

ap

[1]  
https://github.com/jclouds/jclouds/blob/master/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2ComputeServiceLiveTest.java#L91
[2] http://javadocs.jclouds.cloudbees.net/org/jclouds/ec2/features/TagApi.html