Okay.
So I'm tired of using Python on the box now.
What I'm going to do is start an Ubuntu VM on my local mac.
Now I'm using Linux.
I strongly suggest just like Python that you learn Linux.
Linux is one of those core skills.
You're going to use it everywhere, so make sure that you learn Linux.
So here I'm going to open up a terminal.
This is on my local computer.
It's not in.
This is local.
And what I'm going to do is install python three and net mico.
Basically what we're doing is we installing Python three on the Ubuntu PC and we installing net MICO,
which is a great way to connect to network devices.
Rather than you writing all the low level code to SSH to a network device and then send commands to
a network device and then interpret the output.
Net Mico is your first step in automation because the developer of Net Mika has done a lot of the hard
work already and you can just leverage that code in your Python scripts.
One of the advantages of Python is there are a whole bunch of libraries available, including Net MICO,
including apps, including Narnia that make our lives as network engineers a lot simpler.
Don't reinvent the wheel, use the code and the hard work that others have done, and import those libraries
into your code and just leverage them.
Don't reinvent the wheel.
Now I've already installed these commands on my Ubuntu PC, but I'll paste them here just to show you
the process.
So sudo apt install python three.
Pip basically allows me to install python three on the ubuntu computer.
And then I'm going to install net mico.
Once again, I have previously installed the software, so it should all be good.
Just in case you want to know what release I'm using, I'm using ubuntu.
18.
04.3 ELTs.
So this command LSB released a shows me the version of a Punto that I'm using, so I'm just using one
of the later releases of Ubuntu.
So I'll clear the screen.
And now let's create a script.
So here's my script.
I'm going to copy it into that Ubuntu computer and then I'll show you how to use it.
I'm going to create a script called Python one point p.
Not a good name, but it's okay for this demonstration and I'm going to paste that code in.
This is importing the library net MICO So I'm going to basically leverage the power of net mico to connect
to my Nexus device.
Here's the username, here's the password, here's the port.
Now I know a lot of people are going to complain, so I'll just say it right now.
You don't have to store the credentials in your script.
You could prompt for them if you wanted to.
I'm just going to store it yet to keep it simple.
It's a lab anyway, so it doesn't matter.
I just want to show you how simple it is to extract information from a remote router.
This route is running probably in the States somewhere.
I don't know.
It's hosted by Dev Net and I'm going to pull back the show IP interface, brief output and display it
on my computer.
So.
This is an example of a dictionary in Python.
Notice the formatting.
Does that look familiar?
Hopefully that looks familiar, but it's a little bit different here to JSON because in JSON formatting,
we don't use single inverted commas.
Basically, this is a dictionary storing the information that we need to connect to the router.
This command allows me to connect to the router and then this allows me to send a command to the router.
In this case, show IP interface brief.
We store that in a variable and then we print the results out.
So I'll save that script.
I'm going to use Python three to run that script.
Okay, I'm getting an error.
And this is one of the things you need to be careful with using PowerPoint.
Notice the difference between that and this.
Don't use PowerPoint.
Use a text editor.
I typically use sublime text or Visual Studio code.
Notice that's gone green now, so that looks better.
I'll save that script.
Python three.
Python one.
P y script seems to be working now.
So this is a switching to that device and then running the command and then hopefully we'll display
the output.
And there you go.
We can see the output on that remote nexus device on my ubuntu computer.
On the succession to the nexus show ip interface brief.
There's the output of my direct ssh session.
And here's the output using my python script.
Okay.
So once again, I could simply type python three, Python one at P.
Why?
Python three means I'm using Python three.
Python one is the name of my script and I can see the output.
It's as simple as that to retrieve that data from that Nexus device.
But let's try and do something more intelligent with the data.