Skip to content

Commit

Permalink
Merge pull request #7 from jasonyates/main
Browse files Browse the repository at this point in the history
  • Loading branch information
goebelmeier committed Nov 9, 2021
2 parents 42b537c + 43c9623 commit d027de4
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions netbox_cisco_support/management/commands/sync_eox_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from django.core.exceptions import MultipleObjectsReturned
from datetime import datetime
from requests import api
from dcim.models import Manufacturer
Expand All @@ -28,7 +29,13 @@ def update_device_eox_data(self, device):
self.stdout.write(self.style.SUCCESS("Trying to update device %s" % device['sr_no']))

# Get the device object from NetBox
d = Device.objects.get(serial=device['sr_no'])
try:
d = Device.objects.get(serial=device['sr_no'])
except MultipleObjectsReturned:

# Error if netbox has multiple SN's and skip updating
self.stdout.write(self.style.NOTICE("ERROR: Multiple objects exist within Netbox with Serial Number " + device['sr_no']))
return

# Check if a CiscoSupport object already exists, if not, create a new one
try:
Expand Down Expand Up @@ -83,8 +90,16 @@ def update_device_eox_data(self, device):
return

def update_device_type_eox_data(self, pid, eox_data):
# Get the device type object for the supplied PID
dt = DeviceType.objects.get(part_number=pid)

try:
# Get the device type object for the supplied PID
dt = DeviceType.objects.get(part_number=pid)

except MultipleObjectsReturned:

# Error if netbox has multiple PN's
self.stdout.write(self.style.NOTICE("ERROR: Multiple objects exist within Netbox with Part Number " + pid))
return

# Check if CiscoDeviceTypeSupport record already exists
try:
Expand Down

0 comments on commit d027de4

Please sign in to comment.