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 6, 2018
1 parent ce34861 commit 576ced0
Show file tree
Hide file tree
Showing 6 changed files with 20 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/ext_management_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def self.api_allowed_attributes
has_many :customization_specs, :foreign_key => "ems_id", :dependent => :destroy, :inverse_of => :ext_management_system
has_many :storage_profiles, :foreign_key => "ems_id", :dependent => :destroy, :inverse_of => :ext_management_system
has_many :physical_racks, :foreign_key => "ems_id", :dependent => :destroy, :inverse_of => :ext_management_system
has_many :physical_switches, :foreign_key => "ems_id", :dependent => :destroy, :inverse_of => :ext_management_system
has_many :physical_servers, :foreign_key => "ems_id", :dependent => :destroy, :inverse_of => :ext_management_system
has_many :customization_scripts, :foreign_key => "manager_id", :dependent => :destroy, :inverse_of => :ext_management_system

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, :foreign_key => :switch_id, :inverse_of => :hardware

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

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, :inverse_of => :physical_switch

belongs_to :ext_management_system, :foreign_key => :ems_id, :inverse_of => :physical_switches
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 576ced0

Please sign in to comment.