CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-junos-eznc

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

Pending
Overview
Eval results
Files

operational-tables.mddocs/

Operational Data Tables

Factory-based system for retrieving structured operational data from devices using YAML-defined tables and views. Provides access to network protocols, interface statistics, routing information, and system data through a consistent, structured interface.

Capabilities

Factory Framework Classes

The factory framework provides the foundation for structured data access through Table and View classes that are defined via YAML configurations.

class Table:
    def __init__(self, dev):
        """
        Initialize Table bound to a device.
        
        Parameters:
        - dev (Device): Device object to bind to
        """
    
    def get(self, **kwargs):
        """
        Retrieve table data from the device.
        
        Parameters:
        - **kwargs: Table-specific parameters for data filtering
        
        Returns:
        - Table: Self-reference for chaining operations
        
        Raises:
        - RpcError: RPC operation failed
        - RpcTimeoutError: Data retrieval timed out
        """
    
    def __iter__(self):
        """
        Iterate over table items.
        
        Yields:
        - TableItem: Individual table entries
        """
    
    def __len__(self):
        """
        Get number of items in table.
        
        Returns:
        - int: Number of table entries
        """

class View:
    """
    View class for data extraction and formatting from table items.
    
    Views define how to extract specific fields from operational data
    and provide structured access to the information.
    """

Factory Loader

Load YAML-defined table and view definitions for custom operational data access patterns.

class FactoryLoader:
    """Class for loading YAML-defined table and view definitions."""
    
    def load(self, yaml_file):
        """
        Load table/view definitions from YAML file.
        
        Parameters:
        - yaml_file (str): Path to YAML file containing definitions
        
        Returns:
        - dict: Dictionary of loaded table/view classes
        """

def loadyaml(path):
    """
    Load YAML table and view definitions from file.
    
    Parameters:
    - path (str): Path to YAML file
    
    Returns:
    - dict: Dictionary mapping names to table/view classes
    """

Pre-built Operational Tables

Comprehensive set of pre-built tables for common operational data access patterns.

# Network Interface Tables
from jnpr.junos.op.interfaces import InterfaceTable
from jnpr.junos.op.ethport import EthPortTable

# Routing Tables  
from jnpr.junos.op.routes import RouteTable
from jnpr.junos.op.rib import RibTable

# ARP and Neighbor Tables
from jnpr.junos.op.arp import ArpTable
from jnpr.junos.op.ipv6_nd import IPv6NeighborTable

# Protocol Tables
from jnpr.junos.op.bgp import BgpNeighborTable
from jnpr.junos.op.ospf import OspfNeighborTable
from jnpr.junos.op.isis import IsisAdjacencyTable
from jnpr.junos.op.ldp import LdpNeighborTable

# System and Hardware Tables
from jnpr.junos.op.inventory import InventoryTable
from jnpr.junos.op.fpc import FpcTable
from jnpr.junos.op.environment import EnvironmentTable

# VLAN and Layer 2 Tables
from jnpr.junos.op.vlan import VlanTable
from jnpr.junos.op.mac import MacTable

# Security Tables (SRX)
from jnpr.junos.op.security import SecurityZoneTable
from jnpr.junos.op.firewall import FirewallTable

Usage Examples

Basic Interface Information

from jnpr.junos import Device
from jnpr.junos.op.interfaces import InterfaceTable

dev = Device(host='router1.example.com', user='admin', passwd='secret')
dev.open()

# Get interface information
interfaces = InterfaceTable(dev)
interfaces.get()

# Iterate through interfaces
for interface in interfaces:
    print(f"Interface: {interface.name}")
    print(f"  Status: {interface.oper_status}")
    print(f"  Description: {interface.description}")
    print(f"  Speed: {interface.speed}")
    print(f"  Input Bytes: {interface.rx_bytes}")
    print(f"  Output Bytes: {interface.tx_bytes}")
    print()

