Class: KnifeCloudstack::CsHosts

Inherits:
Chef::Knife
  • Object
show all
Defined in:
lib/chef/knife/cs_hosts.rb

Constant Summary collapse

MEGABYTES =
1024 * 1024

Instance Method Summary collapse

Instance Method Details

#locate_config_value(key) ⇒ Object



77
78
79
80
# File 'lib/chef/knife/cs_hosts.rb', line 77

def locate_config_value(key)
  key = key.to_sym
  Chef::Config[:knife][key] || config[key]
end

#runObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/chef/knife/cs_hosts.rb', line 51

def run

  connection = CloudstackClient::Connection.new(
      locate_config_value(:cloudstack_url),
      locate_config_value(:cloudstack_api_key),
      locate_config_value(:cloudstack_secret_key)
  )

  host_list = [
      ui.color('#Public IP', :bold),
      ui.color('Host', :bold),
      ui.color('FQDN', :bold)
  ]

  servers = connection.list_servers
  pf_rules = connection.list_port_forwarding_rules
  servers.each do |s|
    host_list << (connection.get_server_public_ip(s, pf_rules) || '#')
    host_list << (s['name'] || '')
    host_list << (connection.get_server_fqdn(s) || '')
  end
  puts ui.list(host_list, :columns_across, 3)

end