Skip to content

Commit

Permalink
Adding switches support for physical infra
Browse files Browse the repository at this point in the history
  • Loading branch information
saulotoledo committed Mar 27, 2018
1 parent 2ead6ad commit c2e510c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/models/ems_refresh/save_inventory_physical_infra.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#
# Calling order for EmsPhysicalInfra:
# - ems
# - physical_switches
# - physical_servers
#

Expand All @@ -22,6 +23,7 @@ def save_ems_physical_infra_inventory(ems, hashes, target = nil)
end

child_keys = [
:physical_switches,
:physical_servers,
:customization_scripts
]
Expand All @@ -37,6 +39,15 @@ def save_ems_physical_infra_inventory(ems, hashes, target = nil)
ems
end

def save_physical_switches_inventory(ems, hashes, target = nil)
target = ems if target.nil?

deletes = target == ems ? :use_association : []

ems.physical_switches.reset
save_inventory_multi(ems.physical_switches, hashes, deletes, [:uid_ems], %i[asset_detail hardware])
end

def save_physical_servers_inventory(ems, hashes, target = nil)
target = ems if target.nil?

Expand Down
1 change: 1 addition & 0 deletions app/models/hardware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Hardware < ApplicationRecord
belongs_to :miq_template, :foreign_key => :vm_or_template_id
belongs_to :host
belongs_to :computer_system
belongs_to :physical_switch

has_many :networks, :dependent => :destroy
has_many :firmwares, :as => :resource, :dependent => :destroy
Expand Down
3 changes: 3 additions & 0 deletions app/models/manageiq/providers/physical_infra_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ module ManageIQ::Providers
class PhysicalInfraManager < BaseManager
include SupportsFeatureMixin

has_many :physical_switches, :foreign_key => "ems_id", :dependent => :destroy, :inverse_of => :ext_management_system

virtual_total :total_physical_servers, :physical_servers
virtual_total :total_switches, :physical_switches
virtual_column :total_hosts, :type => :integer
virtual_column :total_vms, :type => :integer

Expand Down
7 changes: 7 additions & 0 deletions app/models/physical_switch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class PhysicalSwitch < Switch
has_one :asset_detail, :as => :resource, :dependent => :destroy, :inverse_of => :resource
has_one :hardware, :dependent => :destroy

belongs_to :ext_management_system, :foreign_key => :ems_id, :inverse_of => :physical_switches,
:class_name => "ManageIQ::Providers::PhysicalInfraManager"
end
1 change: 1 addition & 0 deletions app/models/switch.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Switch < ApplicationRecord
include NewWithTypeStiMixin
include CustomActionsMixin

has_many :host_switches, :dependent => :destroy
Expand Down

0 comments on commit c2e510c

Please sign in to comment.