Skip to content

Commit

Permalink
Fixes netbox-community#861: Avoid overwriting device primary IP assig…
Browse files Browse the repository at this point in the history
…nment from alternate family during bulk import of IP addresses
  • Loading branch information
jeremystretch committed Jan 31, 2017
1 parent 59a281e commit 1164df7
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions netbox/ipam/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,16 +635,14 @@ class IPAddressBulkImportView(PermissionRequiredMixin, BulkImportView):

def save_obj(self, obj):
obj.save()
# Update primary IP for device if needed

# Update primary IP for device if needed. The Device must be updated directly in the database; otherwise we risk
# overwriting a previous IP assignment from the same import (see #861).
try:
if obj.family == 4 and obj.primary_ip4_for:
device = obj.primary_ip4_for
device.primary_ip4 = obj
device.save()
Device.objects.filter(pk=obj.primary_ip4_for.pk).update(primary_ip4=obj)
elif obj.family == 6 and obj.primary_ip6_for:
device = obj.primary_ip6_for
device.primary_ip6 = obj
device.save()
Device.objects.filter(pk=obj.primary_ip6_for.pk).update(primary_ip6=obj)
except Device.DoesNotExist:
pass

Expand Down

0 comments on commit 1164df7

Please sign in to comment.