robertcsapo / ciscodnacnetbox

Cisco DNA Center Integration with NetBox
Other
35 stars 16 forks source link

Device sync limited to 500. #15

Open shauntilyard opened 1 year ago

shauntilyard commented 1 year ago

Hello, I have DNAC/Netbox integrated but I am hitting a device sync limit I believe. I can only ever discover 500 devices? I can sync them all with no issues. Is there a limit coded somewhere?

robertcsapo commented 1 year ago

@shauntilyard this would require pagination support in the code.

https://github.com/robertcsapo/ciscodnacnetbox/blob/56de961ec5473548da0840a1459266d1d109d9e6/ciscodnacnetbox/ciscodnac/__init__.py#L65-L70 https://github.com/robertcsapo/ciscodnacnetbox/blob/56de961ec5473548da0840a1459266d1d109d9e6/ciscodnacnetbox/ciscodnac/data.py#L261-L262

Ref https://github.com/cisco-en-programmability/dnacentersdk/issues/70

fue36 commented 7 months ago

Bump, same issue here. No pagination is performed on device import.

fue36 commented 7 months ago

I just followed comment https://github.com/cisco-en-programmability/dnacentersdk/issues/70#issuecomment-1235744999 in the link robertcsapo referred to. I didn't use a debugger, or anything, just vim. Worked for me. Just in time for robertcsapo to merge in time for Cisco Live 2024. :)

My working dir was /opt/netbox/venv/lib/python3.9/site-packages/ciscodnacnetbox/ciscodnac. Restart netbox & netbox-rq after making the changes.

--- __init__.py.orig    2024-05-02 16:20:15.155869824 -0400
+++ __init__.py  2024-05-02 17:03:51.544401637 -0400
@@ -66,7 +66,16 @@
         """
         Get Devices from Cisco DNA Center
         """
-        return tenant.devices.get_device_list().response
+        max_items = 2 #Here goes API Limit elements per page.
+        devices = []
+        offset = 1
+        items = max_items
+        while items >= max_items:
+            devices_api = tenant.devices.get_device_list(offset=offset, limit = max_items)
+            devices.extend(devices_api.response)
+            offset += max_items
+            items = len(devices_api.response)
+        return devices

     def sites(self, tenant):
         """