pynetbox - finding the manufacturer

383 views
Skip to first unread message

Dave Noonan

unread,
Feb 8, 2018, 9:21:57 AM2/8/18
to NetBox
I'm using pynet to pull all active devices...

nb_conn.dcim.devices.filter(status=1)

...and then I loop through the device pulling out some info. 

I was pulling the manufacturer with this...

dev['make'] = x._full_cache[14][1]['manufacturer']['name']

That worked on NetBox 2.2.4 (?) but on 2.2.8 it seems that the order of the list in _full_cache is random so sometimes 14 is correct but sometimes it's 1 and sometimes it's 8, etc.

What is the correct way that I should be pulling the manufacturer?

Thank you

Dave Noonan

unread,
Feb 8, 2018, 9:24:39 AM2/8/18
to NetBox
Also adding that when that worked I was on Python 2.7.13 and when it didn't work I was on 3.4.5 so possibly some variation in Python.

Regardless, I'm pretty sure drilling into _full_cache isn't the optimum way to pull that info.

Jacob Mansfield

unread,
Feb 8, 2018, 9:53:42 AM2/8/18
to Dave Noonan, NetBox
Assuming x is your Device object, then you get get a Manufacturer object with

x.device_type.manufacturer

or just get the name string directly with

x.device_type.manufacturer.name


Regards,
Jacob Mansfield
www.jacobmansfield.co.uk
@KingCyberJacob
> --
> You received this message because you are subscribed to the Google Groups
> "NetBox" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to netbox-discus...@googlegroups.com.
> To post to this group, send email to netbox-...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/netbox-discuss/939dac0e-0803-4213-94e5-fe9c0e13425c%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Dave Noonan

unread,
Feb 8, 2018, 11:05:45 AM2/8/18
to NetBox
It works!  Thank you!

Now if you're feeling really helpful can you give me a clue as to how you knew that?  I didn't find docs of the structure that pynetbox returned so was trying vars(), dir(), etc and none of that was working ("module error not callable" and similar messages).

And again, thank you.
Reply all
Reply to author
Forward
0 new messages