module AWS::EC2::TaggedItem

Public Instance Methods

add_tag(key, options = {}) click to toggle source

Adds a single tag with an optional tag value.

# adds a tag with the key production
resource.tag('production')

# adds a tag with the optional value set to production
resource.tag('role', :value => 'webserver')

@param [String] key The name of the tag to add. @param [Hash] options @option options [String] :value An optional tag value. @return [Tag] The tag that was created.

# File lib/aws/ec2/tagged_item.rb, line 30
def add_tag key, options = {}
  client.create_tags({
    :resources => [id], 
    :tags => [{ :key => key, :value => options[:value].to_s }],
  })
  Tag.new(self, key, options.merge(:config => config))
end
Also aliased as: tag
cached_tags() click to toggle source

@private

# File lib/aws/ec2/tagged_item.rb, line 64
def cached_tags
  if cache = AWS.response_cache
    cache.select(describe_call_name.to_sym).each do |resp|
      if obj = find_in_response(resp)
        return obj.tag_set.inject({}) do |hash, tag|
          hash[tag.key] = tag.value
          hash
        end
      end
    end
  end
  nil
end
clear_tags() click to toggle source

Deletes all tags associated with this EC2 resource. @return [nil]

# File lib/aws/ec2/tagged_item.rb, line 41
def clear_tags
  client.delete_tags(:resources => [self.id])
  nil
end
tag(key, options = {}) click to toggle source
Alias for: add_tag
tagging_resource_type() click to toggle source

@private

# File lib/aws/ec2/tagged_item.rb, line 79
def tagging_resource_type
  Core::Inflection.ruby_name(self.class.to_s).tr("_","-")
end
tags() click to toggle source

Returns a collection that represents only tags belonging to this resource.

@example Manipulating the tags of an EC2 instance

i = ec2.instances["i-123"]
i.tags.to_h                  # => { "foo" => "bar", ... }
i.tags.clear
i.tags.stage = "production"
i.tags.stage                 # => "production"

@return [ResourceTagCollection] A collection of tags that

belong to this resource.
# File lib/aws/ec2/tagged_item.rb, line 59
def tags
  ResourceTagCollection.new(self, :config => config)
end