Skip to content

Commit

Permalink
Merge pull request #2642 from buzzdeee/master
Browse files Browse the repository at this point in the history
(FACT-3163) Add support for OpenBSD
  • Loading branch information
AriaXLi authored Mar 12, 2024
2 parents 82b8cc7 + fff8397 commit d26a217
Show file tree
Hide file tree
Showing 130 changed files with 3,405 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/facter/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ module Config
]
},
{
'Bsd' => [
'Freebsd'
'Bsd' => %w[
Freebsd
Openbsd
]
},
'Solaris',
Expand Down
19 changes: 19 additions & 0 deletions lib/facter/facts/openbsd/augeas/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Facts
module Openbsd
module Augeas
class Version
FACT_NAME = 'augeas.version'
ALIASES = 'augeasversion'

def call_the_resolver
fact_value = Facter::Resolvers::Augeas.resolve(:augeas_version)

[Facter::ResolvedFact.new(FACT_NAME, fact_value),
Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
end
end
end
end
end
19 changes: 19 additions & 0 deletions lib/facter/facts/openbsd/dmi/bios/vendor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Facts
module Openbsd
module Dmi
module Bios
class Vendor
FACT_NAME = 'dmi.bios.vendor'
ALIASES = 'bios_vendor'

def call_the_resolver
fact_value = Facter::Resolvers::Openbsd::DmiBios.resolve(:bios_vendor)
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
end
end
end
end
end
end
19 changes: 19 additions & 0 deletions lib/facter/facts/openbsd/dmi/bios/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Facts
module Openbsd
module Dmi
module Bios
class Version
FACT_NAME = 'dmi.bios.version'
ALIASES = 'bios_version'

def call_the_resolver
fact_value = Facter::Resolvers::Openbsd::DmiBios.resolve(:bios_version)
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
end
end
end
end
end
end
17 changes: 17 additions & 0 deletions lib/facter/facts/openbsd/dmi/manufacturer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module Facts
module Openbsd
module Dmi
class Manufacturer
FACT_NAME = 'dmi.manufacturer'
ALIASES = 'manufacturer'

def call_the_resolver
fact_value = Facter::Resolvers::Openbsd::DmiBios.resolve(:sys_vendor)
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
end
end
end
end
end
19 changes: 19 additions & 0 deletions lib/facter/facts/openbsd/dmi/product/name.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Facts
module Openbsd
module Dmi
module Product
class Name
FACT_NAME = 'dmi.product.name'
ALIASES = 'productname'

def call_the_resolver
fact_value = Facter::Resolvers::Openbsd::DmiBios.resolve(:product_name)
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
end
end
end
end
end
end
19 changes: 19 additions & 0 deletions lib/facter/facts/openbsd/dmi/product/serial_number.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Facts
module Openbsd
module Dmi
module Product
class SerialNumber
FACT_NAME = 'dmi.product.serial_number'
ALIASES = 'serialnumber'

def call_the_resolver
fact_value = Facter::Resolvers::Openbsd::DmiBios.resolve(:product_serial)
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
end
end
end
end
end
end
19 changes: 19 additions & 0 deletions lib/facter/facts/openbsd/dmi/product/uuid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Facts
module Openbsd
module Dmi
module Product
class Uuid
FACT_NAME = 'dmi.product.uuid'
ALIASES = 'uuid'

def call_the_resolver
fact_value = Facter::Resolvers::Openbsd::DmiBios.resolve(:product_uuid)
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
end
end
end
end
end
end
23 changes: 23 additions & 0 deletions lib/facter/facts/openbsd/ec2_metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Facts
module Openbsd
class Ec2Metadata
FACT_NAME = 'ec2_metadata'

def call_the_resolver
return Facter::ResolvedFact.new(FACT_NAME, nil) unless aws_hypervisors?

fact_value = Facter::Resolvers::Ec2.resolve(:metadata)

Facter::ResolvedFact.new(FACT_NAME, fact_value&.empty? ? nil : fact_value)
end

private

def aws_hypervisors?
Facter::Util::Facts::Posix::VirtualDetector.platform =~ /kvm|xen|aws/
end
end
end
end
23 changes: 23 additions & 0 deletions lib/facter/facts/openbsd/ec2_userdata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Facts
module Openbsd
class Ec2Userdata
FACT_NAME = 'ec2_userdata'

def call_the_resolver
return Facter::ResolvedFact.new(FACT_NAME, nil) unless aws_hypervisors?

fact_value = Facter::Resolvers::Ec2.resolve(:userdata)

Facter::ResolvedFact.new(FACT_NAME, fact_value&.empty? ? nil : fact_value)
end

private

def aws_hypervisors?
Facter::Util::Facts::Posix::VirtualDetector.platform =~ /kvm|xen|aws/
end
end
end
end
14 changes: 14 additions & 0 deletions lib/facter/facts/openbsd/facterversion.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Facts
module Openbsd
class Facterversion
FACT_NAME = 'facterversion'

def call_the_resolver
fact_value = Facter::Resolvers::Facterversion.resolve(:facterversion)
Facter::ResolvedFact.new(FACT_NAME, fact_value)
end
end
end
end
16 changes: 16 additions & 0 deletions lib/facter/facts/openbsd/identity/gid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module Facts
module Openbsd
module Identity
class Gid
FACT_NAME = 'identity.gid'

def call_the_resolver
fact_value = Facter::Resolvers::PosxIdentity.resolve(:gid)
Facter::ResolvedFact.new(FACT_NAME, fact_value)
end
end
end
end
end
18 changes: 18 additions & 0 deletions lib/facter/facts/openbsd/identity/group.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module Facts
module Openbsd
module Identity
class Group
FACT_NAME = 'identity.group'
ALIASES = 'gid'

def call_the_resolver
fact_value = Facter::Resolvers::PosxIdentity.resolve(:group)

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

module Facts
module Openbsd
module Identity
class Privileged
FACT_NAME = 'identity.privileged'

def call_the_resolver
fact_value = Facter::Resolvers::PosxIdentity.resolve(:privileged)
Facter::ResolvedFact.new(FACT_NAME, fact_value)
end
end
end
end
end
16 changes: 16 additions & 0 deletions lib/facter/facts/openbsd/identity/uid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module Facts
module Openbsd
module Identity
class Uid
FACT_NAME = 'identity.uid'

def call_the_resolver
fact_value = Facter::Resolvers::PosxIdentity.resolve(:uid)
Facter::ResolvedFact.new(FACT_NAME, fact_value)
end
end
end
end
end
17 changes: 17 additions & 0 deletions lib/facter/facts/openbsd/identity/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module Facts
module Openbsd
module Identity
class User
FACT_NAME = 'identity.user'
ALIASES = 'id'

def call_the_resolver
fact_value = Facter::Resolvers::PosxIdentity.resolve(:user)
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
end
end
end
end
end
20 changes: 20 additions & 0 deletions lib/facter/facts/openbsd/ipaddress6_interfaces.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

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

def call_the_resolver
arr = []
interfaces = Facter::Resolvers::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/openbsd/ipaddress_interfaces.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

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

def call_the_resolver
arr = []
interfaces = Facter::Resolvers::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
21 changes: 21 additions & 0 deletions lib/facter/facts/openbsd/is_virtual.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Facts
module Openbsd
class IsVirtual
FACT_NAME = 'is_virtual'

def call_the_resolver
fact_value = Facter::Util::Facts::Posix::VirtualDetector.platform

Facter::ResolvedFact.new(FACT_NAME, check_if_virtual(fact_value))
end

private

def check_if_virtual(found_vm)
Facter::Util::Facts::PHYSICAL_HYPERVISORS.count(found_vm).zero?
end
end
end
end
14 changes: 14 additions & 0 deletions lib/facter/facts/openbsd/kernel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Facts
module Openbsd
class Kernel
FACT_NAME = 'kernel'

def call_the_resolver
fact_value = Facter::Resolvers::Uname.resolve(:kernelname)
Facter::ResolvedFact.new(FACT_NAME, fact_value)
end
end
end
end
14 changes: 14 additions & 0 deletions lib/facter/facts/openbsd/kernelrelease.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Facts
module Openbsd
class Kernelrelease
FACT_NAME = 'kernelrelease'

def call_the_resolver
fact_value = Facter::Resolvers::Uname.resolve(:kernelrelease)
Facter::ResolvedFact.new(FACT_NAME, fact_value)
end
end
end
end
Loading

0 comments on commit d26a217

Please sign in to comment.