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 Apr 5, 2018
1 parent f66dac0 commit 61fb508
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/models/ems_refresh/save_inventory_physical_infra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Calling order for EmsPhysicalInfra:
# - ems
# - physical_racks
# - physical_switches
# - physical_servers
#

Expand All @@ -22,7 +23,7 @@ def save_ems_physical_infra_inventory(ems, hashes, target = nil)
_log.debug("#{log_header} hashes:\n#{YAML.dump(hashes)}")
end

child_keys = %i(physical_racks physical_servers customization_scripts)
child_keys = %i(physical_racks physical_switches physical_servers customization_scripts)

# Save and link other subsections
save_child_inventory(ems, hashes, child_keys, target)
Expand All @@ -44,6 +45,14 @@ def save_physical_racks_inventory(ems, hashes, target = nil)
store_ids_for_new_records(ems.physical_racks, hashes, :ems_ref)
end

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

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

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_racks, :physical_racks
virtual_total :total_switches, :physical_switches
virtual_total :total_physical_servers, :physical_servers
virtual_column :total_hosts, :type => :integer
virtual_column :total_vms, :type => :integer
Expand Down
6 changes: 6 additions & 0 deletions app/models/physical_switch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class PhysicalSwitch < Switch
has_one :asset_detail, :as => :resource, :dependent => :destroy, :inverse_of => :resource
has_one :hardware, :dependent => :destroy, :foreign_key => :switch_id

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 61fb508

Please sign in to comment.