Skip to content

Commit

Permalink
Fix physical switches be removed after the refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlleDaniel committed Jun 11, 2018
1 parent 802d601 commit a3cd885
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions app/models/ems_refresh/save_inventory_infra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def save_ems_infra_inventory(ems, hashes, target = nil, disconnect = true)
:orchestration_templates,
:orchestration_stacks
]

old_switch_ids = ems.switches.pluck(:id)
# Save and link other subsections
save_child_inventory(ems, hashes, child_keys, target, disconnect)

Expand All @@ -78,7 +78,7 @@ def save_ems_infra_inventory(ems, hashes, target = nil, disconnect = true)

new_relats = hashes_relats(hashes)
link_ems_inventory(ems, target, prev_relats, new_relats, disconnect)
remove_obsolete_switches
remove_obsolete_switches(ems, old_switch_ids)

ems
end
Expand Down Expand Up @@ -331,10 +331,9 @@ def save_switches_inventory(host, hashes)
host.switches.delete(deletes)
end

def remove_obsolete_switches
# delete from switches as s where s.shared is NULL and s.id not in (select switch_id from host_switches)
# delete from switches as s where s.shared = 't' and s.id not in (select switch_id from host_switches)
Switch.where.not(:id => HostSwitch.all.collect(&:switch).uniq).destroy_all
def remove_obsolete_switches(ems, old_switch_ids)
obsolete_switch_ids = old_switch_ids - ems.switches.reload.pluck(:id)
Switch.where(:id => obsolete_switch_ids).destroy_all
end

def save_lans_inventory(switch, hashes)
Expand Down

0 comments on commit a3cd885

Please sign in to comment.