Skip to content

Commit

Permalink
(FACT-2656) Added solaris detailed networking facts
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-miclea committed Jul 9, 2020
1 parent e5d265c commit 361501a
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 6 deletions.
18 changes: 18 additions & 0 deletions lib/facts/solaris/networking/ip6.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module Facts
module Solaris
module Networking
class Ip6
FACT_NAME = 'networking.ip6'
ALIASES = 'ipaddress6'

def call_the_resolver
fact_value = Facter::Resolvers::Solaris::Networking.resolve(:ip6)

[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
end
end
end
end
end
18 changes: 18 additions & 0 deletions lib/facts/solaris/networking/mac.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module Facts
module Solaris
module Networking
class Mac
FACT_NAME = 'networking.mac'
ALIASES = 'macaddress'

def call_the_resolver
fact_value = Facter::Resolvers::Solaris::Networking.resolve(:mac)

[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
end
end
end
end
end
17 changes: 17 additions & 0 deletions lib/facts/solaris/networking/mtu.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module Facts
module Solaris
module Networking
class Mtu
FACT_NAME = 'networking.mtu'

def call_the_resolver
fact_value = Facter::Resolvers::Solaris::Networking.resolve(:mtu)

Facter::ResolvedFact.new(FACT_NAME, fact_value)
end
end
end
end
end
18 changes: 18 additions & 0 deletions lib/facts/solaris/networking/netmask.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module Facts
module Solaris
module Networking
class Netmask
FACT_NAME = 'networking.netmask'
ALIASES = 'netmask'

def call_the_resolver
fact_value = Facter::Resolvers::Solaris::Networking.resolve(:netmask)

[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
end
end
end
end
end
18 changes: 18 additions & 0 deletions lib/facts/solaris/networking/netmask6.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module Facts
module Solaris
module Networking
class Netmask6
FACT_NAME = 'networking.netmask6'
ALIASES = 'netmask6'

def call_the_resolver
fact_value = Facter::Resolvers::Solaris::Networking.resolve(:netmask6)

[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
end
end
end
end
end
18 changes: 18 additions & 0 deletions lib/facts/solaris/networking/network.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module Facts
module Solaris
module Networking
class Network
FACT_NAME = 'networking.network'
ALIASES = 'network'

def call_the_resolver
fact_value = Facter::Resolvers::Solaris::Networking.resolve(:network)

[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
end
end
end
end
end
18 changes: 18 additions & 0 deletions lib/facts/solaris/networking/network6.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module Facts
module Solaris
module Networking
class Network6
FACT_NAME = 'networking.network'
ALIASES = 'network'

def call_the_resolver
fact_value = Facter::Resolvers::Solaris::Networking.resolve(:network6)

[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
end
end
end
end
end
13 changes: 8 additions & 5 deletions lib/resolvers/solaris/networking_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class Networking < BaseResolver
@fact_list ||= {}

BINDINGS_KEY = {
FFI::AF_INET => 'bindings',
FFI::AF_INET6 => 'bindings6'
FFI::AF_INET => :bindings,
FFI::AF_INET6 => :bindings6
}.freeze

class << self
Expand All @@ -32,11 +32,14 @@ def read_facts(fact_name)
add_mac(lifreq)
add_bindings(lifreq)
add_mtu(lifreq)
add_dhcp(lifreq.name)
end

@fact_list = { interfaces: @fact_list }
primary_interface
extract_dhcp(@fact_list[:primary_interface])

::Resolvers::Utils::Networking.expand_main_bindings(@fact_list)

@fact_list[fact_name]
end

Expand Down Expand Up @@ -135,10 +138,10 @@ def primary_interface
@fact_list[:primary_interface] = result.match(/interface: (.+)/)&.captures&.first
end

def extract_dhcp(interface_name)
def add_dhcp(interface_name)
result = Facter::Core::Execution.execute("dhcpinfo -i #{interface_name} ServerID", logger: log)

@fact_list[:dhcp] = result.chomp
@fact_list[interface_name][:dhcp] = result.chomp
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion spec/mocks/ffi_mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ def self.define_errno(arg)
def self.type_size(arg); end

module Library
LIBC = 'libc'.freeze

def ffi_convention(arg); end

def ffi_lib(arg); end

def attach_function(function, args, return_type); end
def attach_function(*); end

def enum(*); end

Expand Down

0 comments on commit 361501a

Please sign in to comment.