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

Disconnect inventory on targeted refresh #16718

Merged
merged 1 commit into from
Jan 2, 2018
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions app/models/ems_refresh/save_inventory_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,16 @@ def determine_deletes_using_association(ems, target, disconnect = true)
[]
end
end

def hashes_of_target_empty?(hashes, target)
hashes.blank? || (hashes[:storages].blank? &&
case target
when VmOrTemplate
hashes[:vms].blank?
when Host
hashes[:hosts].blank?
when EmsFolder
hashes[:folders].blank?
end)
end
end
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, disconnect = true)
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? && hashes[:folders].blank?)
if hashes_of_target_empty?(hashes, target)
target.disconnect_inv if disconnect
return
end
Expand Down