Przemek

Przemek

@ttl255
29 posts

Pynetbox - NetBox Python API client part 3 - updates and deletions

Time for another post in the series on Pynetbox, awesome PythonAPI client for NetBox. In part 1 we learned how to retrieve information from NetBox, and how to work with objects returned by Pynetbox. In part 2 we've gone through object creation, where we learned how to check what fields are required and how to fill them to make NetBox happy. In this post we will talk about updating existing objects and deleting objects we no longer need. Unlike first two posts this one will be much shorter but should be no less exciting! Posts in the Pynetbox series: Pynetbox...

Continue reading »

Pynetbox - NetBox Python API client part 2 - creating objects

Welcome to the second post in the series dedicated to Pynetbox, Python API client for NetBox. In this episode I'll be talking about object creation and we'll go through a few code examples showing how can we add stuff to NetBox. Expect some cool Python code and unexpected plot twists! Posts in the Pynetbox series: Pynetbox - NetBox Python API client part 1 - getting info Pynetbox - NetBox Python API client part 2 - creating objects Pynetbox - NetBox Python API client part 3 - updates and deletions Pynetbox - NetBox Python API client part 4 - tags and...

Continue reading »

Pynetbox - NetBox Python API client part 1 - getting info

NetBox is an open source IPAM/DCIM solution that came out of DigitalOcean. It's an excellent piece of software that is being actively developed and has very lively community. New features are being constantly added and I find it to be better than any of the commercial solutions available out there. If you never heard of it I strongly recommend having a look at the Github and Docs pages: https://github.com/digitalocean/netbox - NetBox Github repo https://netbox.readthedocs.io/en/stable/ - NetBox docs One of the great selling points of NetBox is well thought through and...

Continue reading »

PyTips 2 - Use itertools.product to replace nested loops

Nested loops, we all love them. Or do we? Five levels of indentation later you are not so sure. Your code starts to look ugly and you wish there was another way. Fortunately there is! One of the functions provided by itertools, product(), can replace your loops with a function call. So what is itertools.product? It's a function that takes a number of iterables and returns their Cartesian product, or in simpler terms, all ordered tuples with elements coming from each of the iterables. Product of [1, 2] and ['a', 'b', 'c'] would result in tuples: (1, 'a'), (1,...

Continue reading »

PyTips 1 - Get loop counter with enumerate()

In PyTips I'll be talking about Python features, standard libraries, and interesting packages found on PyPi. The idea is to have a short write up and accompanying code snippets for all Python things that I found useful and interesting. These will be mostly aimed at beginners, and I hope that you too, my reader, will find them helpful. Problem A common idiom while looping over collection is to use helper variable to store index of the element currently worked on. For example, we want to convert IP address from dotted-decimal to the decimal format: my_ip = '10.16.32.113'...

Continue reading »