Class: Management::Server::List

Inherits:
Command
  • Object
show all
Includes:
Helper
Defined in:
lib/management/commands/server/list.rb

Instance Method Summary collapse

Methods included from Helper

#cloud, #config, #get_address, #get_env, #get_script, #get_server, #get_type, #live_servers, #system_verbose

Methods inherited from Command

all, #arg_list, #call_with, #command_name, #fn, #help_string, inherited, maxlen, #true_arity

Instance Method Details

#run(env_name = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/management/commands/server/list.rb', line 11

def run(env_name = nil)
  env = get_env(env_name)

  cols = [
          {size: 20, title: "Name",       field: :name },
          {size: 10, title: "State",      field: :state },
          {size: 20, title: "IP",         field: :public_ip_address },
          {size: 20, title: "Private IP", field: :private_ip_address },
          {size: 10, title: "Size",       field: :flavor_id },
          {size: 15, title: "Env",        field: :env },
          {size: 15, title: "Type",       field: :type },
          {size: 11, title: "EC2 ID",     field: :id },
         ]

  format = cols.map{|c| "%-#{c[:size]}s"}.join("  ") + "\n"

  send :printf, *([format].concat(cols.map{|c|c[:title]}))
  send :printf, *([format].concat(cols.map{|c|'-' * c[:size]}))

  servers = live_servers.sort_by(&:name)

  servers.each do |server|
    next if env_name && server.env != env_name
    next if server.state == 'terminated'

    send :printf, *([format].concat(cols.map{|c|server.send(c[:field])}))
  end
end