Skip to content

Commit

Permalink
Adding connection b/w physical servers and switches
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasgabriel committed May 11, 2018
1 parent 85b25a1 commit 7678a32
Show file tree
Hide file tree
Showing 2 changed files with 34 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
@@ -1,4 +1,18 @@
class PhysicalNetworkPort < ApplicationRecord
belongs_to :guest_device
belongs_to :physical_switch

#
# Get the peer port connected.
# A connected port has the mac address of the pair in its
# peer_mac_address field.
#
# @return [PhysicalNetworkPort] - the connected port
#
def connected_port
port = PhysicalNetworkPort.find_by('peer_mac_address IS NOT NULL AND peer_mac_address = ?', mac_address)
port = PhysicalNetworkPort.find_by('mac_address IS NOT NULL AND mac_address = ?', peer_mac_address) if port.blank?

port
end
end
20 changes: 20 additions & 0 deletions app/models/physical_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,24 @@ def v_availability
def v_host_os
host.try(:vmm_product).nil? ? N_("") : host.vmm_product
end

#
# Searches the switches that are connected to the physical server
# it evaluates the server physical network ports that are
# connected with switch physical network ports
#
# @returns [Array<PhysicalSwitch>] - a list of connected switches,
# and if it isn't connected to any, returns an empty list.
#
def switches
switches = []

hardware.nics&.each do |network_device|
network_device.physical_network_ports&.each do |port|
switches << PhysicalSwitch.find(port.connected_port.switch_id) if port.connected_port.try(:switch_id).present?
end
end

switches
end
end

0 comments on commit 7678a32

Please sign in to comment.