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.
Merge branch 'master' into FACT-2569
- Loading branch information
Showing
23 changed files
with
281 additions
and
69 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
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,43 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Freebsd | ||
module Os | ||
class Release | ||
FACT_NAME = 'os.release' | ||
ALIASES = %w[operatingsystemmajrelease operatingsystemrelease].freeze | ||
|
||
def call_the_resolver | ||
installed_userland = Facter::Resolvers::Freebsd::FreebsdVersion.resolve(:installed_userland) | ||
|
||
return Facter::ResolvedFact.new(FACT_NAME, nil) if !installed_userland || installed_userland.empty? | ||
|
||
value = build_release_hash_from_version(installed_userland) | ||
|
||
[Facter::ResolvedFact.new(FACT_NAME, value), | ||
Facter::ResolvedFact.new(ALIASES.first, value[:major], :legacy), | ||
Facter::ResolvedFact.new(ALIASES.last, installed_userland, :legacy)] | ||
end | ||
|
||
private | ||
|
||
def build_release_hash_from_version(version_string) | ||
version, branch_value = version_string.split('-', 2) | ||
major_value, minor_value = version.split('.') | ||
patchlevel_value = branch_value.split('-p')[1] | ||
|
||
value = { | ||
full: version_string, | ||
major: major_value, | ||
branch: branch_value | ||
} | ||
|
||
value[:minor] = minor_value if minor_value | ||
value[:patchlevel] = patchlevel_value if patchlevel_value | ||
|
||
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
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,39 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facter | ||
module Resolvers | ||
module Freebsd | ||
class FreebsdVersion < BaseResolver | ||
@semaphore = Mutex.new | ||
@fact_list ||= {} | ||
|
||
class << self | ||
private | ||
|
||
def post_resolve(fact_name) | ||
@fact_list.fetch(fact_name) { freebsd_version_system_call(fact_name) } | ||
end | ||
|
||
def freebsd_version_system_call(fact_name) | ||
output, _stderr, status = Open3.capture3('/bin/freebsd-version -kru') | ||
return nil unless status.success? | ||
|
||
build_fact_list(output) | ||
|
||
@fact_list[fact_name] | ||
rescue Errno::ENOENT | ||
nil | ||
end | ||
|
||
def build_fact_list(output) | ||
freebsd_version_results = output.split("\n") | ||
|
||
@fact_list[:installed_kernel] = freebsd_version_results[0].strip | ||
@fact_list[:running_kernel] = freebsd_version_results[1].strip | ||
@fact_list[:installed_userland] = freebsd_version_results[2].strip | ||
end | ||
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 |
---|---|---|
|
@@ -24,7 +24,11 @@ | |
}, | ||
{ | ||
"Solaris": [ | ||
"Bsd" | ||
{ | ||
"Bsd": [ | ||
"Freebsd" | ||
] | ||
} | ||
] | ||
}, | ||
"Macosx", | ||
|
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
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
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
Oops, something went wrong.