netbox-netprod-importer icon indicating copy to clipboard operation
netbox-netprod-importer copied to clipboard

Various Fixes and Updates for newer NetBox Versions

Open nahun opened this issue 3 years ago • 19 comments

This PR is a little big (sorry about that), but I'll summarize the changes.

  • Uses OPTIONS to lookup choices. Requires https://github.com/scaleway/python-netboxapi/pull/9 to be merged.
  • Ignores IPv6 link local address which is anything in fe80::/10.
  • Will only send a PUT request for interfaces and devices when something is going to change.
  • Get all interfaces on a device first and create a map to lookup later. This allows just one bigger request vs many small ones.
  • Does not change the interface type to Other of an existing interface unless overwrite is specified.
  • Fixes IP assignment to the newer model with later NetBox versions (assigned_object_id and assigned_object_type).
  • QSFP interface type fixes.
  • Fixes VLAN tagged list processing.
  • Adds Loopback interface as a Virtual type.
  • Adds detailed LLDP neighbors method to Cisco IOS.

I haven't really looked at the testing. Mostly tested on newer Cisco Cat9Ks.

Fixes #39

nahun avatar May 28 '21 00:05 nahun

I'm not sure if my QSFP changes are correct, but it seems good for Cisco IOS at least. I know the testing is failing for Cisco Nexus though. Probably need to add some testing for QSFP28 100G interfaces.

nahun avatar May 28 '21 01:05 nahun

Hey, Thanks a lot for this PR! I'm not working at Scaleway anymore (that's why I transferred them the ownership of these 2 repos), but I can still do some review.

It'll be however complicated for me to test it, but on the other hand, this tool doesn't work with the recent versions of Netbox, and that for a while, so I won't be picky. If anyone at @scaleway wants to test it, it would help, but otherwise I'll merge if things look ok.

Anyway, I already had a quick look, I'm going to do a review tomorrow. Overall it looks good! There's one thing I thought about the Options. Maybe it can be integrated into the mappers a bit better (in netbox-api) so they handle the caching, and you wouldn't have to bother caring about it here. But your current solution is good enough and it's something that can be added later if there's some interests on it.

aruhier avatar May 28 '21 01:05 aruhier

Hi,

ERROR: netbox_importer: Error when polling device xx-xx--xx: Unexpected format in the OPTIONS response at dcim/

How can we help out?

Best,

I4Networks

i4networks avatar May 28 '21 12:05 i4networks

@i4networks: thanks for the testing. Can you run it again in debug mode so you could paste the OPTIONS request?

aruhier avatar May 28 '21 13:05 aruhier

@aruhier what parameter do u use for debug?

i4networks avatar May 28 '21 14:05 i4networks

--verbose debug should do the trick. It'll be very verbose but normally requests should print you every http requests it's doing.

aruhier avatar May 28 '21 14:05 aruhier

@aruhier ...... switch1# DEBUG: netbox_importer: Interface VRF_0_vlan1015 has IP but was not listed DEBUG: urllib3.connectionpool: Starting new HTTP connection (1): localhost:8001 DEBUG: urllib3.connectionpool: http://localhost:8001 "GET /api/dcim/devices/?name=switch1&limit=50 HTTP/1.1" 200 1772 DEBUG: urllib3.connectionpool: Resetting dropped connection: localhost DEBUG: urllib3.connectionpool: http://localhost:8001 "GET /api/dcim/interfaces/?device_id=31&limit=50 HTTP/1.1" 200 43113 DEBUG: urllib3.connectionpool: Resetting dropped connection: localhost DEBUG: urllib3.connectionpool: http://localhost:8001 "GET /api/dcim/interfaces/?device_id=31&limit=50&offset=50 HTTP/1.1" 200 42974 DEBUG: urllib3.connectionpool: Resetting dropped connection: localhost DEBUG: urllib3.connectionpool: http://localhost:8001 "GET /api/dcim/interfaces/?device_id=31&limit=50&offset=100 HTTP/1.1" 200 42927 DEBUG: urllib3.connectionpool: Resetting dropped connection: localhost DEBUG: urllib3.connectionpool: http://localhost:8001 "GET /api/dcim/interfaces/?device_id=31&limit=50&offset=150 HTTP/1.1" 200 41119 DEBUG: urllib3.connectionpool: Resetting dropped connection: localhost DEBUG: urllib3.connectionpool: http://localhost:8001 "GET /api/dcim/interfaces/?device_id=31&limit=50&offset=200 HTTP/1.1" 200 40691 DEBUG: urllib3.connectionpool: Resetting dropped connection: localhost DEBUG: urllib3.connectionpool: http://localhost:8001 "GET /api/dcim/interfaces/?device_id=31&limit=50&offset=250 HTTP/1.1" 200 40749 DEBUG: urllib3.connectionpool: Resetting dropped connection: localhost DEBUG: urllib3.connectionpool: http://localhost:8001 "GET /api/dcim/interfaces/?device_id=31&limit=50&offset=300 HTTP/1.1" 200 8231 DEBUG: urllib3.connectionpool: Resetting dropped connection: localhost DEBUG: urllib3.connectionpool: http://localhost:8001 "OPTIONS /api/dcim/ HTTP/1.1" 200 181 DEBUG: netmiko: write_channel: b'\n' DEBUG: netmiko: read_channel: i4n-cr1-ahm-dp# DEBUG: netmiko: read_channel: DEBUG: netmiko: read_channel: DEBUG: netmiko: write_channel: b'exit\n' ERROR: netbox_importer: Error when polling device switch1: Unexpected format in the OPTIONS response at dcim/ 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:57<00:00, 57.62s/it] [root@nms netbox-netprod-importer]#

