Class: RightScale::AgentTagManager

Inherits:
Object
  • Object
show all
Includes:
RightSupport::Ruby::EasySingleton
Defined in:
lib/right_agent/agent_tag_manager.rb

Overview

Agent tags management

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#agentObject

(Agent) Agent being managed



31
32
33
# File 'lib/right_agent/agent_tag_manager.rb', line 31

def agent
  @agent
end

Instance Method Details

#add_tags(new_tags) ⇒ Object

Add given tags to agent

Parameters

new_tags(String, Array)

Tag or tags to be added

Block

A block is optional. If provided, should take one argument which will be set with the raw response

Return

true always return true



108
109
110
111
# File 'lib/right_agent/agent_tag_manager.rb', line 108

def add_tags(new_tags)
  new_tags = ensure_flat_array_value(new_tags) unless new_tags.nil? || new_tags.empty?
  do_update(new_tags, []) { |raw_response| yield raw_response if block_given? }
end

#clearObject

Clear all agent tags

Block

Given block should take one argument which will be set with the raw response

Return

true::Always return true



136
137
138
# File 'lib/right_agent/agent_tag_manager.rb', line 136

def clear
  do_update([], @agent.tags) { |raw_response| yield raw_response }
end

#query_tags(tags, options = {}) ⇒ Object

Queries a list of servers in the current deployment which have one or more of the given tags.

Parameters

tags(String, Array)

Tag or tags to query or empty

options(Hash)

Request options

:raw(Boolean)

true to yield raw tag response instead of deserialized tags

:timeout(Integer)

timeout in seconds before giving up and yielding an error message

Block

Given block should take one argument which will be set with an array initialized with the tags of this instance

Return

true

Always return true



72
73
74
75
# File 'lib/right_agent/agent_tag_manager.rb', line 72

def query_tags(tags, options = {})
  tags = ensure_flat_array_value(tags) unless tags.nil? || tags.empty?
  do_query(tags, nil, options) { |result| yield result }
end

#query_tags_raw(tags, hrefs = nil, options = {}) ⇒ Object

Queries a list of servers in the current deployment which have one or more of the given tags. Yields the raw response (for responding locally).

Parameters

tags(String, Array)

Tag or tags to query or empty

hrefs(Array)

hrefs of resources to query with empty or nil meaning all instances in deployment

options(Hash)

Request options

:timeout(Integer)

timeout in seconds before giving up and yielding an error message

Block

Given block should take one argument which will be set with the raw response

Return

true

Always return true



91
92
93
94
95
# File 'lib/right_agent/agent_tag_manager.rb', line 91

def query_tags_raw(tags, hrefs = nil, options = {})
  tags = ensure_flat_array_value(tags) unless tags.nil? || tags.empty?
  options = options.merge(:raw => true)
  do_query(tags, hrefs, options) { |raw_response| yield raw_response }
end

#remove_tags(old_tags) ⇒ Object

Remove given tags from agent

Parameters

old_tags(String, Array)

Tag or tags to be removed

Block

A block is optional. If provided, should take one argument which will be set with the raw response

Return

true always return true



124
125
126
127
# File 'lib/right_agent/agent_tag_manager.rb', line 124

def remove_tags(old_tags)
  old_tags = ensure_flat_array_value(old_tags) unless old_tags.nil? || old_tags.empty?
  do_update([], old_tags) { |raw_response| yield raw_response if block_given? }
end

#tags(options = {}) ⇒ Object

Retrieve current agent tags and give result to block

Parameters

options(Hash)

Request options

:raw(Boolean)

true to yield raw tag response instead of deserialized tags

:timeout(Integer)

timeout in seconds before giving up and yielding an error message

Block

Given block should take one argument which will be set with an array initialized with the tags of this instance

Return

true

Always return true



46
47
48
49
50
51
52
53
54
55
# File 'lib/right_agent/agent_tag_manager.rb', line 46

def tags(options = {})
  # TODO remove use of agent identity when fully drop AMQP
  do_query(nil, @agent.mode == :http ? @agent.self_href : @agent.identity, options) do |result|
    if result.kind_of?(Hash)
      yield(result.size == 1 ? result.values.first['tags'] : [])
    else
      yield result
    end
  end
end