From af1e882c95d14d848e8fa4869470b4274c7ec01d Mon Sep 17 00:00:00 2001 From: douglasgabriel Date: Wed, 30 May 2018 08:57:05 -0300 Subject: [PATCH] Adding connection b/w physical servers and switches --- app/models/computer_system.rb | 2 ++ app/models/guest_device.rb | 1 + app/models/hardware.rb | 1 + app/models/physical_network_port.rb | 5 ++++- app/models/physical_server.rb | 2 ++ 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/computer_system.rb b/app/models/computer_system.rb index 062d9bb3cbd..7f8ebc722d1 100644 --- a/app/models/computer_system.rb +++ b/app/models/computer_system.rb @@ -3,4 +3,6 @@ class ComputerSystem < ApplicationRecord has_one :operating_system, :dependent => :destroy has_one :hardware, :dependent => :destroy + + has_many :connected_physical_switches, :through => :hardware end diff --git a/app/models/guest_device.rb b/app/models/guest_device.rb index cd4791532a2..09db2943cc6 100644 --- a/app/models/guest_device.rb +++ b/app/models/guest_device.rb @@ -16,6 +16,7 @@ class GuestDevice < ApplicationRecord has_many :child_devices, -> { where(:parent_device_id => ids) }, :foreign_key => "parent_device_id", :class_name => "GuestDevice", :dependent => :destroy has_many :physical_network_ports, :dependent => :destroy + has_many :connected_physical_switches, :through => :physical_network_ports alias_attribute :name, :device_name diff --git a/app/models/hardware.rb b/app/models/hardware.rb index af0d5d155e4..4168d913ba8 100644 --- a/app/models/hardware.rb +++ b/app/models/hardware.rb @@ -22,6 +22,7 @@ class Hardware < ApplicationRecord has_many :nics, -> { where("device_type = 'ethernet'") }, :class_name => "GuestDevice", :foreign_key => :hardware_id has_many :ports, -> { where("device_type != 'storage'") }, :class_name => "GuestDevice", :foreign_key => :hardware_id has_many :physical_ports, -> { where("device_type = 'physical_port'") }, :class_name => "GuestDevice", :foreign_key => :hardware_id + has_many :connected_physical_switches, :through => :guest_devices virtual_column :ipaddresses, :type => :string_set, :uses => :networks virtual_column :hostnames, :type => :string_set, :uses => :networks diff --git a/app/models/physical_network_port.rb b/app/models/physical_network_port.rb index ab903f31ab4..0f3cf4ce399 100644 --- a/app/models/physical_network_port.rb +++ b/app/models/physical_network_port.rb @@ -1,4 +1,7 @@ class PhysicalNetworkPort < ApplicationRecord belongs_to :guest_device - belongs_to :physical_switch + 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 end diff --git a/app/models/physical_server.rb b/app/models/physical_server.rb index 7215caed0e7..ccbf8f7a3bf 100644 --- a/app/models/physical_server.rb +++ b/app/models/physical_server.rb @@ -33,6 +33,8 @@ class PhysicalServer < ApplicationRecord virtual_column :v_availability, :type => :string, :uses => :host virtual_column :v_host_os, :type => :string, :uses => :host + has_many :physical_switches, :through => :computer_system, :source => :connected_physical_switches + def name_with_details details % { :name => name,