Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save Physical Storage Model #17380

Merged
merged 1 commit into from
Jun 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Save Physical Storage Model
  • Loading branch information
EsdrasVP committed Jun 4, 2018
commit dd555a9edd9f1f4c865ccececf311e0543413e71
16 changes: 15 additions & 1 deletion app/models/ems_refresh/save_inventory_physical_infra.rb
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
# - ems
# - physical_racks
# - physical_chassis
# - physical_storages
# - physical_servers
# - physical_switches
#
@@ -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)
@@ -91,6 +92,19 @@ 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here there is no ems.physical_storages yet

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it, now it should work.

store_ids_for_new_records(ems.physical_storages, hashes, :ems_ref)
end

#
# Saves asset details information of a resource
#
2 changes: 2 additions & 0 deletions app/models/manageiq/providers/physical_infra_manager.rb
Original file line number Diff line number Diff line change
@@ -6,11 +6,13 @@ class PhysicalInfraManager < BaseManager
has_many :physical_racks, :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 :physical_switches, :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

virtual_total :total_physical_chassis, :physical_chassis
virtual_total :total_physical_racks, :physical_racks
virtual_total :total_physical_servers, :physical_servers
virtual_total :total_physical_switches, :physical_switches
virtual_total :total_physical_storages, :physical_storages

virtual_column :total_hosts, :type => :integer
virtual_column :total_vms, :type => :integer
11 changes: 11 additions & 0 deletions app/models/physical_storage.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class PhysicalStorage < ApplicationRecord
belongs_to :ext_management_system, :foreign_key => :ems_id, :inverse_of => :physical_storages,
:class_name => "ManageIQ::Providers::PhysicalInfraManager"

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