Class: RightScaleCLI::Instances

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Instances

Returns a new instance of Instances.



25
26
27
28
29
# File 'lib/rightscale_cli/instances.rb', line 25

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

Class Method Details



128
129
130
# File 'lib/rightscale_cli/instances.rb', line 128

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

Instance Method Details

#listObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rightscale_cli/instances.rb', line 50

def list()
  filter = []
  filter.push("datacenter_href==#{options[:datacenter]}") if options[:datacenter]
  filter.push("deployment_href==#{options[:deployment]}") if options[:deployment]
  filter.push("name==#{options[:private_ip]}") if options[:name]
  filter.push("os_platform==#{options[:os]}") if options[:os]
  filter.push("parent_href==#{options[:parent]}") if options[:parent]
  filter.push("private_dns_name==#{options[:private_dns]}") if options[:private_dns]
  filter.push("private_ip_address==#{options[:private_ip]}") if options[:private_ip]
  filter.push("public_dns==#{options[:public_dns]}") if options[:public_dns]
  filter.push("public_ip_address==#{options[:public_ip]}") if options[:public_ip]
  filter.push("resource_uid==#{options[:resource_uid]}") if options[:resource_uid]
  filter.push("server_template_href==#{options[:server_template]}") if options[:server_template]
  filter.push("state==#{options[:state]}") if options[:state]

  @logger.debug "filter: #{filter}" if options[:debug]

  instances = []
  @client.client.clouds(:id => options[:cloud]).show.instances(:filter => filter).index.each do |instance|
    instance_href = instance.href
    instance = instance.raw
    instance['href'] = instance_href
    instances.push(instance)
  end
  @client.render(instances, 'instances')
end

#run_exec(exec_type, exec_identifier) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/rightscale_cli/instances.rb', line 98

def run_exec(exec_type, exec_identifier)
  params = {}
  filter = []

  if exec_type == 'recipe'
    params['recipe_name'] = exec_identifier
  elsif exec_type == 'rightscript'
    params['right_script_href'] = "/api/right_scripts/#{exec_identifier}"
  end

  filter.push("datacenter_href==#{options[:datacenter]}") if options[:datacenter]
  filter.push("deployment_href==#{options[:deployment]}") if options[:deployment]
  filter.push("name==#{options[:private_ip]}") if options[:name]
  filter.push("os_platform==#{options[:os]}") if options[:os]
  filter.push("parent_href==#{options[:parent]}") if options[:parent]
  filter.push("private_dns_name==#{options[:private_dns]}") if options[:private_dns]
  filter.push("private_ip_address==#{options[:private_ip]}") if options[:private_ip]
  filter.push("public_dns==#{options[:public_dns]}") if options[:public_dns]
  filter.push("public_ip_address==#{options[:public_ip]}") if options[:public_ip]
  filter.push("resource_uid==#{options[:resource_uid]}") if options[:resource_uid]
  filter.push("server_template_href==#{options[:server_template]}") if options[:server_template]
  filter.push("state==#{options[:state]}") if options[:state]

  params['filter'] = filter
  @logger.debug "filter: #{filter}" if options[:debug]
  @logger.debug "params: #{params}" if options[:debug]
  
  @client.client.clouds(:id => options[:cloud]).show.instances.multi_run_executable(params)
end

#show(instance_id) ⇒ Object



79
80
81
82
# File 'lib/rightscale_cli/instances.rb', line 79

def show(instance_id)
  filter = []
  @client.render(@client.client.clouds(:id => options[:cloud]).show.instances.index(:id => instance_id).show.raw, 'instance')
end