Class: Chef::Knife::BlueboxServerList

Inherits:
Chef::Knife show all
Defined in:
lib/chef/knife/bluebox_server_list.rb

Instance Method Summary collapse

Instance Method Details

#hObject



34
35
36
# File 'lib/chef/knife/bluebox_server_list.rb', line 34

def h
  @highline ||= HighLine.new
end

#runObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/chef/knife/bluebox_server_list.rb', line 38

def run
  bluebox = Fog::Compute::Bluebox.new(
    :bluebox_customer_id => Chef::Config[:knife][:bluebox_customer_id],
    :bluebox_api_key => Chef::Config[:knife][:bluebox_api_key]
  )

  # Make hash of flavor id => name and image id => name
  flavors = bluebox.flavors.inject({}) { |h,f| h[f.id] = f.description; h }
  images  = bluebox.images.inject({}) { |h,i| h[i.id] = i.description; h }

  server_list = [ h.color('ID', :bold), h.color('Hostname', :bold), h.color('IP Address', :bold) ]

  bluebox.servers.each do |server|
    server_list << server.id.to_s
    server_list << server.hostname
    if server.ips[0] && server.ips[0]["address"]
      server_list << server.ips[0]["address"]
    else
      server_list << ""
    end
  end
  puts h.list(server_list, :columns_across, 3)

end