RedHatSatellite / katello-attach-subscription

automatically assign subscriptions to hypervisors based on certain rules
GNU General Public License v2.0
10 stars 5 forks source link

directly merge virt-who data #32

Closed evgeni closed 5 years ago

evgeni commented 5 years ago

currently the data we get from virt-who is used "on demand" by calling gethypervisorsocketfromvirtwho and gethypervisorclusterfromvirtwho, which results in quite a lot of "if/else" code.

how about we always use the data? pseudo ruby:

  hypervisors_collection = []
  hypervisors_list = fetch_all_results(:hosts, :index, {:search => "hypervisor=true"})
  hypervisors_list.each_with_index do |system, currentcount|
    sys = @api.resource(:hosts).call(:show, {:id => system['id'], :fields => 'full'})
    sys = merge_sys_with_virtwodata(sys)  # this is new
    hypervisors_collection.push(sys)
  end

  def merge_sys_with_virtwhodata(sys)
    cleaned_system_name = cleansatellitename(sys['name'])
    rescue_hash = @parsed_hypervisors_hash[cleaned_system_name]
    if rescue_hash.is_a?(Hash)
      rescue_hash['facts'].each do |fact, value|
        fact_name = fact.gsub('.', '::')
        sys['facts'][fact_name] ||= value
      end
    end
    return sys
  end

@mossicrue @Rocco83 thoughts?

mossicrue commented 5 years ago

for me could works better, also adding that facts may help in finding the right type of the hosts