Skip to content

Commit

Permalink
Fix getting facts for hosts from the API
Browse files Browse the repository at this point in the history
Add missing .to_i to convert return value from the api to a number
  • Loading branch information
Dominic Gabriel committed Oct 4, 2019
1 parent ca87f9c commit 88a2984
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions katello-attach-subscription
Original file line number Diff line number Diff line change
Expand Up @@ -1080,12 +1080,14 @@ def vdcupdate()
if @options[:debug]
puts " DEBUG: Checking the number of socket for #{sys["name"]}"
end
# get the facts for the current host from a api call to fact_values
facts = @api.resource(:fact_values).action(:index).call(:organization_id => 1, :per_page => 100000, :search => "host = #{sys['name']}")
# if the number of socket is setted, we can find the value from cpu::cpu_socket(s)
if sys.has_key?("facts") and sys["facts"].is_a?(Hash) and sys["facts"].has_key?("cpu::cpu_socket(s)")
if facts.has_key?('results') and facts['results'].is_a?(Hash) and facts['results'].has_key?(sys['name']) and facts['results'][sys['name']].is_a?(Hash) and facts['results'][sys['name']].has_key?("cpu::cpu_socket(s)")
# if the field is present check if it's a valid entry or not, if not exit with error
if sys["facts"]["cpu::cpu_socket(s)"].to_i > 0
if facts['results'][sys['name']]['cpu::cpu_socket(s)'].to_i > 0
# set sys_socket to the value of cpu::cpu_socket(s)
sys_socket = sys["facts"]["cpu::cpu_socket(s)"].to_i
sys_socket = facts['results'][sys['name']]['cpu::cpu_socket(s)'].to_i
if @options[:debug]
puts " DEBUG: Setting sys_socket to #{sys_socket} for #{sys["name"]}"
end
Expand Down
2 changes: 2 additions & 0 deletions lib/katello_attach_subscription/fact_analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class FactAnalyzer
UNKNOWN = 'Unknown'.freeze

def self.system_type_from_facts(facts)
return unless facts.is_a?(Hash)

if (not facts['virt::host_type'].nil? and facts['virt::host_type'] != 'Not Applicable') or
(facts['virt::is_guest'] and facts['virt::is_guest'].to_s.downcase != 'false') or
facts['virt::uuid']
Expand Down

0 comments on commit 88a2984

Please sign in to comment.