or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

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

0

# Junos PyEZ (junos-eznc)

1

2

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.

3

4

## Package Information

5

6

- **Package Name**: junos-eznc

7

- **Language**: Python

8

- **Installation**: `pip install junos-eznc`

9

- **Python Version**: Requires Python >= 3.8

10

11

## Core Imports

12

13

```python

14

from jnpr.junos import Device

15

```

16

17

For console connections:

18

19

```python

20

from jnpr.junos import Console

21

```

22

23

For exception handling:

24

25

```python

26

from jnpr.junos import exception

27

```

28

29

## Basic Usage

30

31

```python

32

from jnpr.junos import Device

33

34

# Connect to a Junos device

35

dev = Device(host='192.168.1.1', user='admin', passwd='secret')

36

dev.open()

37

38

# Get device facts

39

print(f"Hostname: {dev.facts['hostname']}")

40

print(f"Model: {dev.facts['model']}")

41

print(f"Version: {dev.facts['version']}")

42

43

# Execute CLI commands

44

result = dev.cli('show version')

45

print(result)

46

47

# Execute RPC commands

48

interfaces = dev.rpc.get_interface_information()

49

50

# Close connection

51

dev.close()

52

```

53

54

## Architecture

55

56

Junos PyEZ is built around several key architectural components:

57

58

- **Device/Console Classes**: Core connection management for NETCONF and console sessions

59

- **RPC Meta-Execution**: Dynamic access to all Junos RPC operations through Python methods

60

- **Facts System**: Automatic gathering and caching of device information

61

- **Utility Framework**: Modular utilities for configuration, software management, and file operations

62

- **Factory System**: Structured data handling through YAML-defined tables and views

63

- **Exception Hierarchy**: Comprehensive error handling for all operation types

64

65

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.

66

67

## Capabilities

68

69

### Device Connection Management

70

71

Core device connection functionality for NETCONF and console sessions, including authentication, session management, connectivity testing, and connection lifecycle management.

72

73

```python { .api }

74

class Device:

75

def __init__(self, host=None, user=None, passwd=None, port=830, **kwargs): ...

76

def open(self, **kwargs): ...

77

def close(self): ...

78

def probe(self, timeout=5): ...

79

80

class Console:

81

def __init__(self, host=None, user='root', mode='telnet', **kwargs): ...

82

def open(self, **kwargs): ...

83

def close(self): ...

84

```

85

86

[Device Connection Management](./device-connection.md)

87

88

### Command and RPC Execution

89

90

Command execution capabilities including CLI commands, RPC operations, and XML processing for both structured and unstructured command output.

91

92

```python { .api }

93

def cli(self, command, format='text', warning=True): ...

94

def execute(self, rpc_cmd, **kwargs): ...

95

def display_xml_rpc(self, command, format='xml'): ...

96

```

97

98

[Command and RPC Execution](./command-execution.md)

99

100

### Configuration Management

101

102

Configuration management utilities for loading, committing, rolling back, and managing Junos device configurations with support for multiple formats and advanced commit options.

103

104

```python { .api }

105

class Config:

106

def load(self, config_data, format='text', merge=False, overwrite=False, **kwargs): ...

107

def commit(self, comment=None, confirm=None, timeout=None, **kwargs): ...

108

def rollback(self, rb_id=0, timeout=None): ...

109

def diff(self, rb_id=0, timeout=None): ...

110

def lock(self): ...

111

def unlock(self): ...

112

```

113

114

[Configuration Management](./configuration.md)

115

116

### Facts and Device Information

117

118

Device facts gathering system providing comprehensive device information including hardware details, software versions, network interfaces, and system status.

119

120

```python { .api }

121

def facts_refresh(self, **kwargs): ...

122

123

# Facts dictionary properties

124

facts: dict # Complete device facts

125

hostname: str # Device hostname

126

uptime: int # Device uptime in seconds

127

```

128

129

[Facts and Device Information](./facts.md)

130

131

### Software Management

132

133

Software installation and management utilities for updating Junos software, managing software packages, and performing system operations like reboots.

134

135

```python { .api }

136

class SW:

137

def install(self, package=None, remote_path='/var/tmp', progress=None, **kwargs): ...

138

def reboot(self, in_min=0, at=None): ...

139

def poweroff(self, in_min=0, at=None): ...

140

def validate(self, remote_package, timeout=300): ...

141

```

142

143

[Software Management](./software.md)

144

145

### File System Operations

146

147

File system and transfer utilities for secure file operations, including SCP and FTP transfers, directory operations, and file management.

148

149

```python { .api }

150

class FS:

151

# File system operations

152

153

class SCP:

154

# Secure copy operations

155

156

class FTP:

157

# FTP operations

158

```

159

160

[File System Operations](./filesystem.md)

161

162

### Operational Data Tables

163

164

Factory-based system for retrieving structured operational data from devices using YAML-defined tables and views for network protocols, interfaces, and system information.

165

166

```python { .api }

167

class Table:

168

def get(self, **kwargs): ...

169

def __iter__(self): ...

170

171

class View:

172

# Data extraction and formatting

173

```

174

175

[Operational Data Tables](./operational-tables.md)

176

177

### Exception Handling

178

179

Comprehensive exception hierarchy for handling all types of errors including connection failures, RPC errors, configuration problems, and operational issues.

180

181

```python { .api }

182

class ConnectError(Exception): ...

183

class RpcError(Exception): ...

184

class CommitError(RpcError): ...

185

class ConfigLoadError(RpcError): ...

186

class LockError(RpcError): ...

187

```

188

189

[Exception Handling](./exceptions.md)

190

191

## Types

192

193

```python { .api }

194

# Connection parameters

195

ConnectionParams = dict # host, user, passwd, port, timeout, etc.

196

197

# RPC response format

198

RpcResponse = dict # Parsed RPC response data

199

200

# Facts dictionary

201

FactsDict = dict # Device facts with standard keys

202

203

# Configuration data formats

204

ConfigData = str | dict # Configuration in text, set, XML, or JSON format

205

```