Class: RightScaleCLI::Instances

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details



111
112
113
# File 'lib/rightscale_cli/instances.rb', line 111

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

Instance Method Details

#listObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rightscale_cli/instances.rb', line 40

def list()
  instances = []
  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]

  $log.debug "filter: #{filter}" if options[:debug]

  RightApi::Client.new(RightScaleCLI::Config::API).clouds(:id => options[:cloud]).show.instances(:filter => filter).index.each { |instance|
    instances.push(instance.raw)
  }  
  puts instances.to_yaml
end

#run_exec(exec_type, exec_identifier) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/rightscale_cli/instances.rb', line 79

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
  $log.debug "filter: #{filter}" if options[:debug]
  $log.debug "params: #{params}" if options[:debug]
  
  rightscale = RightApi::Client.new(RightScaleCLI::Config::API)

  rightscale.clouds(:id => options[:cloud]).show.instances.multi_run_executable(params)
end