Automation
Automation

How-To: Install Junos PyEZ correctly

by Cordelia on ‎04-24-2014 07:49 PM - edited on ‎09-11-2017 05:27 PM by Administrator Administrator (7,705 Views)

Overview

Basic remote connectivity and fact gathering.

 

Example


 

from pprint import pprint
from jnpr.junos import Device
dev = Device(host='my_host_or_ipaddr', user='jeremy', password='jeremy123' )
dev.open()
pprint( dev.facts )
dev.close()

 

Here is the sample output when connecting to an SRX210 device:

 

>>> pprint(dev.facts)
{'2RE': False, 'RE0': {'last_reboot_reason': '0x20:power-button soft power off', 'model': 'RE-SRX210H', 'status': 'OK', 'up_time': '10 minutes, 3 seconds'}, 'domain':'workflowsherpas.com'
'fqdn': 'srx210.workflowsherpas.com', 'hostname': 'srx210', 'ifd_style': 'CLASSIC', 'model': 'SRX210H','personality': 'SRX_BRANCH', 'serialnumber': 'AD2909AA0096', 'switch_style': 'VLAN', 'version': '12.1X44-D10.4', 'version_info': junos.versino_info(major=(12, 1), type=X, minor=(44, 'D', 10), build=4)}
 

 

Video

 

'
Comments
Apr 25, 2014
Cordelia
 
Jeremy,

Please let me know what is causing the following issues:

a) 'match' option is cli command is not honoured.
Example: show configuration interface | display set | match vlan ; display all interfaces not the vlans onlt

b) certain randomness in netconf session established
Example; I run a script that scans a list of ex4200 sequentially. Detconf session establishment is not consistent - sometimes it works and sometimes it does not. Wonder if there is a netconf session establishment timer limit.
Posted 12:10, 25 Apr 2014
Mar 25, 2015
Cordelia
 
Hi Karim,

You should be using the RPC on demand feature of PyEZ. Execute is a lower level API and requires the command be built out as an XML object.

http://forums.juniper.net/t5/Automation-Scripting/RPC-On-Demand/ta-p/278823
http://www.juniper.net/techpubs/en_US/junos-pyez1.0/topics/task/program/junos-pyez-rpcs-executing.ht...

If you need further assistance, please reach out to our Google Group
https://groups.google.com/forum/#!forum/junos-python-ez

-Rick
Posted 09:36, 25 Mar 2015
Mar 30, 2015
Cordelia
 
Thanks Rick
Posted 02:24, 30 Mar 2015
Aug 5, 2015
Cordelia
 
Hi Jeremy,
I am trying to issue rpc commands through the execute method of Device. I was expecting that the method would return an xml however it is returning a Boolean (which I suppose has the value True if the rpc is correct). Is this an expected behavior?
Thanks
Posted 08:35, 25 Mar 2015