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
|
# File 'lib/chef/knife/cs_server_list.rb', line 48
def run
$stdout.sync = true
connection = CloudstackClient::Connection.new(
locate_config_value(:cloudstack_url),
locate_config_value(:cloudstack_api_key),
locate_config_value(:cloudstack_secret_key)
)
server_list = [
ui.color('Name', :bold),
ui.color('Public IP', :bold),
ui.color('Service', :bold),
ui.color('Template', :bold),
ui.color('State', :bold),
ui.color('Hypervisor', :bold)
]
servers = connection.list_servers
rules = connection.list_port_forwarding_rules
servers.each do |server|
name = server['name']
display_name = server['displayname']
if display_name && !display_name.empty? && display_name != name
name << " (#{display_name})"
end
server_list << server['name']
server_list << (connection.get_server_public_ip(server, rules) || '')
server_list << server['serviceofferingname']
server_list << server['templatename']
server_list << server['state']
server_list << (server['hostname'] || 'N/A')
end
puts ui.list(server_list, :columns_across, 6)
end
|