diff --git a/app/models/guest_device.rb b/app/models/guest_device.rb index 09db2943cc6..45861c71072 100644 --- a/app/models/guest_device.rb +++ b/app/models/guest_device.rb @@ -1,10 +1,11 @@ class GuestDevice < ApplicationRecord belongs_to :hardware - has_one :vm_or_template, :through => :hardware - has_one :vm, :through => :hardware - has_one :miq_template, :through => :hardware - has_one :host, :through => :hardware + has_one :vm_or_template, :through => :hardware + has_one :vm, :through => :hardware + has_one :miq_template, :through => :hardware + has_one :host, :through => :hardware + has_one :computer_system, :through => :hardware belongs_to :switch # pNICs link to one switch belongs_to :lan # vNICs link to one lan diff --git a/app/models/physical_network_port.rb b/app/models/physical_network_port.rb index a1418a57736..9b9ce8299b7 100644 --- a/app/models/physical_network_port.rb +++ b/app/models/physical_network_port.rb @@ -4,6 +4,8 @@ class PhysicalNetworkPort < ApplicationRecord has_one :connected_port, :foreign_key => "connected_port_uid", :primary_key => "uid_ems", :class_name => "PhysicalNetworkPort", :dependent => :nullify, :inverse_of => :connected_port has_one :connected_physical_switch, :through => :connected_port, :source => :physical_switch + has_one :computer_system, :through => :guest_device + has_one :connected_computer_system, :through => :connected_port, :source => :computer_system alias_attribute :name, :port_name end diff --git a/app/models/physical_switch.rb b/app/models/physical_switch.rb index 19e622e4afa..3dec23ac39c 100644 --- a/app/models/physical_switch.rb +++ b/app/models/physical_switch.rb @@ -10,6 +10,15 @@ class PhysicalSwitch < Switch has_many :physical_network_ports, :dependent => :destroy, :foreign_key => :switch_id has_many :event_streams, :inverse_of => :physical_switch, :dependent => :nullify + has_many :connected_components, :through => :physical_network_ports, :source => :connected_computer_system + + has_many :connected_physical_servers, + :source_type => "PhysicalServer", + :through => :connected_components, + :source => :managed_entity + + alias_attribute :physical_servers, :connected_physical_servers + def my_zone ems = ext_management_system ems ? ems.my_zone : MiqServer.my_zone