Junos 'EZ' automation library for remotely managing and automating Juniper Networks Junos devices through NETCONF protocol
npx @tessl/cli install tessl/pypi-junos-eznc@2.7.0A comprehensive Python library for remotely managing and automating Juniper Networks Junos devices through NETCONF protocol. The library enables both non-programmers and experienced developers to interact with Junos devices without requiring deep knowledge of Junos XML API or complex CLI screen scraping, providing device connectivity management, facts gathering, operational and configuration state retrieval, and common utilities for secure file operations and software updates.
pip install junos-ezncfrom jnpr.junos import DeviceFor console connections:
from jnpr.junos import ConsoleFor exception handling:
from jnpr.junos import exceptionfrom jnpr.junos import Device
# Connect to a Junos device
dev = Device(host='192.168.1.1', user='admin', passwd='secret')
dev.open()
# Get device facts
print(f"Hostname: {dev.facts['hostname']}")
print(f"Model: {dev.facts['model']}")
print(f"Version: {dev.facts['version']}")
# Execute CLI commands
result = dev.cli('show version')
print(result)
# Execute RPC commands
interfaces = dev.rpc.get_interface_information()
# Close connection
dev.close()Junos PyEZ is built around several key architectural components:
The design provides a Python-native abstraction layer over Junos device management that supports all Junos and Junos Evolved platforms, with built-in version independence and extensibility.
Core device connection functionality for NETCONF and console sessions, including authentication, session management, connectivity testing, and connection lifecycle management.
class Device:
def __init__(self, host=None, user=None, passwd=None, port=830, **kwargs): ...
def open(self, **kwargs): ...
def close(self): ...
def probe(self, timeout=5): ...
class Console:
def __init__(self, host=None, user='root', mode='telnet', **kwargs): ...
def open(self, **kwargs): ...
def close(self): ...Command execution capabilities including CLI commands, RPC operations, and XML processing for both structured and unstructured command output.
def cli(self, command, format='text', warning=True): ...
def execute(self, rpc_cmd, **kwargs): ...
def display_xml_rpc(self, command, format='xml'): ...Configuration management utilities for loading, committing, rolling back, and managing Junos device configurations with support for multiple formats and advanced commit options.
class Config:
def load(self, config_data, format='text', merge=False, overwrite=False, **kwargs): ...
def commit(self, comment=None, confirm=None, timeout=None, **kwargs): ...
def rollback(self, rb_id=0, timeout=None): ...
def diff(self, rb_id=0, timeout=None): ...
def lock(self): ...
def unlock(self): ...Device facts gathering system providing comprehensive device information including hardware details, software versions, network interfaces, and system status.
def facts_refresh(self, **kwargs): ...
# Facts dictionary properties
facts: dict # Complete device facts
hostname: str # Device hostname
uptime: int # Device uptime in secondsSoftware installation and management utilities for updating Junos software, managing software packages, and performing system operations like reboots.
class SW:
def install(self, package=None, remote_path='/var/tmp', progress=None, **kwargs): ...
def reboot(self, in_min=0, at=None): ...
def poweroff(self, in_min=0, at=None): ...
def validate(self, remote_package, timeout=300): ...File system and transfer utilities for secure file operations, including SCP and FTP transfers, directory operations, and file management.
class FS:
# File system operations
class SCP:
# Secure copy operations
class FTP:
# FTP operationsFactory-based system for retrieving structured operational data from devices using YAML-defined tables and views for network protocols, interfaces, and system information.
class Table:
def get(self, **kwargs): ...
def __iter__(self): ...
class View:
# Data extraction and formattingComprehensive exception hierarchy for handling all types of errors including connection failures, RPC errors, configuration problems, and operational issues.
class ConnectError(Exception): ...
class RpcError(Exception): ...
class CommitError(RpcError): ...
class ConfigLoadError(RpcError): ...
class LockError(RpcError): ...# Connection parameters
ConnectionParams = dict # host, user, passwd, port, timeout, etc.
# RPC response format
RpcResponse = dict # Parsed RPC response data
# Facts dictionary
FactsDict = dict # Device facts with standard keys
# Configuration data formats
ConfigData = str | dict # Configuration in text, set, XML, or JSON format