Class: Chef::Knife::AzureServerList

Inherits:
Chef::Knife show all
Includes:
AzureBase
Defined in:
lib/chef/knife/azure_server_list.rb

Instance Method Summary collapse

Methods included from AzureBase

#connection, #find_file, included, #is_image_windows?, #locate_config_value, #msg_pair, #msg_server_summary, #parse_publish_settings_file, #validate!

Instance Method Details

#runObject



31
32
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
# File 'lib/chef/knife/azure_server_list.rb', line 31

def run
  $stdout.sync = true

  validate!

  server_labels = ['DNS Name', 'VM Name', 'Status', 'IP Address', 'SSH Port', 'WinRM Port' ]
  server_list =  server_labels.map {|label| ui.color(label, :bold)}
  items = connection.roles.all

  items.each do |server|
    server_list << server.hostedservicename.to_s+".cloudapp.net"  # Info about the DNS name at http://msdn.microsoft.com/en-us/library/ee460806.aspx
    server_list << server.name.to_s
    server_list << begin
                     state = server.status.to_s.downcase
                     case state
                     when 'shutting-down','terminated','stopping','stopped'
                       ui.color(state, :red)
                     when 'pending'
                       ui.color(state, :yellow)
                     else
                       ui.color('ready', :green)
                     end
                   end
    server_list << server.publicipaddress.to_s
    server_list << server.sshport.to_s
    server_list << server.winrmport.to_s
  end
  puts ''
  puts ui.list(server_list, :uneven_columns_across, 6)
end