Class: RightScaleCLI::ServerArrays

Inherits:
Thor
  • Object
show all
Defined in:
lib/rightscale_cli/server_arrays.rb,
lib/rightscale_cli/server_arrays/links.rb,
lib/rightscale_cli/server_arrays/alerts.rb,
lib/rightscale_cli/server_arrays/alert_specs.rb,
lib/rightscale_cli/server_arrays/current_instances.rb,
lib/rightscale_cli/server_arrays/elasticity_params.rb,
lib/rightscale_cli/server_arrays/multi_run_executable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details



123
124
125
# File 'lib/rightscale_cli/server_arrays.rb', line 123

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

Instance Method Details

#alert_specs(server_array_id) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rightscale_cli/server_arrays/alert_specs.rb', line 22

def alert_specs(server_array_id)
  rightscale = RightApi::Client.new(RightScaleCLI::Config::API)

  alert_specs = []
  rightscale.server_arrays(:id => server_array_id).show.alert_specs.index.each { |alert_spec|
    alert_specs.push(alert_spec.raw)
  }

  if options[:xml]
    puts alert_specs.to_xml(:root => 'alert_specs')
  elsif options[:json]
    puts JSON.pretty_generate(alert_specs)
  else
    puts alert_specs.to_yaml
  end
end

#alerts(server_array_id) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rightscale_cli/server_arrays/alerts.rb', line 22

def alerts(server_array_id)
  rightscale = RightApi::Client.new(RightScaleCLI::Config::API)

  array_alerts = rightscale.server_arrays(:id => server_array_id).show.alerts.index

  if options[:xml]
    puts array_alerts.to_xml(:root => 'alerts')
  elsif options[:json]
    puts JSON.pretty_generate(array_alerts)
  else
    puts array_alerts.to_yaml
  end
end

#api_methods(server_array_id) ⇒ Object



115
116
117
118
119
120
121
# File 'lib/rightscale_cli/server_arrays.rb', line 115

def api_methods(server_array_id)
  log = CLILogger.new
  log.info "Retrieving API methods for server array, #{server_array_id}."
  rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
  server_array = rightscale.server_arrays(:id => server_array_id).show.api_methods
  puts server_array
end

#desc(server_array_id) ⇒ Object



99
100
101
102
103
104
# File 'lib/rightscale_cli/server_arrays.rb', line 99

def desc(server_array_id)
  log = CLILogger.new
  log.info "Retrieving description for server array, #{server_array_id}."
  rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
  puts rightscale.server_arrays(:id => server_array_id).show.description
end

#instances(server_array_id) ⇒ Object



37
38
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
# File 'lib/rightscale_cli/server_arrays/current_instances.rb', line 37

def instances(server_array_id)
  log = CLILogger.new
  rightscale = RightApi::Client.new(RightScaleCLI::Config::API)

  array_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.info "filter: #{filter}" if options[:debug]

  rightscale.server_arrays(:id => server_array_id).show.current_instances(:filter => filter).index.each { |array_instance|
    array_instances.push(array_instance.raw)
  }

  RightScaleCLI::Output.render(array_instances, 'array_instances', options)
end

#instances_count(server_array_id) ⇒ Object



91
92
93
94
95
96
# File 'lib/rightscale_cli/server_arrays.rb', line 91

def instances_count(server_array_id)
  log = CLILogger.new
  log.info "Retrieving instances count for server array, #{server_array_id}."
  rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
  puts rightscale.server_arrays(:id => server_array_id).show.instances_count
end


22
23
24
25
26
27
# File 'lib/rightscale_cli/server_arrays/links.rb', line 22

def links(server_array_id)
  log = CLILogger.new
  log.info "Retrieving links for server array, #{server_array_id}."
  rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
  puts rightscale.server_arrays(:id => server_array_id).show.links.to_yaml
end

#listObject



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

def list()
  log = CLILogger.new
  rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
  
  filter = []
  filter.push("cloud_href==/api/clouds/#{options[:cloud]}") if options[:cloud]
  filter.push("deployment_href==/api/deployments/#{options[:cloud]}") if options[:deployment]
  filter.push("name==#{options[:name]}") if options[:name]

  log.info "filter: #{filter}" if options[:debug]
  
  server_arrays = []
  rightscale.server_arrays.index(:filter => filter).each { |server_array|
    server_arrays.push(server_array.raw)
  }

  if options[:xml]
    puts server_arrays.to_xml(:root => 'server_arrays')
  elsif options[:json]
    puts JSON.pretty_generate(server_arrays)
  else
    puts server_arrays.to_yaml
  end
end

#name(server_array_id) ⇒ Object



107
108
109
110
111
112
# File 'lib/rightscale_cli/server_arrays.rb', line 107

def name(server_array_id)
  log = CLILogger.new
  log.info "Retrieving name for server array, #{server_array_id}."
  rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
  puts rightscale.server_arrays(:id => server_array_id).show.name
end

#params(server_array_id) ⇒ Object



22
23
24
25
26
27
# File 'lib/rightscale_cli/server_arrays/elasticity_params.rb', line 22

def params(server_array_id)
  log = CLILogger.new
  log.info "Retrieving elasticity parameters for server array, #{server_array_id}."
  rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
  puts rightscale.server_arrays(:id => server_array_id).show.elasticity_params.to_yaml
end

#run_exec(server_array_id, exec_type, exec_identifier) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rightscale_cli/server_arrays/multi_run_executable.rb', line 22

def run_exec(server_array_id, exec_type, exec_identifier)
  log = CLILogger.new
  rightscale = RightApi::Client.new(RightScaleCLI::Config::API)

  params = {}

  if exec_type == 'recipe'
    params['recipe_name'] = exec_identifier
  elsif exec_type == 'rightscript'
    params['right_script_href'] = "/api/right_scripts/#{exec_identifier}"
  end
  
  server_array = rightscale.server_arrays(:id => server_array_id)

  log.info "params: #{params}" if options[:debug]
  log.info "Running executable on server array."

  server_array.multi_run_executable(params)
end

#show(server_array_id) ⇒ Object



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

def show(server_array_id)
  log = CLILogger.new
  rightscale = RightApi::Client.new(RightScaleCLI::Config::API)

  server_array = rightscale.server_arrays(:id => server_array_id).show.raw

  if options[:xml]
    puts server_array.to_xml(:root => 'server_array')
  elsif options[:json]
    puts JSON.pretty_generate(server_array)
  else
    puts server_array.to_yaml
  end
end

#state(server_array_id) ⇒ Object



83
84
85
86
87
88
# File 'lib/rightscale_cli/server_arrays.rb', line 83

def state(server_array_id)
  log = CLILogger.new
  log.info "Retrieving state for server array, #{server_array_id}."
  rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
  puts rightscale.server_arrays(:id => server_array_id).show.state
end