Class: RightScale::AgentTagManager
- Includes:
- Singleton
- 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) ⇒ Object
Add given tags to agent.
-
#clear ⇒ Object
Clear all agent tags.
-
#query_tags(*tags) ⇒ Object
Queries a list of servers in the current deployment which have one or more of the given tags.
-
#query_tags_raw(tags, agent_ids = 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) ⇒ Object
Remove given tags from agent.
-
#tags(options = {}) ⇒ Object
Retrieve current agent tags and give result to block.
-
#update_tags(new_tags, old_tags, &block) ⇒ Object
Runs a tag update with a list of new and old tags.
Methods included from Singleton
Instance Attribute Details
#agent ⇒ Object
(Agent) Agent being managed
32 33 34 |
# File 'lib/right_agent/agent_tag_manager.rb', line 32 def agent @agent end |
Instance Method Details
#add_tags(*new_tags) ⇒ Object
Add given tags to agent
Parameters
- new_tags(Array)
-
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
113 114 115 |
# File 'lib/right_agent/agent_tag_manager.rb', line 113 def (*) (, []) { |raw_response| yield raw_response if block_given? } end |
#clear ⇒ Object
Clear all agent tags
Block
Given block should take one argument which will be set with the raw response
Return
true::Always return true
174 175 176 |
# File 'lib/right_agent/agent_tag_manager.rb', line 174 def clear ([], ) { |raw_response| yield raw_response } end |
#query_tags(*tags) ⇒ Object
Queries a list of servers in the current deployment which have one or more of the given tags.
Parameters
- tags(Array)
-
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 76 77 78 79 80 81 |
# File 'lib/right_agent/agent_tag_manager.rb', line 72 def (*) if .last.respond_to?(:keys) = [0..-2] = .last else = {} end do_query(, nil, ) { |result| yield result } end |
#query_tags_raw(tags, agent_ids = 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(Array)
-
tags to query or empty
- agent_ids(Array)
-
agent IDs to query or empty or nil
- 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
97 98 99 100 |
# File 'lib/right_agent/agent_tag_manager.rb', line 97 def (, agent_ids = nil, ={}) = .merge(:raw=>true) do_query(, agent_ids, ) { |raw_response| yield raw_response } end |
#remove_tags(*old_tags) ⇒ Object
Remove given tags from agent
Parameters
- old_tags(Array)
-
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
128 129 130 |
# File 'lib/right_agent/agent_tag_manager.rb', line 128 def (*) ([], ) { |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
47 48 49 50 51 52 53 54 55 |
# File 'lib/right_agent/agent_tag_manager.rb', line 47 def (={}) do_query(nil, @agent.identity, ) do |result| if result.kind_of?(Hash) yield(result.size == 1 ? result.values.first['tags'] : []) else yield result end end end |
#update_tags(new_tags, old_tags, &block) ⇒ Object
Runs a tag update with a list of new and old tags.
Parameters
- new_tags(Array)
-
new tags to add or empty
- old_tags(Array)
-
old tags to remove or empty
- block(Block)
-
optional callback for update response
Block
A block is optional. If provided, should take one argument which will be set with the raw response
Return
- true
-
Always return true
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/right_agent/agent_tag_manager.rb', line 145 def (, , &block) agent_check = @agent. += ( || []) -= ( || []) .uniq! payload = {:new_tags => , :obsolete_tags => } request = RightScale::IdempotentRequest.new("/mapper/update_tags", payload) if block # always yield raw response request.callback do |_| # refresh agent's copy of tags on successful update @agent. = block.call(request.raw_response) end request.errback { || block.call(request.raw_response || ) } end request.run true end |