or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

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

operational-tables.mddocs/

0

# Operational Data Tables

1

2

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.

3

4

## Capabilities

5

6

### Factory Framework Classes

7

8

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

9

10

```python { .api }

11

class Table:

12

def __init__(self, dev):

13

"""

14

Initialize Table bound to a device.

15

16

Parameters:

17

- dev (Device): Device object to bind to

18

"""

19

20

def get(self, **kwargs):

21

"""

22

Retrieve table data from the device.

23

24

Parameters:

25

- **kwargs: Table-specific parameters for data filtering

26

27

Returns:

28

- Table: Self-reference for chaining operations

29

30

Raises:

31

- RpcError: RPC operation failed

32

- RpcTimeoutError: Data retrieval timed out

33

"""

34

35

def __iter__(self):

36

"""

37

Iterate over table items.

38

39

Yields:

40

- TableItem: Individual table entries

41

"""

42

43

def __len__(self):

44

"""

45

Get number of items in table.

46

47

Returns:

48

- int: Number of table entries

49

"""

50

51

class View:

52

"""

53

View class for data extraction and formatting from table items.

54

55

Views define how to extract specific fields from operational data

56

and provide structured access to the information.

57

"""

58

```

59

60

### Factory Loader

61

62

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

63

64

```python { .api }

65

class FactoryLoader:

66

"""Class for loading YAML-defined table and view definitions."""

67

68

def load(self, yaml_file):

69

"""

70

Load table/view definitions from YAML file.

71

72

Parameters:

73

- yaml_file (str): Path to YAML file containing definitions

74

75

Returns:

76

- dict: Dictionary of loaded table/view classes

77

"""

78

79

def loadyaml(path):

80

"""

81

Load YAML table and view definitions from file.

82

83

Parameters:

84

- path (str): Path to YAML file

85

86

Returns:

87

- dict: Dictionary mapping names to table/view classes

88

"""

89

```

90

91

### Pre-built Operational Tables

92

93

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

94

95

```python { .api }

96

# Network Interface Tables

97

from jnpr.junos.op.interfaces import InterfaceTable

98

from jnpr.junos.op.ethport import EthPortTable

99

100

# Routing Tables

101

from jnpr.junos.op.routes import RouteTable

102

from jnpr.junos.op.rib import RibTable

103

104

# ARP and Neighbor Tables

105

from jnpr.junos.op.arp import ArpTable

106

from jnpr.junos.op.ipv6_nd import IPv6NeighborTable

107

108

# Protocol Tables

109

from jnpr.junos.op.bgp import BgpNeighborTable

110

from jnpr.junos.op.ospf import OspfNeighborTable

111

from jnpr.junos.op.isis import IsisAdjacencyTable

112

from jnpr.junos.op.ldp import LdpNeighborTable

113

114

# System and Hardware Tables

115

from jnpr.junos.op.inventory import InventoryTable

116

from jnpr.junos.op.fpc import FpcTable

117

from jnpr.junos.op.environment import EnvironmentTable

118

119

# VLAN and Layer 2 Tables

120

from jnpr.junos.op.vlan import VlanTable

121

from jnpr.junos.op.mac import MacTable

122

123

# Security Tables (SRX)

124

from jnpr.junos.op.security import SecurityZoneTable

125

from jnpr.junos.op.firewall import FirewallTable

126

```

127

128

## Usage Examples

129

130

### Basic Interface Information

131

132

```python

133

from jnpr.junos import Device

134

from jnpr.junos.op.interfaces import InterfaceTable

135

136

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

137

dev.open()

138

139

# Get interface information

140

interfaces = InterfaceTable(dev)

141

interfaces.get()

142

143

# Iterate through interfaces

144

for interface in interfaces:

145

print(f"Interface: {interface.name}")

146

print(f" Status: {interface.oper_status}")

147

print(f" Description: {interface.description}")

148

print(f" Speed: {interface.speed}")

149

print(f" Input Bytes: {interface.rx_bytes}")

150

print(f" Output Bytes: {interface.tx_bytes}")

151

print()

152

153

dev.close()

154

```

155

156

