Class: RightScaleCLI::Clouds

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

Overview

Represents Clouds

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Clouds

Returns a new instance of Clouds.



26
27
28
29
30
# File 'lib/rightscale_cli/clouds.rb', line 26

def initialize(*args)
  super
  @client = RightScaleCLI::Client.new(options)
  @logger = RightScaleCLI::Logger.new
end

Class Method Details



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

def self.banner(task, _namespace = true, subcommand = false)
  "#{basename} #{task.formatted_usage(self, true, subcommand)}"
end

Instance Method Details

#listObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rightscale_cli/clouds.rb', line 37

def list
  clouds = @client.get('clouds')

  if options[:basic]
    basic_fields = %w('display_name', 'cloud_type', 'name')
    basic_clouds = []
    @client.get('clouds').each do |cloud|
      cloud_id = cloud['links'].select { |link| link['rel'] == 'instances' }
                 .first['href'].split('/')[3]
      c = cloud.select { |x| basic_fields.include?(x) }
      c['cloud_id'] = cloud_id.to_i
      basic_clouds.push(c)
    end
    clouds = basic_clouds
  end

  @client.render(clouds, 'clouds')
end

#searchObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rightscale_cli/clouds.rb', line 65

def search
  filter = []
  filter.push("name==#{options[:name]}") if options[:name]
  filter.push("cloud_type==#{options[:cloud_type]}") if options[:cloud_type]
  filter.push("description==#{options[:cloud]}") if options[:description]

  @logger.info 'Searching for clouds!'

  puts "filter: #{filter}" if options[:debug]

  clouds = []
  @client.client.clouds.index(filter: filter)
    .each { |cloud| clouds.push(cloud.raw) }
  @client.render(clouds, 'clouds')
end

#show(cloud_id) ⇒ Object



57
58
59
# File 'lib/rightscale_cli/clouds.rb', line 57

def show(cloud_id)
  @client.render(@client.show('clouds', cloud_id), 'cloud')
end