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

Constructor Details

#initialize(*args) ⇒ ServerArrays

Returns a new instance of ServerArrays.



31
32
33
34
35
# File 'lib/rightscale_cli/server_arrays.rb', line 31

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

Class Method Details



105
106
107
# File 'lib/rightscale_cli/server_arrays.rb', line 105

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
# File 'lib/rightscale_cli/server_arrays/alert_specs.rb', line 22

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

  @client.render(alert_specs, 'server_array')
end

#alerts(server_array_id) ⇒ Object



22
23
24
# File 'lib/rightscale_cli/server_arrays/alerts.rb', line 22

def alerts(server_array_id)
  @client.render(@client.client.server_arrays(:id => server_array_id).show.alerts.index, 'alert_specs')
end

#api_methods(server_array_id) ⇒ Object



90
91
92
93
# File 'lib/rightscale_cli/server_arrays.rb', line 90

def api_methods(server_array_id)
  @logger.info "Retrieving API methods for server array, #{server_array_id}."
  puts @client.client.server_arrays(:id => server_array_id).show.api_methods
end

#desc(server_array_id) ⇒ Object



78
79
80
81
# File 'lib/rightscale_cli/server_arrays.rb', line 78

def desc(server_array_id)
  @logger.info "Retrieving description for server array, #{server_array_id}."
  puts @client.client.server_arrays(:id => server_array_id).show.description
end

#inputs(server_array_id) ⇒ Object



96
97
98
# File 'lib/rightscale_cli/server_arrays.rb', line 96

def inputs(server_array_id)
  @client.render(@client.show('server_arrays', server_array_id), 'server_array')
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
# File 'lib/rightscale_cli/server_arrays/current_instances.rb', line 37

def instances(server_array_id)
  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]

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

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

#instances_count(server_array_id) ⇒ Object



72
73
74
75
# File 'lib/rightscale_cli/server_arrays.rb', line 72

def instances_count(server_array_id)
  @logger.info "Retrieving instances count for server array, #{server_array_id}."
  puts @client.client.server_arrays(:id => server_array_id).show.instances_count
end


31
32
33
34
# File 'lib/rightscale_cli/server_arrays/links.rb', line 31

def links(server_array_id)
  @logger.info "Retrieving links for server array, #{server_array_id}."
  @client.render(@client.client.server_arrays(:id => server_array_id).show.links, 'links')
end

#listObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rightscale_cli/server_arrays.rb', line 44

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

  @logger.debug "filter: #{filter}" if options[:debug]
  
  server_arrays = []
  @client.client.server_arrays.index(:filter => filter).each { |server_array|
    server_arrays.push(server_array.raw)
  }

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

#name(server_array_id) ⇒ Object



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

def name(server_array_id)
  @logger.info "Retrieving name for server array, #{server_array_id}."
  puts @client.client.server_arrays(:id => server_array_id).show.name
end

#next(server_array_id) ⇒ Object



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

def next(server_array_id)
  @client.render(@client.client.server_arrays(:id => server_array_id).show.next_instance.index)
end

#params(server_array_id) ⇒ Object



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

def params(server_array_id)
  @logger.info "Retrieving elasticity parameters for server array, #{server_array_id}."
  @client.render(@client.client.server_arrays(:id => server_array_id).show.elasticity_params, 'server_array')
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
# File 'lib/rightscale_cli/server_arrays/multi_run_executable.rb', line 22

def run_exec(server_array_id, exec_type, exec_identifier)
  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 = @client.client.server_arrays(:id => server_array_id)

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

  server_array.multi_run_executable(params)
end

#show(server_array_id) ⇒ Object



61
62
63
# File 'lib/rightscale_cli/server_arrays.rb', line 61

def show(server_array_id)
  @client.render(@client.show('server_arrays', server_array_id), 'server_array')
end

#state(server_array_id) ⇒ Object



66
67
68
69
# File 'lib/rightscale_cli/server_arrays.rb', line 66

def state(server_array_id)
  @logger.info "Retrieving state for server array, #{server_array_id}."
  puts @client.client.server_arrays(:id => server_array_id).show.state
end