or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

command-execution.mdconfiguration.mddevice-connection.mdexceptions.mdfacts.mdfilesystem.mdindex.mdoperational-tables.mdsoftware.md
tile.json

tessl/pypi-junos-eznc

Junos 'EZ' automation library for remotely managing and automating Juniper Networks Junos devices through NETCONF protocol

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/junos-eznc@2.7.x

To install, run

npx @tessl/cli install tessl/pypi-junos-eznc@2.7.0

index.mddocs/

Junos PyEZ (junos-eznc)

A 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.

Package Information

  • Package Name: junos-eznc
  • Language: Python
  • Installation: pip install junos-eznc
  • Python Version: Requires Python >= 3.8

Core Imports

from jnpr.junos import Device

For console connections:

from jnpr.junos import Console

For exception handling:

from jnpr.junos import exception

Basic Usage

from 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()

Architecture

Junos PyEZ is built around several key architectural components:

  • Device/Console Classes: Core connection management for NETCONF and console sessions
  • RPC Meta-Execution: Dynamic access to all Junos RPC operations through Python methods
  • Facts System: Automatic gathering and caching of device information
  • Utility Framework: Modular utilities for configuration, software management, and file operations
  • Factory System: Structured data handling through YAML-defined tables and views
  • Exception Hierarchy: Comprehensive error handling for all operation types

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.

Capabilities

Device Connection Management

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): ...

Device Connection Management

Command and RPC Execution

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'): ...

Command and RPC Execution

Configuration Management

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): ...

Configuration Management

Facts and Device Information

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 seconds

Facts and Device Information

Software Management

Software 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): ...

Software Management

File System Operations

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 operations

File System Operations

Operational Data Tables

Factory-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 formatting

Operational Data Tables

Exception Handling

Comprehensive 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): ...

Exception Handling

Types

# 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