From 89a51c85f1c7abd95611665474d85e2b2d2c289d Mon Sep 17 00:00:00 2001 From: "Saulo S. Toledo" Date: Fri, 4 May 2018 14:43:20 -0300 Subject: [PATCH] Moving Physical Infra models from EMS to PhysicalInfraManager --- app/models/ext_management_system.rb | 4 ---- .../providers/physical_infra_manager.rb | 18 ++++++++++++------ app/models/physical_chassis.rb | 3 ++- app/models/physical_rack.rb | 3 ++- app/models/physical_server.rb | 3 ++- app/models/physical_switch.rb | 5 +++-- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/app/models/ext_management_system.rb b/app/models/ext_management_system.rb index a78bf67dae0..61ca888cb0d 100644 --- a/app/models/ext_management_system.rb +++ b/app/models/ext_management_system.rb @@ -64,10 +64,6 @@ 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_switches, :foreign_key => "ems_id", :dependent => :destroy, :inverse_of => :ext_management_system - has_many :physical_chassis, :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 has_one :iso_datastore, :foreign_key => "ems_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 bb432be099c..c377a45384f 100644 --- a/app/models/manageiq/providers/physical_infra_manager.rb +++ b/app/models/manageiq/providers/physical_infra_manager.rb @@ -2,12 +2,18 @@ module ManageIQ::Providers class PhysicalInfraManager < BaseManager include SupportsFeatureMixin - virtual_total :total_physical_racks, :physical_racks - virtual_total :total_physical_switches, :physical_switches - virtual_total :total_physical_chassis, :physical_chassis - virtual_total :total_physical_servers, :physical_servers - virtual_column :total_hosts, :type => :integer - virtual_column :total_vms, :type => :integer + has_many :physical_chassis, :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 :physical_switches, :foreign_key => "ems_id", :dependent => :destroy, :inverse_of => :ext_management_system + + virtual_total :total_physical_chassis, :physical_chassis + virtual_total :total_physical_racks, :physical_racks + virtual_total :total_physical_servers, :physical_servers + virtual_total :total_physical_switches, :physical_switches + + virtual_column :total_hosts, :type => :integer + virtual_column :total_vms, :type => :integer class << model_name define_method(:route_key) { "ems_physical_infras" } diff --git a/app/models/physical_chassis.rb b/app/models/physical_chassis.rb index 303dcf159cd..6fefe0bd3a2 100644 --- a/app/models/physical_chassis.rb +++ b/app/models/physical_chassis.rb @@ -1,5 +1,6 @@ class PhysicalChassis < ApplicationRecord - belongs_to :ext_management_system, :foreign_key => :ems_id, :inverse_of => :physical_chassis + belongs_to :ext_management_system, :foreign_key => :ems_id, :inverse_of => :physical_chassis, + :class_name => "ManageIQ::Providers::PhysicalInfraManager" belongs_to :physical_rack, :foreign_key => :physical_rack_id, :inverse_of => :physical_chassis has_many :physical_servers, :dependent => :destroy, :inverse_of => :physical_chassis diff --git a/app/models/physical_rack.rb b/app/models/physical_rack.rb index ff1129113cf..7a81c38b7fa 100644 --- a/app/models/physical_rack.rb +++ b/app/models/physical_rack.rb @@ -1,7 +1,8 @@ class PhysicalRack < ApplicationRecord acts_as_miq_taggable - belongs_to :ext_management_system, :foreign_key => :ems_id, :inverse_of => :physical_racks + belongs_to :ext_management_system, :foreign_key => :ems_id, :inverse_of => :physical_racks, + :class_name => "ManageIQ::Providers::PhysicalInfraManager" has_many :physical_chassis, :dependent => :nullify, :inverse_of => :physical_rack has_many :physical_servers, :dependent => :nullify, :inverse_of => :physical_rack diff --git a/app/models/physical_server.rb b/app/models/physical_server.rb index 5241ec3890a..7215caed0e7 100644 --- a/app/models/physical_server.rb +++ b/app/models/physical_server.rb @@ -17,7 +17,8 @@ class PhysicalServer < ApplicationRecord }.freeze validates :vendor, :inclusion =>{:in => VENDOR_TYPES} - belongs_to :ext_management_system, :foreign_key => :ems_id, :inverse_of => :physical_servers + belongs_to :ext_management_system, :foreign_key => :ems_id, :inverse_of => :physical_servers, + :class_name => "ManageIQ::Providers::PhysicalInfraManager" belongs_to :physical_rack, :foreign_key => :physical_rack_id, :inverse_of => :physical_servers belongs_to :physical_chassis, :foreign_key => :physical_chassis_id, :inverse_of => :physical_servers diff --git a/app/models/physical_switch.rb b/app/models/physical_switch.rb index 66878d1b563..e2232872f57 100644 --- a/app/models/physical_switch.rb +++ b/app/models/physical_switch.rb @@ -1,10 +1,11 @@ class PhysicalSwitch < Switch + belongs_to :ext_management_system, :foreign_key => :ems_id, :inverse_of => :physical_switches, + :class_name => "ManageIQ::Providers::PhysicalInfraManager" + has_one :asset_detail, :as => :resource, :dependent => :destroy, :inverse_of => :resource has_one :hardware, :dependent => :destroy, :foreign_key => :switch_id, :inverse_of => :physical_switch has_many :physical_network_ports, :dependent => :destroy, :foreign_key => :switch_id - belongs_to :ext_management_system, :foreign_key => :ems_id, :inverse_of => :physical_switches - def my_zone ems = ext_management_system ems ? ems.my_zone : MiqServer.my_zone