Skip to content

Commit

Permalink
(FACT-2656) Add Solaris networking facts
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdan Irimie authored and sebastian-miclea committed Jul 14, 2020
1 parent 37879e3 commit 133a4bb
Show file tree
Hide file tree
Showing 46 changed files with 1,404 additions and 8 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,30 @@ Facter is a command-line tool that gathers basic facts about nodes (systems) suc
* Ruby 2.3+

## Basic concepts
The project has three main parts, the framework, facts and resolvers.
The project has three main parts, the framework, facts and resolvers.
In the framework we implement functionality that is agnostic of specific facts like parsing user input, formatting output, etc.

Facts are the nuggets of information that will be provided by facter e.g. `os.name`, `networking.interfaces`, etc.

Resolvers have the role of gathering data from the system.
For example a resolver can execute a command on the system, can read a file or any operation that retries some data from a single source on the system.
Resolvers have the role of gathering data from the system.
For example a resolver can execute a command on the system, can read a file or any operation that retries some data from a single source on the system.

![Facter user interaction](docs/diagrams/facter_user_interaction.png?raw=true)

## Getting started
After cloning the project, run `bundle install` to install all dependencies.

You can run facter by executing `./bin/facter`.
You can run facter by executing `./bin/facter`.
The command will output all the facts that facter detected for the current os.

In order to generate a fact, we can use the rake task `rake 'create_fact[<os>,<fact_name>]'` e.g. `rake 'create_fact[ubuntu,facterversion]'`
When generating a fact, the unit test for that fact is also generated. Facts should call on or more resolvers in order to obtain the data they need.

The implementation can be validated locally by running the `./check.sh` script.
The implementation can be validated locally by running the `./check.sh` script.

## Goals - fast, easy, compatible
* Gain performance similar to the C++ version of Facter. We plan to achieve this goal by gathering multiple facts with only one call and by using the faster Win32 API rather than WMI for the Windows implementation.
* Facilitate community contribution. At the moment, C++ presents a possible impediment for community contributions.
* Gain performance similar to the C++ version of Facter. We plan to achieve this goal by gathering multiple facts with only one call and by using the faster Win32 API rather than WMI for the Windows implementation.
* Facilitate community contribution. At the moment, C++ presents a possible impediment for community contributions.
* Enable native integration with other Ruby-based projects such as Bolt and puppet.
* Enable native integration for custom facts.
* Provide 100% compatibility with C++ Facter (drop-in replacement).
27 changes: 27 additions & 0 deletions lib/facter/facts/solaris/dhcp_servers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

module Facts
module Solaris
class DhcpServers
FACT_NAME = 'dhcp_servers'

def call_the_resolver
fact_value = construct_addresses_hash
fact_value = !fact_value || fact_value.empty? ? nil : fact_value
Facter::ResolvedFact.new(FACT_NAME, fact_value, :legacy)
end

private

def construct_addresses_hash
primary_dhcp = Facter::Resolvers::Solaris::Networking.resolve(:dhcp)
interfaces = Facter::Resolvers::Solaris::Networking.resolve(:interfaces)
return unless interfaces

servers = { system: primary_dhcp }
interfaces&.each { |interface_name, info| servers[interface_name] = info[:dhcp] if info[:dhcp] }
servers
end
end
end
end
16 changes: 16 additions & 0 deletions lib/facter/facts/solaris/interfaces.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module Facts
module Solaris
class Interfaces
FACT_NAME = 'interfaces'

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

Facter::ResolvedFact.new(FACT_NAME, fact_value && !fact_value.empty? ? fact_value.keys.sort.join(',') : nil,
:legacy)
end
end
end
end
20 changes: 20 additions & 0 deletions lib/facter/facts/solaris/ipaddress6_interfaces.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Facts
module Solaris
class Ipaddress6Interfaces
FACT_NAME = 'ipaddress6_.*'
TYPE = :legacy

def call_the_resolver
arr = []
interfaces = Facter::Resolvers::Solaris::Networking.resolve(:interfaces)
interfaces&.each do |interface_name, info|
arr << Facter::ResolvedFact.new("ipaddress6_#{interface_name}", info[:ip6], :legacy) if info[:ip6]
end

arr
end
end
end
end
20 changes: 20 additions & 0 deletions lib/facter/facts/solaris/ipaddress_interfaces.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Facts
module Solaris
class IpaddressInterfaces
FACT_NAME = 'ipaddress_.*'
TYPE = :legacy

