Class: RightScaleCLI::Tags
- Inherits:
-
Thor
- Object
- Thor
- RightScaleCLI::Tags
- Defined in:
- lib/rightscale_cli/tags.rb
Overview
Represents RightScale Tags
Class Method Summary collapse
Instance Method Summary collapse
- #add(hrefs, tags) ⇒ Object
- #delete(hrefs, tags) ⇒ Object
-
#initialize(*args) ⇒ Tags
constructor
A new instance of Tags.
- #resource(resource_hrefs) ⇒ Object
- #search(resource_type, tag) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Tags
Returns a new instance of Tags.
26 27 28 29 30 |
# File 'lib/rightscale_cli/tags.rb', line 26 def initialize(*args) super @client = RightScaleCLI::Client.new() @logger = RightScaleCLI::Logger.new end |
Class Method Details
.banner(task, _namespace = true, subcommand = false) ⇒ Object
86 87 88 |
# File 'lib/rightscale_cli/tags.rb', line 86 def self.(task, _namespace = true, subcommand = false) "#{basename} #{task.formatted_usage(self, true, subcommand)}" end |
Instance Method Details
#add(hrefs, tags) ⇒ Object
75 76 77 78 |
# File 'lib/rightscale_cli/tags.rb', line 75 def add(hrefs, ) @client.client..multi_add(resource_hrefs: hrefs.split(','), tags: .split(',')) end |
#delete(hrefs, tags) ⇒ Object
81 82 83 84 |
# File 'lib/rightscale_cli/tags.rb', line 81 def delete(hrefs, ) @client.client..multi_delete(resource_hrefs: hrefs.split(','), tags: .split(',')) end |
#resource(resource_hrefs) ⇒ Object
70 71 72 |
# File 'lib/rightscale_cli/tags.rb', line 70 def resource(resource_hrefs) @client.client..by_resource(resource_hrefs: resource_hrefs.split(',')) end |
#search(resource_type, tag) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rightscale_cli/tags.rb', line 40 def search(resource_type, tag) if [:prefix] [:prefix] = tag results = @client.client..by_tag( with_deleted: [:deleted], match_all: [:all], include_tags_with_prefix: [:prefix], resource_type: resource_type, tags: [tag]) else results = @client.client..by_tag( with_deleted: [:deleted], match_all: [:all], resource_type: resource_type, tags: [tag]) end resources = [] results.each { |resource| resources.push(resource.raw) } if resources.count > 0 resource_count = resources[0]['links'].count else resource_count = 0 end @logger.info "Found #{resource_count} #{resource_type} with tag, '#{tag}'." @client.render(resources[0], 'tag_search') unless [:count] || resource_count == 0 end |