From 53e402adecda5565b27fe1929d3a63981be156e7 Mon Sep 17 00:00:00 2001 From: Douglas Gabriel Date: Fri, 20 Jul 2018 09:45:29 -0300 Subject: [PATCH] Connecting physical switch to computer systems --- app/models/physical_network_port.rb | 14 ++++++++++++++ app/models/physical_switch.rb | 2 ++ 2 files changed, 16 insertions(+) diff --git a/app/models/physical_network_port.rb b/app/models/physical_network_port.rb index a1418a577368..e9810a440a34 100644 --- a/app/models/physical_network_port.rb +++ b/app/models/physical_network_port.rb @@ -3,7 +3,21 @@ class PhysicalNetworkPort < ApplicationRecord belongs_to :physical_switch, :foreign_key => :switch_id, :inverse_of => :physical_network_ports 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 + virtual_has_one :connected_computer_system + alias_attribute :name, :port_name + + # + # Gets the computer system that is connected through a + # physical network port + # + # @return The computer system managed entity connected to this port + # or nil if none computer system is connected. + # + def connected_computer_system + connected_port&.guest_device&.hardware&.computer_system&.managed_entity + end end diff --git a/app/models/physical_switch.rb b/app/models/physical_switch.rb index c1e12b3e33d9..628f9bca7661 100644 --- a/app/models/physical_switch.rb +++ b/app/models/physical_switch.rb @@ -6,6 +6,8 @@ class PhysicalSwitch < Switch has_one :hardware, :dependent => :destroy, :foreign_key => :switch_id, :inverse_of => :physical_switch has_many :physical_network_ports, :dependent => :destroy, :foreign_key => :switch_id + has_many :connected_components, :through => :physical_network_ports, :source => :connected_physical_component + def my_zone ems = ext_management_system ems ? ems.my_zone : MiqServer.my_zone