Przemek

Przemek

@ttl255
47 posts

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 »

Regular expressions for Network Engineers - basics

What? Who needs regular expressions in the age of automation? I do! And maybe you need them too. Personally I think that there are times when regular expressions are the right tool for the job. They have been around for a while and they are still a very useful aid that can be used to solve many problems in the network engineering space. Need to quickly find where ACL is applied, or which config has got the specific IP in it? How about quickly audit config files for the missing configuration line? Regex to the rescue! Contents Introduction Basic syntax...

Continue reading »

NAPALM-Ansible - Automatic validation - part 2

This is the second post in the series on Napalm validation in which we will explore more options available to us for writing validation tests. First part can be found here: NAPALM-Ansible - Automatic validation - part 1. First we'll make amendments to YAML files we used to describe desired LLDP state and see how it affects validation results. After that we'll introduce two more examples, one for checking BGP peerings, and one for verifying reported interfaces. Contents Partial string matching and regex BGP peering validation example Strict mode and 'list' key Listings of Playbooks GitHub repository with resources for...

Continue reading »