Junos EZNC (py-junos-eznc)

2.7.6 · active · verified Thu Apr 16

Junos EZNC is a Python library for automating Juniper Junos devices, simplifying network management tasks for non-programmers. It provides a high-level API to connect to devices, retrieve facts, execute commands, and manage configurations using NETCONF. The current version is 2.7.6, with releases occurring periodically to add features, fix bugs, and ensure compatibility with newer Python versions and underlying dependencies.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to establish a connection to a Junos device, retrieve basic facts, and properly close the connection. It uses environment variables for credentials, making it safer for sharing. For production environments, `hostkey_verify` should be set to `True` for secure SSH connections.

import os
from jnpr.junos import Device
from jnpr.junos.exception import ConnectError

host = os.environ.get('JUNOS_HOST', 'your_junos_device_ip')
user = os.environ.get('JUNOS_USER', 'your_username')
password = os.environ.get('JUNOS_PASSWORD', 'your_password')

dev = None
try:
    # hostkey_verify=False for labs/quick starts, use True in production
    dev = Device(host=host, user=user, password=password, port=22, hostkey_verify=False)
    dev.open()
    print(f"Connected to device: {dev.hostname}")
    print(f"Device facts: {dev.facts['hostname']}, {dev.facts['version']}")
    # Example: Execute a command
    # rpc_resp = dev.rpc.get_system_uptime_information()
    # print(rpc_resp.find('.//up-time').text)

except ConnectError as err:
    print(f"Connection error: {err}")
except Exception as err:
    print(f"An error occurred: {err}")
finally:
    if dev and dev.connected:
        dev.close()
        print("Disconnected from device.")

view raw JSON →