Class: Chef::Knife::OcaServerList

Inherits:
Chef::Knife show all
Includes:
OcaBase
Defined in:
lib/chef/knife/oca_server_list.rb

Instance Method Summary collapse

Methods included from OcaBase

#connection, #dns_reverse_lookup, included, #locate_config_value, #msg_pair, #validate!

Instance Method Details

#runObject



33
34
35
36
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
65
66
67
68
69
70
71
72
73
# File 'lib/chef/knife/oca_server_list.rb', line 33

def run
  $stdout.sync = true

  validate!

  server_list = [
    ui.color('ID', :bold),
    ui.color('Public IP', :bold),
    ui.color('Public DNS Name', :bold),
    ui.color('State', :bold),
    ui.color('CPUs', :bold),
    ui.color('Memory', :bold),
    ui.color('Template', :bold)
  ]
  connection.virtual_machines.all('m').each do |server|
    server_list << server.id.to_s
    server_list << server.template['NIC']['IP'].to_s
    server_list << dns_reverse_lookup(server.template['NIC']['IP'].to_s)
    server_list << begin
      state = server.lcm_state.to_i
      state = 1 if state == 0
      state = Fog::Compute::OCA::VirtualMachine::LCM_STATE[state]
      case state
      when 'SHUTDOWN', 'CANCEL', 'FAILURE', 'UNKNOWN'
        ui.color(Fog::Compute::OCA::VirtualMachine::SHORT_LCM_STATES[state], :red)
      when 'LCM_INIT', 'PROLOG', 'BOOT'
        ui.color(Fog::Compute::OCA::VirtualMachine::SHORT_LCM_STATES[state], :yellow)
      else
        ui.color(Fog::Compute::OCA::VirtualMachine::SHORT_LCM_STATES[state], :green)
      end
    end
    server_list << server.template['VCPU'].to_s
    server_list << server.template['MEMORY'].to_s
    server_list << begin
      template = connection.templates.get(server.template['TEMPLATE_ID'])
      template.name.to_s
    end
  end
  puts ui.list(server_list, :uneven_columns_across, 7)

end