diff --git a/app/models/ems_refresh/save_inventory_physical_infra.rb b/app/models/ems_refresh/save_inventory_physical_infra.rb index f1e9b319077..e6a72aa300d 100644 --- a/app/models/ems_refresh/save_inventory_physical_infra.rb +++ b/app/models/ems_refresh/save_inventory_physical_infra.rb @@ -2,6 +2,7 @@ # Calling order for EmsPhysicalInfra: # - ems # - physical_racks +# - physical_switches # - physical_servers # @@ -22,7 +23,7 @@ def save_ems_physical_infra_inventory(ems, hashes, target = nil) _log.debug("#{log_header} hashes:\n#{YAML.dump(hashes)}") end - child_keys = %i(physical_racks physical_servers customization_scripts) + child_keys = %i(physical_racks physical_switches physical_servers customization_scripts) # Save and link other subsections save_child_inventory(ems, hashes, child_keys, target) @@ -44,6 +45,14 @@ def save_physical_racks_inventory(ems, hashes, target = nil) store_ids_for_new_records(ems.physical_racks, hashes, :ems_ref) end + def save_physical_switches_inventory(ems, hashes, target = nil) + target = ems if target.nil? + + deletes = target == ems ? :use_association : [] + + save_inventory_multi(ems.physical_switches, hashes, deletes, [:uid_ems], %i(asset_detail hardware)) + end + def save_physical_servers_inventory(ems, hashes, target = nil) target = ems if target.nil? diff --git a/app/models/ext_management_system.rb b/app/models/ext_management_system.rb index 14c6d92aeba..da74eda3275 100644 --- a/app/models/ext_management_system.rb +++ b/app/models/ext_management_system.rb @@ -65,6 +65,7 @@ def self.api_allowed_attributes 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_switches, :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/hardware.rb b/app/models/hardware.rb index f0e07f09396..c9079cbc7d5 100644 --- a/app/models/hardware.rb +++ b/app/models/hardware.rb @@ -4,6 +4,7 @@ class Hardware < ApplicationRecord belongs_to :miq_template, :foreign_key => :vm_or_template_id belongs_to :host belongs_to :computer_system + belongs_to :physical_switch, :foreign_key => :switch_id, :inverse_of => :hardware has_many :networks, :dependent => :destroy has_many :firmwares, :as => :resource, :dependent => :destroy diff --git a/app/models/manageiq/providers/physical_infra_manager.rb b/app/models/manageiq/providers/physical_infra_manager.rb index 4d0efe300ce..8eb7678e631 100644 --- a/app/models/manageiq/providers/physical_infra_manager.rb +++ b/app/models/manageiq/providers/physical_infra_manager.rb @@ -3,6 +3,7 @@ class PhysicalInfraManager < BaseManager include SupportsFeatureMixin virtual_total :total_physical_racks, :physical_racks + virtual_total :total_physical_switches, :physical_switches 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_switch.rb b/app/models/physical_switch.rb new file mode 100644 index 00000000000..e95721dd126 --- /dev/null +++ b/app/models/physical_switch.rb @@ -0,0 +1,6 @@ +class PhysicalSwitch < Switch + has_one :asset_detail, :as => :resource, :dependent => :destroy, :inverse_of => :resource + has_one :hardware, :dependent => :destroy, :foreign_key => :switch_id, :inverse_of => :physical_switch + + belongs_to :ext_management_system, :foreign_key => :ems_id, :inverse_of => :physical_switches +end diff --git a/app/models/switch.rb b/app/models/switch.rb index b4972302262..17a803fabbe 100644 --- a/app/models/switch.rb +++ b/app/models/switch.rb @@ -1,4 +1,5 @@ class Switch < ApplicationRecord + include NewWithTypeStiMixin include CustomActionsMixin has_many :host_switches, :dependent => :destroy