summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-11-26 16:13:22 -0800
committerTim Smith <tsmith@chef.io>2018-11-26 16:13:22 -0800
commitcaceb5b9af91b4635c03a289be0f8cca0a08a043 (patch)
tree99c31e4cea1366bda7c3c1eb88b578be89ee7795
parent616c2f7d0220f58dcd89265728ffc3598ff850c8 (diff)
downloadohai-caceb5b9af91b4635c03a289be0f8cca0a08a043.tar.gz
Switch the platform remapping to a hash table
This is faster and also easier to read Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/ohai/plugins/linux/platform.rb57
1 files changed, 26 insertions, 31 deletions
diff --git a/lib/ohai/plugins/linux/platform.rb b/lib/ohai/plugins/linux/platform.rb
index a36cdc8c..eb793458 100644
--- a/lib/ohai/plugins/linux/platform.rb
+++ b/lib/ohai/plugins/linux/platform.rb
@@ -20,6 +20,20 @@ Ohai.plugin(:Platform) do
provides "platform", "platform_version", "platform_family"
depends "lsb"
+ # the platform mappings between /etc/os-release values and ohai platforms
+ unless defined?(PLATFORM_MAPPINGS)
+ PLATFORM_MAPPINGS = {
+ "rhel" => "redhat",
+ "amzn" => "amazon",
+ "ol" => "oracle",
+ "sles" => "suse",
+ "opensuse-leap" => "opensuseleap",
+ "xenenterprise" => "xenserver",
+ "cumulus-linux" => "cumulus",
+ "nexus" => "nexus_centos",
+ }.freeze
+ end
+
# @deprecated
def get_redhatish_platform(contents)
contents[/^Red Hat/i] ? "redhat" : contents[/(\w+)/i, 1].downcase
@@ -97,6 +111,18 @@ Ohai.plugin(:Platform) do
nil
end
+ # our platform names don't match os-release. given a time machine they would but ohai
+ # came before the os-release file. This method remaps the os-release names to
+ # the ohai names
+ #
+ # @param id [String] the platform ID from /etc/os-release
+ #
+ # @returns [String] the platform name to use in Ohai
+ #
+ def platform_id_remap(id)
+ PLATFORM_MAPPINGS[id] || id
+ end
+
#
# Determines the platform_family based on the platform
#
@@ -273,37 +299,6 @@ Ohai.plugin(:Platform) do
end
end
- # our platform names don't match os-release. given a time machine they would but ohai
- # came before the os-release file. This method remaps the os-release names to
- # the ohai names
- #
- # @param id [String] the platform ID from /etc/os-release
- #
- # @returns [String] the platform name to use in Ohai
- #
- def platform_id_remap(id)
- case id
- when "rhel"
- "redhat"
- when "amzn"
- "amazon"
- when "ol"
- "oracle"
- when "sles"
- "suse"
- when "opensuse-leap"
- "opensuseleap"
- when "xenenterprise"
- "xenserver"
- when "cumulus-linux"
- "cumulus"
- when "nexus"
- "nexus_centos"
- else
- id
- end
- end
-
# Grab the version from the VERSION_ID field and use the kernel release if that's not
# available. It should be there for everything, but rolling releases like arch / gentoo
# where we've traditionally used the kernel as the version