Junos PyEZ
Your step-by-step guide to installing Juniper’s Junos PyEZ.
Whether installed directly on a management server or in a virtual environment, Junos PyEZ lets you manage and automate devices running Junos OS. Learn how to set it up in this step-by-step demo from Juniper’s Gordon Mosley.
You’ll learn
How Junos PyEZ uses Python to enable you to manage and automate Junos devices
To install Junos PyEZ in a virtual environment or as a Docker container
How to use Junos PyEZ to connect to a Junos device and retrieve device facts
Who is this for?
Host
Transcript
00:00 [Music]
00:11 hello and welcome to the junos pi
00:13 easy learning bite i'm gordon mosley
00:16 with the education services department
00:18 at juniper networks
00:19 let's get started
00:22 after successfully completing this
00:23 learning by you will be able to
00:25 install joondal's pi easy and use joonas
00:28 pi easy to connect to a genos device
00:31 and retrieve device fax let's start by
00:34 learning what joonas pi easy is
00:37 junos pi ez is a free python library
00:40 available from juniper networks that
00:43 enables you
00:44 to automate the management of junos
00:46 devices
00:47 using python extensive junos knowledge
00:50 or juno cli knowledge really is not
00:53 required
00:55 a good way to learn juno's pi easy
00:57 there's a free junos pi ez developers
00:59 guide
01:00 on juniper's website you can also
01:01 download it in pdf format
01:03 it gave me it was a good starting point
01:05 for me to learn simple examples and and
01:07 use cases
01:08 i found it very helpful the idea of
01:11 juno's pi easy is that it can provide
01:13 the same capabilities of the juno cli
01:16 without needing to use the juno cli
01:19 i can use python and juno's pi easy
01:22 to remotely automate the management of
01:25 wider
01:26 range of juno's platforms let's look at
01:28 a joonas pi
01:29 ez installation this example installs
01:31 joondal's pi easy on a cent
01:33 os workstation in the examples i'm using
01:37 python version 3 joonas pi ez will work
01:40 with either python 2
01:41 or python 3. in this example i'm using
01:44 the
01:44 python pip 3 utility because it's python
01:47 3.
01:48 install junos eznc this is the name of
01:51 the python library that pip will pull
01:53 down
01:54 out of the the python package index and
01:55 this installs joonas pi easy
01:57 locally on this workstation it can also
01:59 be installed in a python virtual
02:01 environment
02:02 or it supports being installed as a
02:04 docker container if you prefer that that
02:06 option
02:07 there are some software prerequisites
02:09 kind of based on the operating system
02:11 that you're installing
02:12 you know juno's pi easy on uh so that's
02:15 i'm gonna reference you back to the
02:17 junos pi easy developers guide it will
02:19 list for the supported operating systems
02:21 any prerequisite software
02:23 there were six or seven you know unix
02:26 pieces of software i had to install
02:27 before i was able to run
02:29 the pip3 command to install it but it's
02:31 very easy to do and very quick
02:34 and so this is this will get us junos pi
02:36 easy installed and now i'm ready to
02:38 leverage geno's pi easy to manage my
02:40 junos platforms
02:42 this is an example python script that
02:45 connects to a junos device and will
02:47 retrieve
02:48 facts about the device and print them on
02:50 the screen so we'll be able to see the
02:52 results of this python script
02:54 so let's look at some of these
02:55 components in the script i'm going to
02:57 start focusing on the from statements
02:58 right this is where we import
03:00 we use the from the python from
03:02 statement to import
03:03 python modules so we can use them and
03:06 the example here in our first line
03:07 this is the junos pi easy library and
03:10 this is how it's identified in the
03:11 python interpreter and a python script
03:14 you say from this junos pi easy library
03:17 here jnpr.juniors i want to
03:19 import a device object this represents a
03:22 junos device
03:24 now i'm going to retrieve some facts i
03:26 want to print them on the screen
03:28 i don't have to use the the unix pretty
03:31 print
03:32 library to do that but if i leverage
03:35 this if i import the pretty print
03:36 library the functionality of that
03:38 my output looks better it's formatted a
03:41 little better on my screen and it's
03:42 easier for me to read
03:44 you don't have to use that you can just
03:46 use the standard unix
03:47 python print library if you'd like now
03:50 i'm going to declare a variable called
03:51 dev
03:53 and when i say dev i want to reference
03:54 this device
03:56 object that that is it represents a
03:57 connection to this
03:59 target host so you can adjust the ip
04:01 address here to match your environment
04:03 and test this out now i want to
04:07 use the device object open method this
04:10 is how i establish a connection to this
04:12 target host and then i want to
04:15 retrieve the device fact and i want to
04:18 use pretty print to
04:19 print those to my screen so retrieve the
04:22 device fax
04:24 and then pretty print those to my screen
04:26 and then as a good citizen
04:27 i would like to close the connection i
04:29 don't want to leave that
04:30 connection open the device junos pi ez
04:33 by default
04:34 will connect to this target device using
04:37 secure shell
04:38 and use netcomp right that's a comp over
04:41 ssh connection
04:42 it can also connect to devices using a
04:44 console connection
04:46 or a telnet connection but this is the
04:48 default a netcomp over ssh connection
04:51 i'm also when you connect to a junos
04:53 device you
04:54 have to authenticate before you can
04:56 issue commands you have to authenticate
04:58 when you connect
04:59 and in this example i'm going to use ssh
05:01 keys to do that i'm not going to be
05:03 prompted for a username and password
05:05 that's what this automation stuff is all
05:07 about
05:07 right so i'm going to connect to a
05:09 device now and we'll look again at this
05:11 script and then we'll run it and see the
05:13 output
05:14 and this is what you would see in this
05:16 case i'm running remember python3
05:19 and so i have python3 and then i say the
05:21 name of my script and it just executes
05:24 i'm not prompted for a username and
05:25 password
05:27 and this is the retrieved fax output let
05:29 me connect to a device and we'll look at
05:31 the script and i'll show you that now
05:34 okay here's my cenos desktop where i
05:36 have joondale's pie easy installed
05:38 and let's first take a look we'll use
05:39 the cat utility to look at the hello
05:41 world dot
05:42 python script again the same script that
05:44 we saw on the slide so it's on it
05:46 the script is built now let's run it so
05:48 python3 hello world.pi
05:50 and that's it i just referenced the
05:52 script and here is my
05:54 device fax output and so here's the the
05:58 script we ran
05:59 and then you see the output so this is
06:01 just an example i didn't have to
06:03 manually connect i didn't have to issue
06:05 any journals commands this is the
06:06 equivalent
06:07 of a juno show version command if you're
06:09 if you know much about
06:10 or have any experience with the with the
06:12 juno cli in this example i pulled that
06:14 same information using a python script
06:17 leveraging the junos pi ez library in
06:20 this learning byte we installed
06:22 junos pi ez and we used a simple python
06:25 script to connect to a junos device
06:27 and retrieve device backs thank you very
06:29 much
06:31 visit the juniper education services
06:33 website
06:34 to learn more about courses view our
06:37 full range of classroom
06:38 online and e-learning courses
06:42 learning paths industry segment and
06:44 technology specific
06:46 training juniper networks certification
06:49 program
06:50 the ultimate demonstration of your
06:52 confidence and
06:53 the training community from forums to
06:56 social media
06:57 join the discussion
07:03 you