Class: RightScaleCLI::Tags
- Inherits:
-
Thor
- Object
- Thor
- RightScaleCLI::Tags
- Defined in:
- lib/rightscale_cli/tags.rb
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.
25 26 27 28 29 |
# File 'lib/rightscale_cli/tags.rb', line 25 def initialize(*args) super @client = RightScaleCLI::Client.new() @logger = RightScaleCLI::Logger.new() end |
Class Method Details
.banner(task, namespace = true, subcommand = false) ⇒ Object
83 84 85 |
# File 'lib/rightscale_cli/tags.rb', line 83 def self.(task, namespace = true, subcommand = false) "#{basename} #{task.formatted_usage(self, true, subcommand)}" end |
Instance Method Details
#add(hrefs, tags) ⇒ Object
74 75 76 |
# File 'lib/rightscale_cli/tags.rb', line 74 def add(hrefs, ) @client.client..multi_add(:resource_hrefs => hrefs.split(','), :tags => .split(',')) end |
#delete(hrefs, tags) ⇒ Object
79 80 81 |
# File 'lib/rightscale_cli/tags.rb', line 79 def delete(hrefs, ) @client.client..multi_delete(:resource_hrefs => hrefs.split(','), :tags => .split(',')) end |
#resource(resource_hrefs) ⇒ Object
69 70 71 |
# File 'lib/rightscale_cli/tags.rb', line 69 def resource(resource_hrefs) @client.client..by_resource(:resource_hrefs => resource_hrefs.split(',')) end |
#search(resource_type, tag) ⇒ Object
39 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 |
# File 'lib/rightscale_cli/tags.rb', line 39 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 |