Class: Chef::Knife::SceServerList

Inherits:
Chef::Knife show all
Includes:
SceBase
Defined in:
lib/chef/knife/sce_server_list.rb

Instance Method Summary collapse

Methods included from SceBase

#connection, #connection_storage, #datacenter_id, included, #locate_config_value, #msg_pair, #validate!

Instance Method Details

#runObject



46
47
48
49
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/chef/knife/sce_server_list.rb', line 46

def run
  $stdout.sync = true

  validate!
  
  server_list = [
    ui.color('Instance ID', :bold),
    if config[:name]
      ui.color("Name", :bold)
    end,
    if config[:owner]
      ui.color("Owner", :bold)
    end,
    ui.color('Public IP', :bold),
    ui.color('Secondary IPs', :bold),
    ui.color('Flavor', :bold),
    ui.color('Image', :bold),
    ui.color('SSH Key', :bold),
    ui.color('Expires', :bold),
    ui.color('Request', :bold),
    ui.color('State', :bold)
    
  ].flatten.compact
  
  output_column_count = server_list.length
  
  servers = run!
  
  servers.each do |server|
    server_list << server.id.to_s
    if config[:name]
      server_list << server.name.to_s
    end
    if config[:owner]
      server_list << server.owner.to_s
    end
    server_list << server.primary_ip['hostname'].to_s
    if server.secondary_ip.empty?
      server_list << "n/a"
    else
      ips = []
      server.secondary_ip.each {|sip| ips << sip['ip'] }
      server_list << ips.join(",")
    end
    server_list << server.instance_type.to_s
    server_list << server.image_id.to_s
    server_list << server.key_name.to_s
    server_list << server.expires_at.to_s
    server_list << server.request_id.to_s
    server_list << server.state.to_s
  end
  
  puts ui.list(server_list, :uneven_columns_across, output_column_count)

end

#run!Object



42
43
44
# File 'lib/chef/knife/sce_server_list.rb', line 42

def run!
  connection.servers.all
end