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 Jun 29, 2018
1 parent 8e109d6 commit af1e882
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/models/computer_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions app/models/guest_device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions app/models/hardware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion app/models/physical_network_port.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions app/models/physical_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit af1e882

Please sign in to comment.