From 7a01394c08f45adc9229bdb06b27bb7b5eff2b81 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 6 Dec 2017 12:13:12 -0500 Subject: [PATCH] Merge pull request #16605 from Ladas/allowing_operating_system_for_cloud_manager_graph_refresh Allowing OperatingSystem for CloudManager graph refresh (cherry picked from commit 35f16365d0d366091678058aa4db08222f51632d) https://bugzilla.redhat.com/show_bug.cgi?id=1524572 --- app/models/ext_management_system.rb | 1 + app/models/manageiq/providers/infra_manager.rb | 1 - .../inventory_collection_default.rb | 18 ++++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/models/ext_management_system.rb b/app/models/ext_management_system.rb index eda5beb144e..da2405e20e0 100644 --- a/app/models/ext_management_system.rb +++ b/app/models/ext_management_system.rb @@ -42,6 +42,7 @@ def self.supported_types_and_descriptions_hash :class_name => "VmOrTemplate", :inverse_of => :ext_management_system has_many :miq_templates, :foreign_key => :ems_id, :inverse_of => :ext_management_system has_many :vms, :foreign_key => :ems_id, :inverse_of => :ext_management_system + has_many :operating_systems, :through => :vms_and_templates has_many :hardwares, :through => :vms_and_templates has_many :networks, :through => :hardwares has_many :disks, :through => :hardwares diff --git a/app/models/manageiq/providers/infra_manager.rb b/app/models/manageiq/providers/infra_manager.rb index fbf49df6d35..aafad5dce7f 100644 --- a/app/models/manageiq/providers/infra_manager.rb +++ b/app/models/manageiq/providers/infra_manager.rb @@ -13,7 +13,6 @@ class InfraManager < BaseManager has_many :host_switches, :through => :hosts has_many :host_networks, :through => :hosts, :source => :networks has_many :snapshots, :through => :vms_and_templates - has_many :operating_systems, :through => :vms_and_templates has_many :switches, -> { distinct }, :through => :hosts has_many :lans, -> { distinct }, :through => :hosts has_many :subnets, -> { distinct }, :through => :lans diff --git a/app/models/manager_refresh/inventory_collection_default.rb b/app/models/manager_refresh/inventory_collection_default.rb index 804f0cfb7c5..2122a26d128 100644 --- a/app/models/manager_refresh/inventory_collection_default.rb +++ b/app/models/manager_refresh/inventory_collection_default.rb @@ -72,6 +72,24 @@ def hardwares(extra_attributes = {}) attributes.merge!(extra_attributes) end + def operating_systems(extra_attributes = {}) + attributes = { + :model_class => ::OperatingSystem, + :manager_ref => [:vm_or_template], + :association => :operating_systems, + :parent_inventory_collections => [:vms, :miq_templates], + } + + attributes[:targeted_arel] = lambda do |inventory_collection| + manager_uuids = inventory_collection.parent_inventory_collections.flat_map { |c| c.manager_uuids.to_a } + inventory_collection.parent.operating_systems.joins(:vm_or_template).where( + 'vms' => {:ems_ref => manager_uuids} + ) + end + + attributes.merge!(extra_attributes) + end + def disks(extra_attributes = {}) attributes = { :model_class => ::Disk,