13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
|
# File 'lib/chef/knife/voxel_devices_list.rb', line 13
def run
devices = [ ui.color('ID', :bold), ui.color('Name', :bold), ui.color('Type', :bold), ui.color('Status', :bold), ui.color('Facility', :bold), ui.color('Public_IP', :bold), ui.color('Private_IP', :bold) ]
statuses = hapi.helper_devices_status
devices_list = hapi.voxel_devices_list['devices']
unless devices_list.empty?
devices_list['device'] = [ devices_list['device'] ] if devices_list['device'].is_a?(Hash)
devices_list['device'].each do |device|
devices << device['id']
devices << device['label']
devices << case device['type']['content']
when "Virtual Server"
"VoxCLOUD"
when "Server"
"VoxSERVER"
else
device['type']['content']
end
devices << (statuses.has_key?(device['id']) ? statuses[device['id']] : "N/A")
devices << ( device.has_key?('location') ? device['location']['facility']['code'] : "N/A")
if device.has_key?('ipassignments')
ips = device['ipassignments']['ipassignment']
if ips.is_a?(Hash)
ips = [ ips ]
end
ip_frontend = ips.select { |a| a['type'] == "frontend" }.first
ip_backend = ips.select { |a| a['type'] == "backend" }.first
devices << (ip_frontend.nil? ? "" : ip_frontend["content"])
devices << (ip_backend.nil? ? "" : ip_backend["content"])
else
devices << "N/A"
devices << "N/A"
end
end
end
puts ui.list(devices, :columns_across, 7)
end
|