i4networks avatar May 28 '21 15:05 i4networks

I don't get why it tries to do a query on api/dcim. @nahun can you investigate this issue? I will also try to do the same later on my side.

aruhier avatar May 28 '21 15:05 aruhier

Interesting, I can't find any reason that would be happening.

@i4networks, can you post more information like your config.yml and devices.yml?

I thought maybe it was due to not using the latest changes in netboxapi, but it would throw a straight python exception about no options() method in the mapper if that was the case.

The only call to options() is in the _NetboxPusher.search_value_in_choices() method and it seems fine. Doesn't seem possible that it wouldn't use the model correctly for the route in netboxapi.

nahun avatar Jun 01 '21 03:06 nahun

@i4networks: Any news about the bug you encountered?

aruhier avatar Jun 04 '21 13:06 aruhier

Hi @aruhier ,

Sorry for the late response. I tried both Cisco and Juniper MX with a fairly simple yaml.

test.yml netboxhostname: driver: ios

config.yml cat config.yml ########################

Global options

########################

Be more verbose

verbose: None

Disable ssl warnings in urllib3

disable_ssl_warnings: False


################

Netbox

################

netbox:

Netbox API URL

url: "http://localhost:8001/api"

username: "user"

password: "password"

or to use a token instead

token: "letsnotleakthetokenongithub"

##########################

Interconnections

##########################

On some devices, LLDP will expose the host FQDN. If devices are stored on

Netbox only by their hostname, the interconnection process will not be able

to find them. Fill this list to strip the domain name from exposed names.

remove_domains:

  • "foo.tld"
  • "bar.tld"

vim: set ts=2 sw=2:


netbox version v2.11.4 Python 2.7.5

i4networks avatar Jun 05 '21 10:06 i4networks

@i4networks, it happens on both Cisco and Juniper devices if you try one at a time? I don't have a Juniper device to test with unfortunately.

nahun avatar Jun 08 '21 23:06 nahun

@nahun i tested with only one device at the time in the test.yml

i4networks avatar Jun 11 '21 11:06 i4networks

I can't reproduce that error. You'll need to be very specific on how you're able to reproduce.

Versions of everything like Python & Python packages (use pip freeze). Confirm using the latest netboxapi from the master branch.

Config and device files

Model of each device and what version they're running.

Provide anything else that might be useful.

nahun avatar Jun 23 '21 21:06 nahun

Lets not block this PR for too long, now this project is not working anymore for a lot of people anyway. I'm doing the review right now.

aruhier avatar Jun 23 '21 21:06 aruhier

Hi,

ERROR: netbox_importer: Error when polling device xx-xx--xx: Unexpected format in the OPTIONS response at dcim/

How can we help out?

Best,

I4Networks

This is due to the fact that the latest changes to the library https://github.com/scaleway/python-netboxapi are not published in the pip repository. Delete the system one and install it from github.

VictorPavlushin avatar Sep 20 '21 12:09 VictorPavlushin

Hi, ERROR: netbox_importer: Error when polling device xx-xx--xx: Unexpected format in the OPTIONS response at dcim/ How can we help out? Best, I4Networks

This is due to the fact that the latest changes to the library https://github.com/scaleway/python-netboxapi are not published in the pip repository. Delete the system one and install it from github.

pip uninstall netboxapi python -m pip install git+https://github.com/scaleway/python-netboxapi.git

fixed the issue.

i4networks avatar Nov 27 '21 17:11 i4networks

I have the same problem

pip install git+https://github.com/scaleway/python-netboxapi.git

it didn't work for me, now it tells me:

ERROR: netbox_importer: Error when polling device xxx.xxx.xxx: 404 Client Error: Not Found for url: https://test-domain.com/api/dcim/_choices/?limit=50 -

any ideas?

brianpr avatar Dec 03 '21 19:12 brianpr

I have the same problem

pip install git+https://github.com/scaleway/python-netboxapi.git

it didn't work for me, now it tells me:

ERROR: netbox_importer: Error when polling device xxx.xxx.xxx: 404 Client Error: Not Found for url: https://test-domain.com/api/dcim/_choices/?limit=50 -

any ideas?

use this branch with commits: https://github.com/nahun/netbox-netprod-importer/pull/1

VictorPavlushin avatar Dec 04 '21 08:12 VictorPavlushin

So, what happened here? Why did these fixes not get merged? This project is broken and dead. Worthless to anyone.

@nahun How do I pull this fixed code base, it looks like you deleted it?

appleoddity avatar Sep 01 '23 13:09 appleoddity