diff --git a/app/models/ems_refresh/save_inventory_physical_infra.rb b/app/models/ems_refresh/save_inventory_physical_infra.rb index ab4f01a16717..18264e9f265f 100644 --- a/app/models/ems_refresh/save_inventory_physical_infra.rb +++ b/app/models/ems_refresh/save_inventory_physical_infra.rb @@ -2,6 +2,8 @@ # Calling order for EmsPhysicalInfra: # - ems # - physical_servers +# - physical_racks +# - physical_servers # module EmsRefresh::SaveInventoryPhysicalInfra @@ -21,10 +23,7 @@ def save_ems_physical_infra_inventory(ems, hashes, target = nil) _log.debug("#{log_header} hashes:\n#{YAML.dump(hashes)}") end - child_keys = [ - :physical_servers, - :customization_scripts - ] + child_keys = %i(physical_servers physical_racks customization_scripts) # Save and link other subsections save_child_inventory(ems, hashes, child_keys, target) @@ -37,17 +36,23 @@ def save_ems_physical_infra_inventory(ems, hashes, target = nil) ems end + def save_physical_racks_inventory(ems, hashes, target = nil) + target = ems if target.nil? + + deletes = target == ems ? :use_association : [] + + ems.physical_racks.reset + save_inventory_multi(ems.physical_racks, hashes, deletes, [:uid_ems], [:physical_servers]) + end + def save_physical_servers_inventory(ems, hashes, target = nil) target = ems if target.nil? ems.physical_servers.reset - deletes = if target == ems - :use_association - else - [] - end + deletes = target == ems ? :use_association : [] + + child_keys = %i(computer_system asset_detail hosts) - child_keys = [:computer_system, :asset_detail, :hosts] save_inventory_multi(ems.physical_servers, hashes, deletes, [:ems_ref], child_keys) store_ids_for_new_records(ems.physical_servers, hashes, :ems_ref) end @@ -56,11 +61,7 @@ def save_customization_scripts_inventory(ems, hashes, target = nil) target = ems if target.nil? ems.customization_scripts.reset - deletes = if target == ems - :use_association - else - [] - end + deletes = target == ems ? :use_association : [] save_inventory_multi(ems.customization_scripts, hashes, deletes, [:manager_ref]) store_ids_for_new_records(ems.customization_scripts, hashes, :manager_ref) diff --git a/app/models/ext_management_system.rb b/app/models/ext_management_system.rb index 56cd3c3aea67..33287ecac374 100644 --- a/app/models/ext_management_system.rb +++ b/app/models/ext_management_system.rb @@ -64,6 +64,7 @@ def self.api_allowed_attributes has_many :resource_pools, :foreign_key => "ems_id", :dependent => :destroy, :inverse_of => :ext_management_system has_many :customization_specs, :foreign_key => "ems_id", :dependent => :destroy, :inverse_of => :ext_management_system has_many :storage_profiles, :foreign_key => "ems_id", :dependent => :destroy, :inverse_of => :ext_management_system + has_many :physical_racks, :foreign_key => "ems_id", :dependent => :destroy, :inverse_of => :ext_management_system has_many :physical_servers, :foreign_key => "ems_id", :dependent => :destroy, :inverse_of => :ext_management_system has_many :customization_scripts, :foreign_key => "manager_id", :dependent => :destroy, :inverse_of => :ext_management_system diff --git a/app/models/manageiq/providers/physical_infra_manager.rb b/app/models/manageiq/providers/physical_infra_manager.rb index 2c075a16ae83..4d0efe300ceb 100644 --- a/app/models/manageiq/providers/physical_infra_manager.rb +++ b/app/models/manageiq/providers/physical_infra_manager.rb @@ -2,6 +2,7 @@ module ManageIQ::Providers class PhysicalInfraManager < BaseManager include SupportsFeatureMixin + virtual_total :total_physical_racks, :physical_racks virtual_total :total_physical_servers, :physical_servers virtual_column :total_hosts, :type => :integer virtual_column :total_vms, :type => :integer diff --git a/app/models/physical_rack.rb b/app/models/physical_rack.rb new file mode 100644 index 000000000000..937a2711d6f2 --- /dev/null +++ b/app/models/physical_rack.rb @@ -0,0 +1,6 @@ +class PhysicalRack < ApplicationRecord + belongs_to :ext_management_system, :foreign_key => :ems_id, + :class_name => "ManageIQ::Providers::PhysicalInfraManager", :inverse_of => :physical_racks + + has_many :physical_servers, :dependent => :destroy, :inverse_of => :physical_rack +end diff --git a/app/models/physical_server.rb b/app/models/physical_server.rb index c937015716b6..d3a535fde4bb 100644 --- a/app/models/physical_server.rb +++ b/app/models/physical_server.rb @@ -18,6 +18,7 @@ class PhysicalServer < ApplicationRecord validates :vendor, :inclusion =>{:in => VENDOR_TYPES} belongs_to :ext_management_system, :foreign_key => :ems_id, :class_name => "ManageIQ::Providers::PhysicalInfraManager" + belongs_to :physical_rack has_one :computer_system, :as => :managed_entity, :dependent => :destroy has_one :hardware, :through => :computer_system diff --git a/spec/factories/physical_rack.rb b/spec/factories/physical_rack.rb new file mode 100644 index 000000000000..00f100085f40 --- /dev/null +++ b/spec/factories/physical_rack.rb @@ -0,0 +1,3 @@ +FactoryGirl.define do + factory :physical_rack +end