Skip to content

Commit

Permalink
add new PhysicalRack model
Browse files Browse the repository at this point in the history
  • Loading branch information
felipedf committed Feb 19, 2018
1 parent fb9e78a commit f1f44c4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 15 deletions.
31 changes: 16 additions & 15 deletions app/models/ems_refresh/save_inventory_physical_infra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Calling order for EmsPhysicalInfra:
# - ems
# - physical_servers
# - physical_racks
# - physical_servers
#

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

child_keys = [
:physical_servers,
:customization_scripts
]
child_keys = %i(physical_servers physical_racks customization_scripts)

# Save and link other subsections
save_child_inventory(ems, hashes, child_keys, target)
Expand All @@ -37,17 +36,23 @@ def save_ems_physical_infra_inventory(ems, hashes, target = nil)
ems
end

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

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

ems.physical_racks.reset
save_inventory_multi(ems.physical_racks, hashes, deletes, [:uid_ems], [:physical_servers])
end

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

ems.physical_servers.reset
deletes = if target == ems
:use_association
else
[]
end
deletes = target == ems ? :use_association : []

child_keys = %i(computer_system asset_detail hosts)

child_keys = [:computer_system, :asset_detail, :hosts]
save_inventory_multi(ems.physical_servers, hashes, deletes, [:ems_ref], child_keys)
store_ids_for_new_records(ems.physical_servers, hashes, :ems_ref)
end
Expand All @@ -56,11 +61,7 @@ def save_customization_scripts_inventory(ems, hashes, target = nil)
target = ems if target.nil?

ems.customization_scripts.reset
deletes = if target == ems
:use_association
else
[]
end
deletes = target == ems ? :use_association : []

save_inventory_multi(ems.customization_scripts, hashes, deletes, [:manager_ref])
store_ids_for_new_records(ems.customization_scripts, hashes, :manager_ref)
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 @@ -64,6 +64,7 @@ def self.api_allowed_attributes
has_many :resource_pools, :foreign_key => "ems_id", :dependent => :destroy, :inverse_of => :ext_management_system
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_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 @@ -2,6 +2,7 @@ module ManageIQ::Providers
class PhysicalInfraManager < BaseManager
include SupportsFeatureMixin

virtual_total :total_physical_racks, :physical_racks
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_rack.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class PhysicalRack < ApplicationRecord
belongs_to :ext_management_system, :foreign_key => :ems_id,
:class_name => "ManageIQ::Providers::PhysicalInfraManager", :inverse_of => :physical_racks

has_many :physical_servers, :dependent => :destroy, :inverse_of => :physical_rack
end
1 change: 1 addition & 0 deletions app/models/physical_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class PhysicalServer < ApplicationRecord

validates :vendor, :inclusion =>{:in => VENDOR_TYPES}
belongs_to :ext_management_system, :foreign_key => :ems_id, :class_name => "ManageIQ::Providers::PhysicalInfraManager"
belongs_to :physical_rack

has_one :computer_system, :as => :managed_entity, :dependent => :destroy
has_one :hardware, :through => :computer_system
Expand Down
3 changes: 3 additions & 0 deletions spec/factories/physical_rack.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FactoryGirl.define do
factory :physical_rack
end

0 comments on commit f1f44c4

Please sign in to comment.