Class/Module Index [+]

Quicksearch

Facter::Util::DHCPServers

Public Class Methods

device_dhcp_server(device) click to toggle source
# File lib/facter/util/dhcp_servers.rb, line 26
def self.device_dhcp_server(device)
  if Facter::Core::Execution.which('nmcli')
    # If the version is >= 0.9.9, use show instead of list
    if is_newer_nmcli?
      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() click to toggle source
# 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/ }.collect{ |line| line.split[0] }
  else
    []
  end
end
gateway_device() click to toggle source
# 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
is_newer_nmcli?() click to toggle source
# File lib/facter/util/dhcp_servers.rb, line 54
def self.is_newer_nmcli?
  version = nmcli_version
  version && (version[0] > 0 || version[1] > 9 || (version[1] == 9 && version[2] >= 9))
end
network_manager_state() click to toggle source
# File lib/facter/util/dhcp_servers.rb, line 37
def self.network_manager_state
  # If the version is >= 0.9.9, use g instead of nm
  if is_newer_nmcli?
    output = Facter::Core::Execution.exec('nmcli -t -f STATE g 2>/dev/null')
  else
    output = Facter::Core::Execution.exec('nmcli -t -f STATE nm 2>/dev/null')
  end
  return nil unless output
  output.strip
end
nmcli_version() click to toggle source
# File lib/facter/util/dhcp_servers.rb, line 48
def self.nmcli_version
  if version = Facter::Core::Execution.exec("nmcli --version")
    version.scan(/version\s(\d+)\.?(\d+)?\.?(\d+)?\.?(\d+)?/).flatten.map(&:to_i)
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.