class Facter::Resolvers::Aix::Networking

Private Class Methods

build_bindings(name, ip, mask_length, is_ipv4) click to toggle source
# File lib/facter/resolvers/aix/networking_resolver.rb, line 45
def build_bindings(name, ip, mask_length, is_ipv4)
  bind_to_add = is_ipv4 ? :bindings : :bindings6
  ip = ip.gsub(/%[0-9]$/, '') # remove mask information if it exists
  mask_length = mask_length.to_i - 1 unless is_ipv4
  @fact_list[:interfaces][name] ||= {}
  @fact_list[:interfaces][name][bind_to_add] ||= []
  @fact_list[:interfaces][name][bind_to_add] << ::Resolvers::Utils::Networking.build_binding(ip, mask_length)
end
extract_interfaces(netstat_output) click to toggle source
# File lib/facter/resolvers/aix/networking_resolver.rb, line 32
def extract_interfaces(netstat_output)
  netstat_output.each do |line|
    next if line =~ /default/

    info = line.split("\s")
    mask_length = info[0].match(%r{/([0-9]+)|%([0-9]+)})
    next unless mask_length

    is_ipv4 = info[1] =~ /[0-9]+.[0-9]+.[0-9]+.[0-9]+/
    build_bindings(info[5], info[1], mask_length[1] || mask_length[2], is_ipv4)
  end
end
format_mac_address(address) click to toggle source
# File lib/facter/resolvers/aix/networking_resolver.rb, line 67
def format_mac_address(address)
  address.split('.').map { |e| format('%<mac_address>02s', mac_address: e) }.join(':').tr(' ', '0')
end
get_primary_interface_info(output) click to toggle source
# File lib/facter/resolvers/aix/networking_resolver.rb, line 27
def get_primary_interface_info(output)
  primary_interface_info = output.find { |line| line =~ /=>/ }&.split(' ')
  @fact_list[:primary_interface] = primary_interface_info[5] if primary_interface_info
end
populate_with_mtu_and_mac!(interfaces) click to toggle source
# File lib/facter/resolvers/aix/networking_resolver.rb, line 54
def populate_with_mtu_and_mac!(interfaces)
  output = Facter::Core::Execution.execute('netstat -in', logger: log)
  output.each_line do |line|
    next if line =~ /Name\s/

    info = line.split("\s")
    interface_name = info[0]
    mac = info[3][/^([0-9a-f]{1,2}[\.:-]){5}([0-9a-f]{1,2})$/]
    interfaces[interface_name][:mtu] = info[1].to_i
    interfaces[interface_name][:mac] = format_mac_address(mac) if mac
  end
end
post_resolve(fact_name) click to toggle source
# File lib/facter/resolvers/aix/networking_resolver.rb, line 11
def post_resolve(fact_name)
  @fact_list.fetch(fact_name) { read_netstat(fact_name) }
end
read_netstat(fact_name) click to toggle source
# File lib/facter/resolvers/aix/networking_resolver.rb, line 15
def read_netstat(fact_name)
  @fact_list[:interfaces] = {}
  output = Facter::Core::Execution.execute('netstat -rn', logger: log)
  output = output.each_line.select { |line| (line =~ /\s\s[0-9]+.[0-9]+.[0-9]+.[0-9]+|\s\s.*:[0-9a-f]+/) }
  extract_interfaces(output)

  populate_with_mtu_and_mac!(@fact_list[:interfaces])
  get_primary_interface_info(output)
  ::Resolvers::Utils::Networking.expand_main_bindings(@fact_list)
  @fact_list[fact_name]
end