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 10, 2018
1 parent 85b25a1 commit 8190a91
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/models/physical_network_port.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
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
18 changes: 18 additions & 0 deletions app/models/physical_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,22 @@ 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] - a list of connected switches, and if it isn't connected to any, returns a empty list
#
def switches
switches = []

guest_devices.each do |device|
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 8190a91

Please sign in to comment.