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 8, 2018
1 parent 802d601 commit 234b64c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/models/ems_refresh/save_inventory_infra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.switches)

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

def remove_obsolete_switches
def remove_obsolete_switches(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
switch_ids = HostSwitch.all.collect(&:switch_id)
switches.where.not(:id => switch_ids).destroy_all
end

def save_lans_inventory(switch, hashes)
Expand Down

0 comments on commit 234b64c

Please sign in to comment.