### Routing Table Analysis

157

158

```python

159

from jnpr.junos import Device

160

from jnpr.junos.op.routes import RouteTable

161

162

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

163

dev.open()

164

165

# Get routing table

166

routes = RouteTable(dev)

167

routes.get()

168

169

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

170

171

# Analyze routes by protocol

172

protocol_counts = {}

173

for route in routes:

174

protocol = route.protocol

175

protocol_counts[protocol] = protocol_counts.get(protocol, 0) + 1

176

177

print("\nRoutes by protocol:")

178

for protocol, count in protocol_counts.items():

179

print(f" {protocol}: {count}")

180

181

# Find default route

182

for route in routes:

183

if route.destination == '0.0.0.0/0':

184

print(f"\nDefault route via {route.next_hop}")

185

break

186

187

dev.close()

188

```

189

190

### BGP Neighbor Status

191

192

```python

193

from jnpr.junos import Device

194

from jnpr.junos.op.bgp import BgpNeighborTable

195

196

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

197

dev.open()

198

199

# Get BGP neighbor information

200

bgp_neighbors = BgpNeighborTable(dev)

201

bgp_neighbors.get()

202

203

print("BGP Neighbor Status:")

204

print("-" * 60)

205

206

for neighbor in bgp_neighbors:

207

print(f"Neighbor: {neighbor.peer_address}")

208

print(f" AS: {neighbor.peer_as}")

209

print(f" State: {neighbor.state}")

210

print(f" Uptime: {neighbor.elapsed_time}")

211

print(f" Received Routes: {neighbor.accepted_route_count}")

212

print(f" Active Routes: {neighbor.active_route_count}")

213

print()

214

215

dev.close()

216

```

217

218

### ARP Table Information

219

220

```python

221

from jnpr.junos import Device

222

from jnpr.junos.op.arp import ArpTable

223

224

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

225

dev.open()

226

227

# Get ARP table

228

arp_table = ArpTable(dev)

229

arp_table.get()

230

231

print("ARP Table:")

232

print("-" * 50)

233

234

for arp_entry in arp_table:

235

print(f"IP: {arp_entry.ip_address:<15} "

236

f"MAC: {arp_entry.mac_address:<17} "

237

f"Interface: {arp_entry.interface}")

238

239

dev.close()

240

```

241

242

### System Inventory

243

244

```python

245

from jnpr.junos import Device

246

from jnpr.junos.op.inventory import InventoryTable

247

248

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

249

dev.open()

250

251

# Get system inventory

252

inventory = InventoryTable(dev)

253

inventory.get()

254

255

print("System Inventory:")

256

print("-" * 60)

257

258

for item in inventory:

259

print(f"Component: {item.name}")

260

print(f" Type: {item.type}")

261

print(f" Part Number: {item.part_number}")

262

print(f" Serial Number: {item.serial_number}")

263

print(f" Description: {item.description}")

264

print()

265

266

dev.close()

267

```

268

269

### OSPF Neighbor Information

270

271

```python

272

from jnpr.junos import Device

273

from jnpr.junos.op.ospf import OspfNeighborTable

274

275

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

276

dev.open()

277

278

# Get OSPF neighbors

279

ospf_neighbors = OspfNeighborTable(dev)

280

ospf_neighbors.get()

281

282

print("OSPF Neighbors:")

283

print("-" * 50)

284

285

for neighbor in ospf_neighbors:

286

print(f"Neighbor ID: {neighbor.neighbor_id}")

287

print(f" Address: {neighbor.neighbor_address}")

288

print(f" Interface: {neighbor.interface_name}")

289

print(f" State: {neighbor.neighbor_state}")

290

print(f" Priority: {neighbor.neighbor_priority}")

291

print()

292

293

dev.close()

294

```

295

296

### Custom Table with Filtering

297

298

```python

299

from jnpr.junos import Device

300

from jnpr.junos.op.routes import RouteTable

301

302

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

303

dev.open()

304

305

# Get routes with filtering

306

routes = RouteTable(dev)

307

308

# Filter for specific destination

309

routes.get(destination='192.168.1.0/24')

310

311

for route in routes:

312

print(f"Route: {route.destination}")

313

print(f" Next Hop: {route.next_hop}")

314

print(f" Protocol: {route.protocol}")

315

print(f" Preference: {route.preference}")

316

317

dev.close()

318

```

