Skip to content

Commit

Permalink
Save Physical Storage Model
Browse files Browse the repository at this point in the history
  • Loading branch information
EsdrasVP committed May 8, 2018
1 parent fd76353 commit 127620a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
17 changes: 16 additions & 1 deletion app/models/ems_refresh/save_inventory_physical_infra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# - ems
# - physical_racks
# - physical_chassis
# - physical_storages
# - physical_servers
# - physical_switches
#
Expand All @@ -24,7 +25,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_chassis physical_servers physical_switches customization_scripts)
child_keys = %i(physical_racks physical_chassis physical_storages physical_servers physical_switches customization_scripts)

# Save and link other subsections
save_child_inventory(ems, hashes, child_keys, target)
Expand Down Expand Up @@ -91,6 +92,20 @@ def save_physical_chassis_inventory(ems, hashes, target = nil)
store_ids_for_new_records(ems.physical_chassis, hashes, :ems_ref)
end

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

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

hashes.each do |h|
h[:physical_rack_id] = h.delete(:physical_rack).try(:[], :id)
end

child_keys = %i(computer_system asset_detail)
save_inventory_multi(ems.physical_storages, hashes, deletes, [:ems_ref], child_keys)
store_ids_for_new_records(ems.physical_storages, hashes, :ems_ref)
end

#
# Saves asset details information of a resource
#
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 @@ -67,6 +67,7 @@ def self.api_allowed_attributes
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_chassis, :foreign_key => "ems_id", :dependent => :destroy, :inverse_of => :ext_management_system
has_many :physical_storages, :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/manageiq/providers/physical_infra_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class PhysicalInfraManager < BaseManager
virtual_total :total_physical_switches, :physical_switches
virtual_total :total_physical_chassis, :physical_chassis
virtual_total :total_physical_servers, :physical_servers
virtual_total :total_physical_storages, :physical_storages
virtual_column :total_hosts, :type => :integer
virtual_column :total_vms, :type => :integer

Expand Down
1 change: 1 addition & 0 deletions app/models/physical_rack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ class PhysicalRack < ApplicationRecord

has_many :physical_chassis, :dependent => :nullify, :inverse_of => :physical_rack
has_many :physical_servers, :dependent => :nullify, :inverse_of => :physical_rack
has_many :physical_storages, :dependent => :nullify, :inverse_of => :physical_rack
end
9 changes: 9 additions & 0 deletions app/models/physical_storage.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class PhysicalStorage < ApplicationRecord
belongs_to :ext_management_system, :foreign_key => :ems_id, :inverse_of => :physical_storages
belongs_to :physical_rack, :foreign_key => :physical_rack_id, :inverse_of => :physical_storages

has_one :computer_system, :as => :managed_entity, :dependent => :destroy, :inverse_of => false
has_one :hardware, :through => :computer_system
has_one :asset_detail, :as => :resource, :dependent => :destroy, :inverse_of => false
has_many :guest_devices, :through => :hardware
end

0 comments on commit 127620a

Please sign in to comment.