gNMI Get¤
Retrieve configuration or operational data using gnmi_get. Device YANG models
and Get support determine which paths are available.
Output¤
Results are keyed by host, then get. Replies contain notification
data with paths, timestamps, and values. The value structure depends on the
requested YANG tree. Serialization and failure options are described below.
Examples¤
Read an OpenConfig path:
nf# nornir gnmi get FL ceos-spine-1 path /system/config/hostname datatype config
nf# nornir gnmi get FL ceos-spine-1 openconfig-interfaces
Read an OpenConfig path:
result = client.run_job(
"nornir", "gnmi_get",
kwargs={"FL": ["ceos-spine-1"], "path": ["/system/config/hostname"], "datatype": "config"},
)
For native Junos configuration, use the juniper origin, datatype config,
and encoding json_ietf. Put the origin in either the path or the prefix.
CLI examples - read configuration sections:
nf# nornir gnmi get FL vmx-1 path juniper:/interfaces datatype config encoding json_ietf
nf# nornir gnmi get FL vmx-1 path juniper:/protocols/bgp datatype config encoding json_ietf
nf# nornir gnmi get FL vmx-1 path juniper:/system/services datatype config encoding json_ietf
Read one Junos interface using a prefix:
nf# nornir gnmi get FL vmx-1 prefix juniper:/interfaces path interface[name=ge-0/0/0] datatype config encoding json_ietf
Python examples - read configuration sections:
result = client.run_job(
"nornir", "gnmi_get",
kwargs={
"FL": ["vmx-1"],
"path": ["juniper:/interfaces", "juniper:/protocols/bgp",
"juniper:/system/services"],
"datatype": "config",
"encoding": "json_ietf",
},
)
Read one Junos interface using a prefix:
result = client.run_job(
"nornir", "gnmi_get",
kwargs={
"FL": ["vmx-1"],
"prefix": "juniper:/interfaces",
"path": ["interface[name=ge-0/0/0]"],
"datatype": "config",
"encoding": "json_ietf",
},
)
The prefix example selects the same configuration as
juniper:/interfaces/interface[name=ge-0/0/0]. Use path / with
datatype config and encoding json_ietf for the complete native Junos
configuration. OpenConfig shortcuts select a different model.
Named getters¤
Select one or more shortcuts instead of, or alongside, explicit paths.
Python uses the corresponding underscore name with True.
| CLI shortcut | Python argument | Path |
|---|---|---|
openconfig-system |
openconfig_system |
openconfig:/system |
openconfig-interfaces |
openconfig_interfaces |
openconfig:/interfaces |
openconfig-lldp |
openconfig_lldp |
openconfig:/lldp |
openconfig-platform |
openconfig_platform |
openconfig:/components |
The shortcut names identify YANG modules. openconfig is the gNMI origin.
At least one path or getter is required.
Note
OpenConfig Get requests have been validated with Arista EOS and Cisco IOS XR.
The same approach should work with any device that supports the requested
openconfig:/ path and Get operation. Available paths and encodings depend on
the device.
Read paths from a file¤
The path argument also accepts an nf:// JSON/YAML file containing a list of
paths. Use the same file for all selected devices. Write the paths directly
in the file. Templates and links to other files are not supported.
gnmi/paths.yaml:
- openconfig:/interfaces/interface[name=Loopback100]
- openconfig:/interfaces/interface[name=Loopback101]
nf# nornir gnmi get FL ceos-spine-1 path nf://gnmi/paths.yaml
gnmi/paths.yaml:
- openconfig:/interfaces/interface[name=Loopback100]
- openconfig:/interfaces/interface[name=Loopback101]
result = client.run_job(
"nornir", "gnmi_get",
kwargs={"FL": ["ceos-spine-1"], "path": "nf://gnmi/paths.yaml"},
)
Notes¤
Configure credentials, port, and TLS in the gNMI connection inventory.
Common host filters, retries, and structured processors such as jmespath apply.
Use add_details=True for error and execution details. Use to_dict=False
for a list of results. Unmatched filters return no_match. Connection and
device errors mark hosts failed.
Use prefix for a shared path prefix and target for a gNMI target name.
Encoding is chosen automatically. If you set encoding, choose a format your
device supports for Get. Subscriptions are not exposed by this task.
Troubleshooting¤
For connection errors, check the gRPC service, port, TLS, and credentials. For device errors, check the path, datatype, and encoding. Advertised capabilities do not guarantee every combination works. See Get Capabilities.
Task Command Shell Reference¤
nf#man tree nornir.gnmi.get
R - required field, M - supports multiline input, D - dynamic key
root
└── nornir: Nornir service
└── gnmi: Retrieve device data using gNMI
└── get: Retrieve configuration or state
├── timeout: Job timeout
├── workers: Filter workers to target, default 'all'
├── verbose-result: Control output details, default 'False'
├── nowait: Do not wait for job to complete, default 'False'
├── FO: Filter hosts using a Nornir-Salt Filter Object
├── FB: Filter hosts by name using glob patterns
├── FH: Filter hosts by hostname
├── FC: Filter hosts by name containment pattern
├── FR: Filter hosts by name using regular expressions
├── FG: Filter hosts by group
├── FP: Filter hosts by hostname using IP prefix
├── FL: Filter hosts by names list
├── FM: Filter hosts by platform
├── FX: Exclude hosts by name
├── FN: Negate the host filter match
├── on-failed: Run task on hosts currently marked as failed by Nornir, default 'False'
├── to-dict: Return task results as a dictionary keyed by host, default 'True'
├── add-details: Add Nornir task execution details to results, default 'False'
├── progress: Emit progress events during task execution, default 'True'
├── num-workers: RetryRunner number of threads for task execution
├── num-connectors: RetryRunner number of threads for device connections
├── connect-retry: RetryRunner number of connection attempts
├── task-retry: RetryRunner number of attempts to run each task
├── reconnect-on-fail: RetryRunner reconnects to a host after task failure
├── connect-check: RetryRunner tests TCP connectivity before opening connection
├── connect-timeout: RetryRunner TCP connection check timeout in seconds
├── creds-retry: RetryRunner connection credentials and parameters to retry
├── tf: File group name to save task results on the worker
├── tf-skip-failed: Skip failed task results when saving to file
├── diff: File group name to diff task results against
├── diff-last: Previous saved file version to diff against
├── jmespath: JMESPath expression to run with DataProcessor
├── path: YANG path or list of paths to retrieve, default '[]'
├── openconfig-system: Get the OpenConfig system tree, default 'False'
├── openconfig-interfaces: Get the OpenConfig interfaces tree, default 'False'
├── openconfig-lldp: Get the OpenConfig LLDP tree, default 'False'
├── openconfig-platform: Get the OpenConfig components tree, default 'False'
├── prefix: Common YANG path prefix, default ''
├── target: gNMI target name
├── datatype: Data type to retrieve, default 'GnmiDataType.all_'
└── encoding: Response encoding. Default negotiates with the device
nf#
Python API Reference¤
Retrieve configuration or operational state over gNMI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
Job
|
NorFab job metadata. |
required |
path
|
list[str] | str
|
YANG paths or nf:// JSON/YAML list; requires paths or a getter. |
None
|
prefix
|
str
|
Common path prefix. |
''
|
target
|
str
|
Optional gNMI target name. |
None
|
datatype
|
str
|
Data selection: all, config, state, or operational. |
'all'
|
encoding
|
str
|
Optional encoding, defaults to backend negotiation. |
None
|
openconfig_system
|
bool
|
Retrieve openconfig:/system. |
False
|
openconfig_interfaces
|
bool
|
Retrieve openconfig:/interfaces. |
False
|
openconfig_lldp
|
bool
|
Retrieve openconfig:/lldp. |
False
|
openconfig_platform
|
bool
|
Retrieve openconfig:/components. |
False
|
**kwargs
|
Any
|
Common Nornir host filters, processors, retry options, to_dict and add_details serialization options. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
Host results under get containing backend notification data. to_dict=False returns records instead. Unmatched hosts return no_match. Connection and RPC errors mark hosts failed. Device YANG models and supported encodings determine available data. Configure port, credentials and TLS in connection_options.pygnmi. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If a referenced file cannot be fetched. |
YAMLError
|
If a file contains malformed YAML/JSON. |
ValidationError
|
If file contents have an invalid payload shape. |
Source code in norfab\workers\nornir_worker\gnmi_tasks.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |