So previously we were able to connect to a singular device by reading in data
from an external file, a YAML file,
and we passed that information to a netmeco and ultimately sent a show command.
Let's now build out that external file to include more files rather, more
devices.
And ultimately let's connect to more devices at once to really enjoy the
benefits of automation.
So the first thing I will do is go to my inventory file, in fact what I will do
here.
Let me just copy this over, I will just call this one new inventory. YAML, okay WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Let me just copy this over, I will just call this one new inventory. YAML, okay
, so let's open this one up.
Okay, so here's the big difference. Let's actually change this name to be
plural, not that it has any effect,
but it is a little bit more descriptive given the fact that we are going to be
dealing with multiple different devices.
And what I want to do here is I want to use a hyphen to denote that I have got
multiple different entries, okay.
So let me just indent the rest of this, and pretty much all I am going to do is
copy this right here.
And I am just going to paste this in, and then paste it in, and then paste it
in one more time.
Okay, so I have now got four entries. All I am going to do now though is change WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Okay, so I have now got four entries. All I am going to do now though is change
the IP address of these.
So I have got 102, 103 as well as 104, okay.
So now essentially let me just zoom out a little bit.
This is our file which ultimately defines four different devices in fact to
make it a little bit easier.
Let me just do some spacing, okay, just so it is a little bit cleaner.
There we go right there. Okay, so let's save this.
And now we have our new inventory.YML file. So what I will do here is I will
copy over example 4.py,
and I will create a new one called example 5.py, and I will do the
modifications necessary. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
modifications necessary.
So let's open you up, go into example 5.py.
The right now is it stands, let me just comment this out.
So that way we are not actually executing.
And all I am going to do is I am going to load my file in, although this time
the file is going to be new on the score inventory,
which has got the additional details.
And this time here the key as you remember is not going to be device.
We changed it to be devices just to be a little bit clearer.
So it will just change this right here.
And again similarly just to make things a little bit more descriptive. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Let's use a better name and use the plural here for devices.
So ultimately if I just print out the devices variable right here.
And I say Python 3 example 5.py right now.
As we can see here I am getting access to all of this new connection
information.
Basically the connection details for all four of my devices.
Now here is the thing.
What I want to do is I want to essentially loop through each of the devices
that I have access to right here.
So if I just say for device and the devices object I have right here.
And if I just print out that device, save this. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
And if I just print out that device, save this.
If I clear this green and run the script.
What we are actually getting here is the first dictionary with all the
connection details.
Then we print out the second dictionary with all the connection details.
Then the third and then lastly the fourth.
Now what I want to do is as opposed to printing them out to one by one.
I want to pass them in one by one into the connection handle just as we saw
before.
So here's what I am going to do.
I am going to get rid of this print statement.
So let me just uncomment this piece of code right here.
There we go. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
And what I will do is I will just cut this.
And I am just going to move it inside the follow up right here.
So let's paste this in.
In fact let me just fix the indentation for this part here.
As well as this.
So the big difference here though.
So we are doing the same thing as before.
I will be loading a different file.
This ultimately gives us access to our device information.
And this top level key now contains the information for multiple devices.
And we are saving this into a variable.
And all we are doing is looping through that variable.
And passing in the information that we loop through every single time into NITN WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
And passing in the information that we loop through every single time into NITN
IKO's
KNET handler and then sending that show command to all of the devices one by
one.
So if I save this here and I try rerunning the script, let's hit enter.
There is device one, now device two, then device three, and then finally device
four comes through also.
So now we are able to use NITNIKO to ultimately send show command to multiple
devices utilizing Python loops.
Let's now see how we can use NITNIKO to ultimately send configuration changes
to those devices.