-
Notifications
You must be signed in to change notification settings - Fork 21
/
contrail_interfaces.rb
executable file
·30 lines (29 loc) · 1.27 KB
/
contrail_interfaces.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require 'facter'
Facter.add(:contrail_interfaces) do
setcode do
contrail_interfaces = {}
operatingsystem = Facter.value('operatingsystem')
case operatingsystem
when "CentOS"
interface_list_str = %x[ifconfig -a | grep flags | awk \'{ print $1 \'} | sed \'s/:$// \']
when "Ubuntu"
interface_list_str = %x[ifconfig -a | grep HWaddr | awk \'{ print $1 \'}]
end
intf_list = interface_list_str.split("\n")
intf_list.each do |intf|
intf_detail = {}
vlan_intf = %x[ip addr show #{intf} | head -1| cut -f2 -d':' | grep -o '@.*']
if (vlan_intf != "")
intf_detail["vlan"] = true
intf_detail["parent"] = vlan_intf.delete("\n").delete('@')
else
intf_detail["vlan"] = false
# pci_address = %x[udevadm info -a -p /sys/class/net/#{intf} | awk -F/ '/device.*eth/ {print $4}']
pci_address = %x[/var/lib/puppet/lib/facter/dpdk_nic_bind.py --status | grep #{intf} | cut -d' ' -f 1]
intf_detail["pci_address"] = pci_address.delete("\n")
end
contrail_interfaces[intf] = intf_detail
end
contrail_interfaces
end
end