Class: RightScale::AgentTagManager
- Includes:
- RightSupport::Ruby::EasySingleton
- Defined in:
- lib/right_agent/agent_tag_manager.rb
Overview
Agent tags management
Instance Attribute Summary collapse
-
#agent ⇒ Object
(Agent) Agent being managed.
Instance Method Summary collapse
-
#add_tags(new_tags, options = {}) ⇒ Object
Add given tags to agent.
-
#clear(options = {}) ⇒ Object
Clear all agent tags.
-
#query_tags(tags, options = {}) ⇒ Object
Queries a list of servers in the current deployment which have one or more of the given tags.
-
#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.
-
#remove_tags(old_tags, options = {}) ⇒ Object
Remove given tags from agent.
-
#tags(options = {}) ⇒ Object
Retrieve current agent tags and give result to block.
Instance Attribute Details
#agent ⇒ Object
(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, options = {}) ⇒ Object
Add given tags to agent
Parameters
- new_tags(String, Array)
-
Tag or tags to be added
- options(Hash)
-
Request options
- :timeout(Integer)
-
timeout in seconds before giving up and yielding an error message
Block
A block is optional. If provided, should take one argument which will be set with the raw response
Return
true always return true
110 111 112 113 |
# File 'lib/right_agent/agent_tag_manager.rb', line 110 def (, = {}) = ensure_flat_array_value() unless .nil? || .empty? do_update(, [], ) { |raw_response| yield raw_response if block_given? } end |
#clear(options = {}) ⇒ Object
Clear all agent tags
Parameters
- 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
144 145 146 |
# File 'lib/right_agent/agent_tag_manager.rb', line 144 def clear( = {}) do_update([], @agent., ) { |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 (, = {}) = ensure_flat_array_value() unless .nil? || .empty? do_query(, nil, ) { |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 (, hrefs = nil, = {}) = ensure_flat_array_value() unless .nil? || .empty? = .merge(:raw => true) do_query(, hrefs, ) { |raw_response| yield raw_response } end |
#remove_tags(old_tags, options = {}) ⇒ Object
Remove given tags from agent
Parameters
- old_tags(String, Array)
-
Tag or tags to be removed
- options(Hash)
-
Request options
- :timeout(Integer)
-
timeout in seconds before giving up and yielding an error message
Block
A block is optional. If provided, should take one argument which will be set with the raw response
Return
true always return true
128 129 130 131 |
# File 'lib/right_agent/agent_tag_manager.rb', line 128 def (, = {}) = ensure_flat_array_value() unless .nil? || .empty? do_update([], , ) { |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 ( = {}) # TODO remove use of agent identity when fully drop AMQP do_query(nil, @agent.mode == :http ? @agent.self_href : @agent.identity, ) do |result| if result.kind_of?(Hash) yield(result.size == 1 ? result.values.first['tags'] : []) else yield result end end end |