This repository has been archived by the owner on Jun 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(FACT-2247) Add networking fact for linux
- Loading branch information
Oana Tanasoiu
committed
May 7, 2020
1 parent
fc5e4f5
commit db972bd
Showing
54 changed files
with
1,115 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Linux | ||
class DhcpServers | ||
FACT_NAME = 'dhcp_servers' | ||
|
||
def call_the_resolver | ||
fact_value = construct_addresses_hash | ||
Facter::ResolvedFact.new(FACT_NAME, !fact_value || fact_value.empty? ? nil : fact_value, :legacy) | ||
end | ||
|
||
private | ||
|
||
def construct_addresses_hash | ||
primary = Facter::Resolvers::NetworkingLinux.resolve(:primary_interface) | ||
interfaces = Facter::Resolvers::NetworkingLinux.resolve(:interfaces) | ||
return unless interfaces | ||
|
||
servers = { system: interfaces[primary][:dhcp] } | ||
interfaces&.each { |interface_name, info| servers[interface_name] = info[:dhcp] if info[:dhcp] } | ||
servers | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Linux | ||
class Ipaddress6Interfaces | ||
FACT_NAME = 'ipaddress6_.*' | ||
TYPE = :legacy | ||
|
||
def call_the_resolver | ||
arr = [] | ||
interfaces = Facter::Resolvers::NetworkingLinux.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Linux | ||
class IpaddressInterfaces | ||
FACT_NAME = 'ipaddress_.*' | ||
TYPE = :legacy | ||
|
||
def call_the_resolver | ||
arr = [] | ||
interfaces = Facter::Resolvers::NetworkingLinux.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Linux | ||
class MacaddressInterfaces | ||
FACT_NAME = 'macaddress_.*' | ||
TYPE = :legacy | ||
|
||
def call_the_resolver | ||
arr = [] | ||
interfaces = Facter::Resolvers::NetworkingLinux.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Linux | ||
class MtuInterfaces | ||
FACT_NAME = 'mtu_.*' | ||
TYPE = :legacy | ||
|
||
def call_the_resolver | ||
arr = [] | ||
interfaces = Facter::Resolvers::NetworkingLinux.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Linux | ||
class Netmask6Interfaces | ||
FACT_NAME = 'netmask6_.*' | ||
TYPE = :legacy | ||
|
||
def call_the_resolver | ||
arr = [] | ||
interfaces = Facter::Resolvers::NetworkingLinux.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Linux | ||
class NetmaskInterfaces | ||
FACT_NAME = 'netmask_.*' | ||
TYPE = :legacy | ||
|
||
def call_the_resolver | ||
arr = [] | ||
interfaces = Facter::Resolvers::NetworkingLinux.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Linux | ||
class Network6Interfaces | ||
FACT_NAME = 'network6_.*' | ||
TYPE = :legacy | ||
|
||
def call_the_resolver | ||
arr = [] | ||
interfaces = Facter::Resolvers::NetworkingLinux.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Linux | ||
class NetworkInterfaces | ||
FACT_NAME = 'network_.*' | ||
TYPE = :legacy | ||
|
||
def call_the_resolver | ||
arr = [] | ||
interfaces = Facter::Resolvers::NetworkingLinux.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Linux | ||
module Networking | ||
class Dhcp | ||
FACT_NAME = 'networking.dhcp' | ||
|
||
def call_the_resolver | ||
interfaces = Facter::Resolvers::NetworkingLinux.resolve(:interfaces) | ||
primary = Facter::Resolvers::NetworkingLinux.resolve(:primary_interface) | ||
|
||
fact_value = interfaces[primary][:dhcp] if interfaces && interfaces[primary] | ||
|
||
Facter::ResolvedFact.new(FACT_NAME, fact_value) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Linux | ||
module Networking | ||
class Ip6 | ||
FACT_NAME = 'networking.ip6' | ||
ALIASES = 'ipaddress6' | ||
|
||
def call_the_resolver | ||
interfaces = Facter::Resolvers::NetworkingLinux.resolve(:interfaces) | ||
primary = Facter::Resolvers::NetworkingLinux.resolve(:primary_interface) | ||
|
||
fact_value = interfaces[primary][:ip6] if interfaces && interfaces[primary] | ||
|
||
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Linux | ||
module Networking | ||
class Mtu | ||
FACT_NAME = 'networking.mtu' | ||
|
||
def call_the_resolver | ||
interfaces = Facter::Resolvers::NetworkingLinux.resolve(:interfaces) | ||
primary = Facter::Resolvers::NetworkingLinux.resolve(:primary_interface) | ||
|
||
fact_value = interfaces[primary][:mtu] if interfaces && interfaces[primary] | ||
|
||
Facter::ResolvedFact.new(FACT_NAME, fact_value) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Linux | ||
module Networking | ||
class Netmask | ||
FACT_NAME = 'networking.netmask' | ||
ALIASES = 'netmask' | ||
|
||
def call_the_resolver | ||
interfaces = Facter::Resolvers::NetworkingLinux.resolve(:interfaces) | ||
primary = Facter::Resolvers::NetworkingLinux.resolve(:primary_interface) | ||
|
||
fact_value = interfaces[primary][:netmask] if interfaces && interfaces[primary] | ||
|
||
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Linux | ||
module Networking | ||
class Netmask6 | ||
FACT_NAME = 'networking.netmask6' | ||
ALIASES = 'netmask6' | ||
|
||
def call_the_resolver | ||
interfaces = Facter::Resolvers::NetworkingLinux.resolve(:interfaces) | ||
primary = Facter::Resolvers::NetworkingLinux.resolve(:primary_interface) | ||
|
||
fact_value = interfaces[primary][:netmask6] if interfaces && interfaces[primary] | ||
|
||
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.