def call_the_resolver
arr = []
interfaces = Facter::Resolvers::Solaris::Networking.resolve(:interfaces)
interfaces&.each do |interface_name, info|
arr << Facter::ResolvedFact.new("ipaddress_#{interface_name}", info[:ip], :legacy) if info[:ip]
end

arr
end
end
end
end
20 changes: 20 additions & 0 deletions lib/facter/facts/solaris/macaddress_interfaces.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Facts
module Solaris
class MacaddressInterfaces
FACT_NAME = 'macaddress_.*'
TYPE = :legacy

def call_the_resolver
arr = []
interfaces = Facter::Resolvers::Solaris::Networking.resolve(:interfaces)
interfaces&.each do |interface_name, info|
arr << Facter::ResolvedFact.new("macaddress_#{interface_name}", info[:mac], :legacy) if info[:mac]
end

arr
end
end
end
end
20 changes: 20 additions & 0 deletions lib/facter/facts/solaris/mtu_interfaces.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Facts
module Solaris
class MtuInterfaces
FACT_NAME = 'mtu_.*'
TYPE = :legacy

def call_the_resolver
arr = []
interfaces = Facter::Resolvers::Solaris::Networking.resolve(:interfaces)
interfaces&.each do |interface_name, info|
arr << Facter::ResolvedFact.new("mtu_#{interface_name}", info[:mtu], :legacy) if info[:mtu]
end

arr
end
end
end
end
20 changes: 20 additions & 0 deletions lib/facter/facts/solaris/netmask6_interfaces.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Facts
module Solaris
class Netmask6Interfaces
FACT_NAME = 'netmask6_.*'
TYPE = :legacy

def call_the_resolver
arr = []
interfaces = Facter::Resolvers::Solaris::Networking.resolve(:interfaces)
interfaces&.each do |interface_name, info|
arr << Facter::ResolvedFact.new("netmask6_#{interface_name}", info[:netmask6], :legacy) if info[:netmask6]
end

arr
end
end
end
end
20 changes: 20 additions & 0 deletions lib/facter/facts/solaris/netmask_interfaces.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Facts
module Solaris
class NetmaskInterfaces
FACT_NAME = 'netmask_.*'
TYPE = :legacy

def call_the_resolver
arr = []
interfaces = Facter::Resolvers::Solaris::Networking.resolve(:interfaces)
interfaces&.each do |interface_name, info|
arr << Facter::ResolvedFact.new("netmask_#{interface_name}", info[:netmask], :legacy) if info[:netmask]
end

arr
end
end
end
end
20 changes: 20 additions & 0 deletions lib/facter/facts/solaris/network6_interfaces.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Facts
module Solaris
class Network6Interfaces
FACT_NAME = 'network6_.*'
TYPE = :legacy

def call_the_resolver
arr = []
interfaces = Facter::Resolvers::Solaris::Networking.resolve(:interfaces)
interfaces&.each do |interface_name, info|
arr << Facter::ResolvedFact.new("network6_#{interface_name}", info[:network6], :legacy) if info[:network6]
end

arr
end
end
end
end
20 changes: 20 additions & 0 deletions lib/facter/facts/solaris/network_interfaces.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Facts
module Solaris
class NetworkInterfaces
FACT_NAME = 'network_.*'
TYPE = :legacy

def call_the_resolver
arr = []
interfaces = Facter::Resolvers::Solaris::Networking.resolve(:interfaces)
interfaces&.each do |interface_name, info|
arr << Facter::ResolvedFact.new("network_#{interface_name}", info[:network], :legacy) if info[:network]
end

arr
end
end
end
end
17 changes: 17 additions & 0 deletions lib/facter/facts/solaris/networking/dhcp.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 Dhcp
FACT_NAME = 'networking.dhcp'

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

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

module Facts
module Solaris
module Networking
class Interfaces
FACT_NAME = 'networking.interfaces'

def call_the_resolver
fact_value = Facter::Resolvers::Solaris::Networking.resolve(:interfaces)
Facter::ResolvedFact.new(FACT_NAME, fact_value)
end
end
end
end
end
18 changes: 18 additions & 0 deletions lib/facter/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/facter/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/facter/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/facter/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/facter/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/facter/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
Loading

0 comments on commit 133a4bb

Please sign in to comment.