319

320

### Environment and Hardware Status

321

322

```python

323

from jnpr.junos import Device

324

from jnpr.junos.op.environment import EnvironmentTable

325

from jnpr.junos.op.fpc import FpcTable

326

327

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

328

dev.open()

329

330

# Check environmental status

331

env_table = EnvironmentTable(dev)

332

env_table.get()

333

334

print("Environmental Status:")

335

for item in env_table:

336

print(f"{item.name}: {item.status} ({item.temperature}°C)")

337

338

# Check FPC status

339

fpc_table = FpcTable(dev)

340

fpc_table.get()

341

342

print("\nFPC Status:")

343

for fpc in fpc_table:

344

print(f"FPC {fpc.slot}: {fpc.state}")

345

print(f" Temperature: {fpc.temperature}°C")

346

print(f" Memory: {fpc.memory_utilization}%")

347

print(f" CPU: {fpc.cpu_utilization}%")

348

349

dev.close()

350

```

351

352

### VLAN Information

353

354

```python

355

from jnpr.junos import Device

356

from jnpr.junos.op.vlan import VlanTable

357

358

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

359

dev.open()

360

361

# Get VLAN information

362

vlans = VlanTable(dev)

363

vlans.get()

364

365

print("VLAN Configuration:")

366

print("-" * 40)

367

368

for vlan in vlans:

369

print(f"VLAN {vlan.vlan_id}: {vlan.name}")

370

print(f" Tag: {vlan.tag}")

371

print(f" Interfaces: {', '.join(vlan.interfaces) if vlan.interfaces else 'None'}")

372

print()

373

374

dev.close()

375

```

376

377

### Loading Custom YAML Tables

378

379

```python

380

from jnpr.junos import Device

381

from jnpr.junos.factory.factory_loader import FactoryLoader

382

383

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

384

dev.open()

385

386

# Load custom table definitions from YAML

387

loader = FactoryLoader()

388

custom_tables = loader.load('/path/to/custom_tables.yaml')

389

390

# Use custom table

391

CustomTable = custom_tables['CustomTable']

392

custom_data = CustomTable(dev)

393

custom_data.get()

394

395

for item in custom_data:

396

# Access custom fields defined in YAML

397

print(f"Custom Field: {item.custom_field}")

398

399

dev.close()

400

```

401

402

### Error Handling

403

404

```python

405

from jnpr.junos import Device

406

from jnpr.junos.op.interfaces import InterfaceTable

407

from jnpr.junos.exception import RpcError, RpcTimeoutError

408

409

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

410

dev.open()

411

412

try:

413

interfaces = InterfaceTable(dev)

414

interfaces.get(timeout=30) # Set timeout for data retrieval

415

416

for interface in interfaces:

417

print(f"Interface: {interface.name}")

418

419

except RpcTimeoutError:

420

print("Table data retrieval timed out")

421

422

except RpcError as e:

423

print(f"RPC error retrieving table data: {e}")

424

425

except Exception as e:

426

print(f"Unexpected error: {e}")

427

428

dev.close()

429

```

430

431

## Types

432

433

```python { .api }

434

# Table and view types

435

TableClass = type # Class derived from Table base class

436

ViewClass = type # Class derived from View base class

437

438

# Table item types

439

TableItem = object # Individual table entry/row

440

TableData = list[TableItem] # Collection of table items

441

442

# Factory loader types

443

YamlDefinitions = dict[str, type] # Mapping of names to table/view classes

444

YamlPath = str # Path to YAML definition file

445

446

# Table parameters

447

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

448

449

# Common table fields (examples)

450

InterfaceName = str # Interface name (e.g., 'ge-0/0/0')

451

IpAddress = str # IP address string

452

MacAddress = str # MAC address string

453

OperStatus = str # Operational status

454

RouteProtocol = str # Routing protocol name

455

```