0
# Facts and Device Information
1
2
Device facts gathering system providing comprehensive device information including hardware details, software versions, chassis information, routing engine details, and network interface data automatically collected during device connection.
3
4
## Capabilities
5
6
### Facts Dictionary Access
7
8
Access to comprehensive device facts through the facts property, providing structured information about device hardware, software, and operational status.
9
10
```python { .api }
11
@property
12
def facts(self) -> dict:
13
"""
14
Device facts dictionary containing comprehensive device information.
15
16
Standard facts keys:
17
- hostname: Device hostname
18
- model: Device model/platform
19
- serialnumber: Chassis serial number
20
- version: Software version string
21
- personality: Device personality (MX, EX, SRX, etc.)
22
- switch_style: Switch style (BRIDGE_DOMAIN, VLAN, etc.)
23
- master: Master routing engine status
24
- vc_capable: Virtual chassis capable
25
- vc_mode: Virtual chassis mode
26
- vc_fabric: Virtual chassis fabric status
27
- 2RE: Dual routing engine status
28
- domain: Configuration domain
29
- re_info: Routing engine information
30
- ifd_style: Interface style
31
- current_re: Current routing engine info
32
- fpc: Flexible PIC Concentrator information
33
- srx_cluster: SRX cluster status (SRX devices only)
34
- srx_cluster_id: SRX cluster ID (SRX devices only)
35
- srx_cluster_redundancy_group: SRX cluster redundancy group
36
37
Returns:
38
- dict: Device facts dictionary
39
"""
40
```
41
42
### Facts Refresh
43
44
Methods for refreshing device facts, useful when device state may have changed or when custom fact gathering is required.
45
46
```python { .api }
47
def facts_refresh(self, **kwargs):
48
"""
49
Refresh device facts by re-gathering information from device.
50
51
Parameters:
52
- **kwargs: Optional fact gathering parameters
53
- keys (list): Specific fact keys to refresh
54
- timeout (int): Timeout for fact gathering operations
55
56
Updates the device facts dictionary with current information.
57
58
Raises:
59
- RpcError: Fact gathering RPC failed
60
- RpcTimeoutError: Fact gathering timed out
61
"""
62
```
63
64
### Individual Fact Properties
65
66
Direct access to commonly used device facts through individual properties for convenience and backward compatibility.
67
68
```python { .api }
69
@property
70
def hostname(self) -> str:
71
"""Device hostname from system configuration or facts"""
72
73
@property
74
def uptime(self) -> int:
75
"""Device uptime in seconds"""
76
77
@property
78
def master(self) -> bool:
79
"""True if connected to master routing engine"""
80
81
@property
82
def re_name(self) -> str:
83
"""Current routing engine name (re0, re1, etc.)"""
84
```
85
86
### Version Information
87
88
Structured access to software version information with parsing and comparison capabilities.
89
90
```python { .api }
91
class version_info:
92
"""
93
Software version information parsing and representation.
94
95
Provides structured access to Junos software version components
96
including major/minor versions, build information, and type.
97
"""
98
99
def __init__(self, verstr):
100
"""
101
Parse version string into structured components.
102
103
Parameters:
104
- verstr (str): Version string to parse (e.g., "21.4R3.15")
105
"""
106
107
@property
108
def major(self) -> tuple:
109
"""Major version components (year, quarter)"""
110
111
@property
112
def minor(self) -> int:
113
"""Minor version number"""
114
115
@property
116
def type(self) -> str:
117
"""Version type (R, I, F, etc.)"""
118
119
@property
120
def build(self) -> int:
121
"""Build number"""
122
123
def __str__(self) -> str:
124
"""String representation of version"""
125
126
def __repr__(self) -> str:
127
"""Developer representation of version"""
128
```
129
130
### Legacy Facts (Deprecated)
131
132
Access to legacy facts system for backward compatibility, though new code should use the standard facts dictionary.
133
134
```python { .api }
135
@property
136
def ofacts(self) -> dict:
137
"""
138
Legacy operational facts dictionary (deprecated).
139
140
Provided for backward compatibility. New code should use
141
the 'facts' property instead.
142
143
Returns:
144
- dict: Legacy facts dictionary
145
"""
146
```
147
148
## Usage Examples
149
150
### Basic Facts Access
151
152
```python
153
from jnpr.junos import Device
154
155
dev = Device(host='router1.example.com', user='admin', passwd='secret')
156
dev.open()
157
158
# Access individual facts
159
print(f"Hostname: {dev.facts['hostname']}")
160
print(f"Model: {dev.facts['model']}")
161
print(f"Serial Number: {dev.facts['serialnumber']}")
162
print(f"Software Version: {dev.facts['version']}")
163
print(f"Device Personality: {dev.facts['personality']}")
164
165
# Check device capabilities
166
print(f"Virtual Chassis Capable: {dev.facts['vc_capable']}")
167
print(f"Dual RE: {dev.facts['2RE']}")
168
print(f"Master RE: {dev.facts['master']}")
169
170
dev.close()
171
```
172
173
### Complete Facts Display
174
175
```python
176
from jnpr.junos import Device
177
import json
178
179
dev = Device(host='router1.example.com', user='admin', passwd='secret')
180
dev.open()
181
182
# Display all facts in formatted JSON
183
print("Device Facts:")
184
print(json.dumps(dev.facts, indent=2, default=str))
185
186
dev.close()
187
```
188
189
### Version Information Parsing
190
191
```python
192
from jnpr.junos import Device
193
from jnpr.junos.facts.swver import version_info
194
195
dev = Device(host='router1.example.com', user='admin', passwd='secret')
196
dev.open()
197
198
# Parse version information
199
version = version_info(dev.facts['version'])
200
201
print(f"Full Version: {version}")
202
print(f"Major Version: {version.major}")
203
print(f"Minor Version: {version.minor}")
204
print(f"Version Type: {version.type}")
205
print(f"Build Number: {version.build}")
206
207
# Version comparison example
208
if version.major >= (21, 4):
209
print("Running Junos 21.4 or later")
210
211
dev.close()
212
```
213
214
### Facts Refresh
215
216
```python
217
from jnpr.junos import Device
218
219
dev = Device(host='router1.example.com', user='admin', passwd='secret')
220
dev.open()
221
222
# Initial facts
223
print(f"Initial uptime: {dev.uptime} seconds")
224
225
# Wait some time or after configuration changes...
226
import time
227
time.sleep(60)
228
229
# Refresh facts to get updated information
230
dev.facts_refresh()
231
print(f"Updated uptime: {dev.uptime} seconds")
232
233
dev.close()
234
```
235
236
### Routing Engine Information
237
238
```python
239
from jnpr.junos import Device
240
241
dev = Device(host='router1.example.com', user='admin', passwd='secret')
242
dev.open()
243
244
# Check routing engine details
245
if dev.facts['2RE']:
246
print("Dual routing engine system")
247
print(f"Current RE: {dev.re_name}")
248
print(f"Master status: {dev.master}")
249
250
# Access detailed RE information
251
if 're_info' in dev.facts:
252
for re_name, re_info in dev.facts['re_info'].items():
253
print(f"RE {re_name}:")
254
print(f" Status: {re_info.get('status', 'unknown')}")
255
print(f" Model: {re_info.get('model', 'unknown')}")
256
print(f" Uptime: {re_info.get('up_time', 'unknown')}")
257
else:
258
print("Single routing engine system")
259
print(f"RE Name: {dev.re_name}")
260
261
dev.close()
262
```
263
264
### Device Capabilities Check
265
266
```python
267
from jnpr.junos import Device
268
269
dev = Device(host='router1.example.com', user='admin', passwd='secret')
270
dev.open()
271
272
# Check device type and capabilities
273
device_type = dev.facts['personality']
274
print(f"Device Type: {device_type}")
275
276
if device_type == 'SRX_BRANCH':
277
print("SRX Series branch device")
278
if 'srx_cluster' in dev.facts:
279
print(f"Cluster Status: {dev.facts['srx_cluster']}")
280
if dev.facts['srx_cluster']:
281
print(f"Cluster ID: {dev.facts['srx_cluster_id']}")
282
print(f"Redundancy Group: {dev.facts['srx_cluster_redundancy_group']}")
283
284
elif device_type in ['MX', 'MX_MASTER', 'MX_BACKUP']:
285
print("MX Series device")
286
print(f"Switch Style: {dev.facts['switch_style']}")
287
288
elif device_type in ['EX', 'EX_MASTER', 'EX_BACKUP']:
289
print("EX Series switch")
290
if dev.facts['vc_capable']:
291
print(f"Virtual Chassis Mode: {dev.facts['vc_mode']}")
292
print(f"VC Fabric: {dev.facts['vc_fabric']}")
293
294
dev.close()
295
```
296
297
### Selective Facts Refresh
298
299
```python
300
from jnpr.junos import Device
301
302
dev = Device(host='router1.example.com', user='admin', passwd='secret')
303
dev.open()
304
305
# Refresh only specific facts (implementation dependent)
306
try:
307
dev.facts_refresh(keys=['hostname', 'uptime', 'version'])
308
print("Refreshed key facts successfully")
309
except Exception as e:
310
print(f"Facts refresh error: {e}")
311
312
dev.close()
313
```
314
315
### Facts-Based Device Configuration
316
317
```python
318
from jnpr.junos import Device
319
from jnpr.junos.utils.config import Config
320
321
dev = Device(host='router1.example.com', user='admin', passwd='secret')
322
dev.open()
323
dev.bind(cu=Config)
324
325
# Configure based on device facts
326
model = dev.facts['model']
327
hostname = dev.facts['hostname']
328
329
if model.startswith('EX'):
330
# EX switch specific configuration
331
config = f'''
332
set system host-name {hostname}-switch
333
set vlans vlan100 vlan-id 100
334
set vlans vlan100 description "Data VLAN"
335
'''
336
elif model.startswith('SRX'):
337
# SRX firewall specific configuration
338
config = f'''
339
set system host-name {hostname}-firewall
340
set security zones security-zone trust interfaces ge-0/0/1
341
set security zones security-zone untrust interfaces ge-0/0/0
342
'''
343
else:
344
# Generic router configuration
345
config = f'''
346
set system host-name {hostname}-router
347
set interfaces lo0 unit 0 family inet address 192.168.255.1/32
348
'''
349
350
print(f"Applying configuration for {model} device")
351
dev.cu.load(config, format='set')
352
dev.cu.commit(comment=f'Model-specific configuration for {model}')
353
354
dev.close()
355
```
356
357
## Types
358
359
```python { .api }
360
# Facts dictionary type
361
FactsDict = dict[str, any] # Device facts with standard and device-specific keys
362
363
# Version information type
364
VersionInfo = object # version_info class instance
365
366
# Routing engine information
367
REInfo = dict[str, dict[str, any]] # RE name to RE details mapping
368
369
# FPC information
370
FPCInfo = dict[str, dict[str, any]] # FPC slot to FPC details mapping
371
372
# Standard fact keys (commonly available)
373
StandardFactKeys = [
374
'hostname', 'model', 'serialnumber', 'version', 'personality',
375
'switch_style', 'master', 'vc_capable', 'vc_mode', 'vc_fabric',
376
'2RE', 'domain', 're_info', 'ifd_style', 'current_re', 'fpc'
377
]
378
```