dev.close()

Routing Table Analysis

from jnpr.junos import Device
from jnpr.junos.op.routes import RouteTable

dev = Device(host='router1.example.com', user='admin', passwd='secret')
dev.open()

# Get routing table
routes = RouteTable(dev)
routes.get()

print(f"Total routes: {len(routes)}")

# Analyze routes by protocol
protocol_counts = {}
for route in routes:
    protocol = route.protocol
    protocol_counts[protocol] = protocol_counts.get(protocol, 0) + 1

print("\nRoutes by protocol:")
for protocol, count in protocol_counts.items():
    print(f"  {protocol}: {count}")

# Find default route
for route in routes:
    if route.destination == '0.0.0.0/0':
        print(f"\nDefault route via {route.next_hop}")
        break

dev.close()

BGP Neighbor Status

from jnpr.junos import Device
from jnpr.junos.op.bgp import BgpNeighborTable

dev = Device(host='router1.example.com', user='admin', passwd='secret')
dev.open()

# Get BGP neighbor information
bgp_neighbors = BgpNeighborTable(dev)
bgp_neighbors.get()

print("BGP Neighbor Status:")
print("-" * 60)

for neighbor in bgp_neighbors:
    print(f"Neighbor: {neighbor.peer_address}")
    print(f"  AS: {neighbor.peer_as}")
    print(f"  State: {neighbor.state}")
    print(f"  Uptime: {neighbor.elapsed_time}")
    print(f"  Received Routes: {neighbor.accepted_route_count}")
    print(f"  Active Routes: {neighbor.active_route_count}")
    print()

dev.close()

ARP Table Information

from jnpr.junos import Device
from jnpr.junos.op.arp import ArpTable

dev = Device(host='router1.example.com', user='admin', passwd='secret')
dev.open()

# Get ARP table
arp_table = ArpTable(dev)
arp_table.get()

print("ARP Table:")
print("-" * 50)

for arp_entry in arp_table:
    print(f"IP: {arp_entry.ip_address:<15} "
          f"MAC: {arp_entry.mac_address:<17} "
          f"Interface: {arp_entry.interface}")

dev.close()

System Inventory

from jnpr.junos import Device
from jnpr.junos.op.inventory import InventoryTable

dev = Device(host='router1.example.com', user='admin', passwd='secret')
dev.open()

# Get system inventory
inventory = InventoryTable(dev)
inventory.get()

print("System Inventory:")
print("-" * 60)

for item in inventory:
    print(f"Component: {item.name}")
    print(f"  Type: {item.type}")
    print(f"  Part Number: {item.part_number}")
    print(f"  Serial Number: {item.serial_number}")
    print(f"  Description: {item.description}")
    print()

dev.close()

OSPF Neighbor Information

from jnpr.junos import Device
from jnpr.junos.op.ospf import OspfNeighborTable

dev = Device(host='router1.example.com', user='admin', passwd='secret')
dev.open()

# Get OSPF neighbors
ospf_neighbors = OspfNeighborTable(dev)
ospf_neighbors.get()

print("OSPF Neighbors:")
print("-" * 50)

for neighbor in ospf_neighbors:
    print(f"Neighbor ID: {neighbor.neighbor_id}")
    print(f"  Address: {neighbor.neighbor_address}")
    print(f"  Interface: {neighbor.interface_name}")
    print(f"  State: {neighbor.neighbor_state}")
    print(f"  Priority: {neighbor.neighbor_priority}")
    print()

dev.close()

Custom Table with Filtering

from jnpr.junos import Device
from jnpr.junos.op.routes import RouteTable

dev = Device(host='router1.example.com', user='admin', passwd='secret')
dev.open()

# Get routes with filtering
routes = RouteTable(dev)

# Filter for specific destination
routes.get(destination='192.168.1.0/24')

