Skip to content

Commit

Permalink
Merge pull request #17423 from saulotoledo/moving_physical_models_to_…
Browse files Browse the repository at this point in the history
…physical_infra

Moving Physical Infra models from EMS to PhysicalInfraManager
  • Loading branch information
agrare authored May 22, 2018
2 parents 2903440 + 89a51c8 commit 35b479e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
4 changes: 0 additions & 4 deletions app/models/ext_management_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 12 additions & 6 deletions app/models/manageiq/providers/physical_infra_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
3 changes: 2 additions & 1 deletion app/models/physical_chassis.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion app/models/physical_rack.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion app/models/physical_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions app/models/physical_switch.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 35b479e

Please sign in to comment.