Module: Facter::Util::DHCPServers
- Defined in:
- lib/facter/util/dhcp_servers.rb
Class Method Summary collapse
- .device_dhcp_server(device) ⇒ Object
- .devices ⇒ Object
- .gateway_device ⇒ Object
- .nmcli_version ⇒ Object
Class Method Details
.device_dhcp_server(device) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/facter/util/dhcp_servers.rb', line 26 def self.device_dhcp_server(device) if Facter::Core::Execution.which('nmcli') version = self.nmcli_version # If the version is >= 0.9.9, use show instead of list if version && version[0] > 0 || version[1] > 9 || (version[1] == 9 && version[2] >= 9) Facter::Core::Execution.exec("nmcli -f all d show #{device}").scan(/dhcp_server_identifier.*?(\d+\.\d+\.\d+\.\d+)$/).flatten.first else Facter::Core::Execution.exec("nmcli -f all d list iface #{device}").scan(/dhcp_server_identifier.*?(\d+\.\d+\.\d+\.\d+)$/).flatten.first end end end |
.devices ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/facter/util/dhcp_servers.rb', line 18 def self.devices if Facter::Core::Execution.which('nmcli') Facter::Core::Execution.exec("nmcli d").split("\n").select {|d| d =~ /\sconnected/i }.collect{ |line| line.split[0] } else [] end end |
.gateway_device ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/facter/util/dhcp_servers.rb', line 4 def self.gateway_device interface = nil if routes = Facter::Util::FileRead.read('/proc/net/route') routes.each_line do |line| device, destination = line.split(' ') if destination == '00000000' interface = device break end end end interface end |