python |


Network Automation Example - Finditer With Defaultdict

Submitted by zeroslash on Sat, 04/27/2019 - 01:40

In this example, I explored another approach to using Finditer to count network interfaces in my last post. I recommend you check that out first before going through this one.

Here I combined re.finditer() with defaultdict() instead, keeping the matched patterns associated with the keyword we are looking for.

Network Automation Example - Finditer With Counter

Submitted by zeroslash on Thu, 12/27/2018 - 11:10

Still using the same example data that I've been using in my previous Network Automation examples, this time around I try out a counting scenario.

In this example, I wanted a quick and easy way to just zip through the text and count how many interfaces of a certain type I will find.

I'm using the re.finditer() function to give me an iterable of all matches (line 16).

Copying Files Through SCP With Junos PyEZ

Submitted by zeroslash on Wed, 08/29/2018 - 15:52

Copying a file is one of the simplest tasks you can do with Junos PyEZ or with Junos in general. You typically do this for example when you are copying the text file for request support information before you submit it to support. Having said that, let's get right into an example of this using Junos PyEZ.

Network Automation Example - Generators With Filtering

Submitted by zeroslash on Tue, 05/15/2018 - 12:58

Following on from my last post, I made a variation of it. In this instance I wanted to filter the interfaces based on a certain amount of errors.

One thing I changed is I switched it up with a generator function instead (lines 11-14) and used that to provide the iterable sequence in the generator comprehension following that. The generator comprehension (lines 16-18) is where the filtering happens.

Network Automation Example - Namedtuple

Submitted by zeroslash on Wed, 05/09/2018 - 01:08

Let's say we just grabbed the list of interfaces from a router along with its error count. As you can see here I used namedtuples with a list comprehension (lines 13-14). Then I moved on to sort the data by error field and then provide some order with the name field as well, for errors with the same value (line 15). The output looks good. This type of approach seems enough for now but may change or improve given new scenarios to cover in the future. 

Testing SSH Key-based Authentication for Network Automation

Submitted by zeroslash on Fri, 03/23/2018 - 10:05

In my last post How To Configure SSH Key-based Authentication on Linux, I gave a walkthrough on how to set up SSH keys with an SSH agent so you get the benefits of passwordless logins while still maintaining the increased security that key-based authentication is supposed to provide. The reason why I reiterate this is because using SSH keys without passphrases pretty much defeats the purpose of using keys at all.

Installing Python 3 for Development in Centos 7 Step by Step

Submitted by zeroslash on Thu, 02/22/2018 - 12:56

Updated to Python 3.7.0 on Oct 12, 2018

In this setup, I'm using a vagrant machine but you don't necessarily need to do the same thing. Technically these procedures will apply to any computer running Centos 7. For the purpose of development, however, which is what this post is intended for, I highly recommend using vagrant. It makes working with development VMs so much easier.