for route in routes:
    print(f"Route: {route.destination}")
    print(f"  Next Hop: {route.next_hop}")
    print(f"  Protocol: {route.protocol}")
    print(f"  Preference: {route.preference}")

dev.close()

Environment and Hardware Status

from jnpr.junos import Device
from jnpr.junos.op.environment import EnvironmentTable
from jnpr.junos.op.fpc import FpcTable

dev = Device(host='router1.example.com', user='admin', passwd='secret')
dev.open()

# Check environmental status
env_table = EnvironmentTable(dev)
env_table.get()

print("Environmental Status:")
for item in env_table:
    print(f"{item.name}: {item.status} ({item.temperature}°C)")

# Check FPC status
fpc_table = FpcTable(dev)
fpc_table.get()

print("\nFPC Status:")
for fpc in fpc_table:
    print(f"FPC {fpc.slot}: {fpc.state}")
    print(f"  Temperature: {fpc.temperature}°C")
    print(f"  Memory: {fpc.memory_utilization}%")
    print(f"  CPU: {fpc.cpu_utilization}%")

dev.close()

VLAN Information

from jnpr.junos import Device
from jnpr.junos.op.vlan import VlanTable

dev = Device(host='router1.example.com', user='admin', passwd='secret')
dev.open()

# Get VLAN information
vlans = VlanTable(dev)
vlans.get()

print("VLAN Configuration:")
print("-" * 40)

for vlan in vlans:
    print(f"VLAN {vlan.vlan_id}: {vlan.name}")
    print(f"  Tag: {vlan.tag}")
    print(f"  Interfaces: {', '.join(vlan.interfaces) if vlan.interfaces else 'None'}")
    print()

dev.close()

Loading Custom YAML Tables

from jnpr.junos import Device
from jnpr.junos.factory.factory_loader import FactoryLoader

dev = Device(host='router1.example.com', user='admin', passwd='secret')
dev.open()

# Load custom table definitions from YAML
loader = FactoryLoader()
custom_tables = loader.load('/path/to/custom_tables.yaml')

# Use custom table
CustomTable = custom_tables['CustomTable']
custom_data = CustomTable(dev)
custom_data.get()

for item in custom_data:
    # Access custom fields defined in YAML
    print(f"Custom Field: {item.custom_field}")

dev.close()

Error Handling

from jnpr.junos import Device
from jnpr.junos.op.interfaces import InterfaceTable
from jnpr.junos.exception import RpcError, RpcTimeoutError

dev = Device(host='router1.example.com', user='admin', passwd='secret')
dev.open()

try:
    interfaces = InterfaceTable(dev)
    interfaces.get(timeout=30)  # Set timeout for data retrieval
    
    for interface in interfaces:
        print(f"Interface: {interface.name}")
        
except RpcTimeoutError:
    print("Table data retrieval timed out")
    
except RpcError as e:
    print(f"RPC error retrieving table data: {e}")
    
except Exception as e:
    print(f"Unexpected error: {e}")

dev.close()

Types

# Table and view types
TableClass = type  # Class derived from Table base class
ViewClass = type   # Class derived from View base class

# Table item types
TableItem = object  # Individual table entry/row
TableData = list[TableItem]  # Collection of table items

# Factory loader types
YamlDefinitions = dict[str, type]  # Mapping of names to table/view classes
YamlPath = str  # Path to YAML definition file

# Table parameters
TableParams = dict[str, any]  # Parameters for table data filtering

# Common table fields (examples)
InterfaceName = str      # Interface name (e.g., 'ge-0/0/0')
IpAddress = str          # IP address string
MacAddress = str         # MAC address string
OperStatus = str         # Operational status
RouteProtocol = str      # Routing protocol name

Install with Tessl CLI

npx tessl i tessl/pypi-junos-eznc

docs

command-execution.md

configuration.md

device-connection.md

exceptions.md

facts.md

filesystem.md

index.md

operational-tables.md

software.md

tile.json