onering-report-plugins 0.0.45 → 0.0.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/facter/onering_properties_network.rb +64 -19
- metadata +1 -1
@@ -94,31 +94,70 @@ end
|
|
94
94
|
|
95
95
|
# LLDP
|
96
96
|
begin
|
97
|
+
require 'xmlsimple'
|
97
98
|
current_iface = nil
|
98
99
|
network_lldp = {}
|
99
100
|
|
100
|
-
output = Facter::Util::Resolution.exec('lldpctl')
|
101
|
+
output = Facter::Util::Resolution.exec('lldpctl -f xml')
|
102
|
+
|
103
|
+
if not output.nil?
|
104
|
+
# XML formatting worked, parse as such
|
105
|
+
if output[0..1] == '<?'
|
106
|
+
output = XmlSimple.xml_in(output)
|
107
|
+
|
108
|
+
(output['interface'] || []).each do |i|
|
109
|
+
current_iface = i['name']
|
110
|
+
port = i['port'].first
|
111
|
+
vlan = i['vlan']
|
112
|
+
chassis = i['chassis'].first
|
113
|
+
speed, duplex = port['auto-negotiation'].first['current'].first['content'].split(' - ',2).first.split(/BaseT/i,2)
|
114
|
+
|
115
|
+
speed = (Integer(speed) * 1000000 rescue nil) # convert to bits
|
116
|
+
duplex = case duplex
|
117
|
+
when 'FD' then :full
|
118
|
+
when 'HD' then :half
|
119
|
+
else nil
|
120
|
+
end
|
121
|
+
|
122
|
+
# port settings
|
123
|
+
network_lldp[current_iface] = Hash[_format(:port_descr, port['descr'].first['content'])]
|
101
124
|
|
102
|
-
|
103
|
-
|
104
|
-
|
125
|
+
network_lldp[current_iface]['port_mac'] = (port['id'].first['content'] rescue nil)
|
126
|
+
network_lldp[current_iface]['mfs'] = (port['mfs'].first['content'].to_i rescue nil)
|
127
|
+
network_lldp[current_iface]['speed'] = speed
|
128
|
+
network_lldp[current_iface]['duplex'] = duplex
|
105
129
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
key = key.downcase.strip.to_sym
|
111
|
-
value.strip!
|
112
|
-
kvs = _format(key,value)
|
130
|
+
# switch settings
|
131
|
+
network_lldp[current_iface]['switch'] = (chassis['name'].first['content'] rescue nil)
|
132
|
+
network_lldp[current_iface]['management_ip'] = (chassis['mgmt-ip'].first['content'] rescue nil)
|
133
|
+
network_lldp[current_iface]['chassis_mac'] = (chassis['id'].first['content'] rescue nil)
|
113
134
|
|
114
|
-
|
115
|
-
|
135
|
+
# Layer 2 / VLAN details
|
136
|
+
network_lldp[current_iface]['vlan'] = (Integer(vlan.select{|i| i['pvid'] == 'yes' }.first['vlan-id']) rescue nil)
|
137
|
+
network_lldp[current_iface]['tagged_vlans'] = (vlan.select{|i| i['pvid'] != 'yes' }.collect{|i| Integer(i['vlan-id']) } rescue nil)
|
138
|
+
end
|
116
139
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
140
|
+
else
|
141
|
+
output.gsub(/^\s+/,'').lines do |line|
|
142
|
+
key, value = line.strip.chomp.squeeze(' ').split(/:\s+/, 2)
|
143
|
+
|
144
|
+
if key and value
|
145
|
+
key.gsub!(/ID$/, '_id')
|
146
|
+
key.gsub!(/[\-\s]+/, '_')
|
147
|
+
key.gsub!(/([a-z])([A-Z])/, '\1_\2')
|
148
|
+
key = key.downcase.strip.to_sym
|
149
|
+
value.strip!
|
150
|
+
kvs = _format(key,value)
|
151
|
+
|
152
|
+
kvs.each do |k, v|
|
153
|
+
next unless k and v
|
154
|
+
|
155
|
+
if k == :interface
|
156
|
+
current_iface = v.split(',').first.to_sym
|
157
|
+
else
|
158
|
+
network_lldp[current_iface] = {} unless network_lldp[current_iface]
|
159
|
+
network_lldp[current_iface][k] = v
|
160
|
+
end
|
122
161
|
end
|
123
162
|
end
|
124
163
|
end
|
@@ -127,6 +166,8 @@ begin
|
|
127
166
|
|
128
167
|
network_lldp.each do |iface, lldp|
|
129
168
|
lldp.each do |key, value|
|
169
|
+
next if value.respond_to?(:empty?) and value.empty?
|
170
|
+
|
130
171
|
Facter.add("lldp_#{key}_#{iface}") do
|
131
172
|
setcode { value }
|
132
173
|
end
|
@@ -170,4 +211,8 @@ begin
|
|
170
211
|
|
171
212
|
rescue Exception => e
|
172
213
|
STDERR.puts "#{e.name}: #{e.message}"
|
173
|
-
|
214
|
+
|
215
|
+
e.backtrace.each do |b|
|
216
|
+
STDERR.puts b
|
217
|
+
end
|
218
|
+
end
|