Release 2.0.0
Console connection using PyEZ
Now PyEZ will support Console (Telnet/Serial) connection apart from SSH
- Telnet Connection
- Over managment ip
- Over Console Server ip/port
- Serial Connection
Example:
from jnpr.junos import Device
from lxml import etree
with Device(host='console-srv-ip', user='xxx', password='xxxx', mode='telnet', port='7011', gather_facts=True) as dev:
print dev.facts
op = dev.rpc.get_interface_information(interface_name='fxp0')
print etree.tostring(op)
Python >=3.4 support
$ python
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from jnpr.junos import Device
>>> dev = Device('xxxx', user='xxxx', password='xxxx')
>>> dev.open()
>>> print (dev.facts)
Configuration Tables to Define and Configure Structured Resources
Example:
from jnpr.junos import Device
from jnpr.junos.resources.interface import InterfaceTable
dev = Device(host='xx.xx.xx.xx', user='xxx', gather_facts=False)
dev.open()
intf = InterfaceTable(dev)
intf.name = "ge-1/1/5"
intf.unit_name = 0
intf.disable = True
intf.mode = "trunk"
intf.vlan_list = [510, 520, 530]
intf.native_vlan = 510
intf.desc = "l2-interface created"
intf.append()
intf.set()
JSON Config load
For devices >=16.1, user can also load JSON config apart from xml/set/text
Example:
from jnpr.junos import Device
dev = Device(host='xx.xxx.xxx.xx', user='xxxx', password='xxxx', gather_facts=False)
dev.open()
cnf = """{
"configuration" : {
"system" : {
"services" : {
"telnet" : [null]
}
}
}
}"""
cu = Config(dev)
op = cu.load(cnf, format='json')
print etree.tostring(op)
dev.close()
FTP Utility
Option to use FTP utility to transfer files in addition to existing SCP.
from jnpr.junos import Device
from jnpr.junos.utils.ftp import FTP
dev = Device(host='xx.xxx.xxx.xx', user='xxxx', password='xxxx', gather_facts=False)
dev.open()
with FTP(dev) as ftp:
ftp.put('/var/tmp/test.txt', '/var/tmp/test.txt')
dev.close()
Multi RPC error
If the config being loaded got more then 1 error/warning, PyEZ will give all error details to the user
from jnpr.junos import Device
from jnpr.junos.utils.config import Config
dev = Device(host='xx.xxx.xxx.xx', user='xxxx', password='xxxx', gather_facts=False)
dev.open()
cnf = \
"""set interfaces xe-0/0/10 ether-options 802.3ad ae10
et interfaces xe-0/0/11 ether-options 802.3ad ae11
set interfaces xe-0/0/12 ether-options 802.3ad lcap force-up
set interfaces xe-0/0/14 ether-options 802.3ad ae14"""
cu = Config(dev)
try:
cu.load(cnf, format='set')
cu.commit()
except Exception as ex:
print ex.errs
print ex```
Output
[{'source': None, 'message': 'syntax error', 'bad_element': 'ether-options', 'severity': 'error'},
{'source': None, 'message': 'unknown command', 'bad_element': 'et', 'severity': 'error'},
{'source': None, 'message': 'syntax error', 'bad_element': 'ether-options', 'severity': 'error'},
{'source': None, 'message': 'syntax error', 'bad_element': 'ether-options', 'severity': 'error'}]
ConfigLoadError(severity: error, bad_element: ether-options, message: error: syntax error
error: unknown command
error: syntax error
error: syntax error)```