Skip to content

Commit

Permalink
Connecting physical switch to computer systems
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasgabriel committed Jul 20, 2018
1 parent 3e58954 commit 53e402a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/models/physical_network_port.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions app/models/physical_switch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 53e402a

Please sign in to comment.