Skip to content

Commit

Permalink
Add folder creation to save_new_target
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Apr 24, 2017
1 parent 28e3e4d commit 82b1c04
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/models/ems_refresh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def self.refresh(target, id = nil)
def self.refresh_new_target(target_hash, ems_id)
ems = ExtManagementSystem.find(ems_id)

target = save_new_target(target_hash)
target = save_new_target(ems, target_hash)
if target.nil?
_log.warn "Unknown target for event data: #{target_hash}."
return
Expand Down
7 changes: 4 additions & 3 deletions app/models/ems_refresh/save_inventory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -354,15 +354,14 @@ def save_event_logs_inventory(os, hashes)
save_inventory_multi(os.event_logs, hashes, :use_association, [:uid])
end

def save_new_target(target_hash)
unless target_hash[:vm].nil?
def save_new_target(ems, target_hash)
if target_hash[:vm]
vm_hash = target_hash[:vm]
existing_vm = VmOrTemplate.find_by(:ems_ref => vm_hash[:ems_ref], :ems_id => target_hash[:ems_id])
unless existing_vm.nil?
return existing_vm
end

ems = ExtManagementSystem.find_by(:id => target_hash[:ems_id])
old_cluster = get_cluster(ems, target_hash[:cluster], target_hash[:resource_pools], target_hash[:folders])

vm_hash[:ems_cluster_id] = old_cluster[:id]
Expand All @@ -379,6 +378,8 @@ def save_new_target(target_hash)
resource_pool.save!

new_vm
elsif target_hash[:folder]
ems.ems_folders.create!(target_hash[:folder])
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/ems_refresh/save_inventory_infra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def save_ems_infra_inventory(ems, hashes, target = nil)
log_header = "EMS: [#{ems.name}], id: [#{ems.id}]"

# Check if the data coming in reflects a complete removal from the ems
if hashes.blank? || (hashes[:hosts].blank? && hashes[:vms].blank? && hashes[:storages].blank?)
if hashes.blank? || (hashes[:hosts].blank? && hashes[:vms].blank? && hashes[:storages].blank? && hashes[:folders].blank?)
target.disconnect_inv
return
end
Expand Down

0 comments on commit 82b1c04

Please sign in to comment.