Class: RightScaleCLI::Tags

Inherits:
Thor
  • Object
show all
Defined in:
lib/rightscale_cli/tags.rb

Overview

Represents RightScale Tags

Class Method Summary collapse

Instance Method Summary collapse

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(options)
  @logger = RightScaleCLI::Logger.new
end

Class Method Details



86
87
88
# File 'lib/rightscale_cli/tags.rb', line 86

def self.banner(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, tags)
  @client.client.tags.multi_add(resource_hrefs: hrefs.split(','),
                                tags: tags.split(','))
end

#delete(hrefs, tags) ⇒ Object



81
82
83
84
# File 'lib/rightscale_cli/tags.rb', line 81

def delete(hrefs, tags)
  @client.client.tags.multi_delete(resource_hrefs: hrefs.split(','),
                                   tags: tags.split(','))
end

#resource(resource_hrefs) ⇒ Object



70
71
72
# File 'lib/rightscale_cli/tags.rb', line 70

def resource(resource_hrefs)
  @client.client.tags.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 options[:prefix]
    options[:prefix] = tag
    results = @client.client.tags.by_tag(
      with_deleted: options[:deleted],
      match_all: options[:all],
      include_tags_with_prefix: options[:prefix],
      resource_type: resource_type,
      tags: [tag])
  else
    results = @client.client.tags.by_tag(
      with_deleted: options[:deleted],
      match_all: options[: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 options[:count] || resource_count == 0
end