RESTCONF GET¤
Read device configuration or operational data with restconf_get. Use a RESTCONF resource
path to retrieve only the information you need, or select a predefined getter to read
a supported OpenConfig subtree without specifying a path.
Output¤
Each host's reply appears under get. JSON responses become structured data. Other responses
remain text. Successful operations may return an empty string. Connection and device errors mark
hosts failed. add_details=True includes execution details. to_dict=False returns list records.
{
"ceos-spine-1": {
"get": {
"openconfig-system:hostname": "ceos-spine-1"
}
}
}
Supported Getters¤
Getters are predefined RESTCONF resource shortcuts. The selected device must support the corresponding YANG data model. A shortcut does not translate between vendor models.
| Getter | Description |
|---|---|
openconfig-interfaces |
Interface configuration, state and counters under openconfig-interfaces:interfaces. |
openconfig-lldp |
LLDP configuration and neighbor state under openconfig-lldp:lldp. |
openconfig-system |
System configuration and operational state under openconfig-system:system. |
Select only one getter or explicit url per request. False flags do not count.
Unsupported models produce the device's response or a failed host result. No automatic
vendor fallback is performed. Replies retain the device model structure under get.
CLI flags use hyphens. Python and FastAPI arguments use underscores, for example
openconfig_lldp. Subtrees follow the
OpenConfig models.
Examples¤
Read a resource path¤
nf# nornir restconf get FL ceos-spine-1 url openconfig-system:system/state/hostname
result = client.run_job(
"nornir",
"restconf_get",
workers="nornir-worker-1",
kwargs={
"FL": ["ceos-spine-1"],
"url": "openconfig-system:system/state/hostname",
},
)
Replace the address and token with those of your FastAPI service.
Python requests
import requests
response = requests.post(
"http://localhost:8000/api/nornir/restconf_get/",
headers={"Authorization": "Bearer YOUR_TOKEN"},
json={
"workers": "nornir-worker-1",
"FL": ["ceos-spine-1"],
"url": "openconfig-system:system/state/hostname",
},
timeout=60,
)
response.raise_for_status()
print(response.json())
curl
curl -X POST 'http://localhost:8000/api/nornir/restconf_get/' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
--data '{
"workers": "nornir-worker-1",
"FL": [
"ceos-spine-1"
],
"url": "openconfig-system:system/state/hostname"
}'
Use the NorFab Nornir RESTCONF get tool to read the hostname of ceos-spine-1.
Show the returned hostname.
Use a predefined getter¤
This example retrieves OpenConfig interfaces. Use openconfig-lldp or
openconfig-system in CLI, or openconfig_lldp=True or openconfig_system=True
in Python, to select another getter. FastAPI JSON uses lowercase true.
nf# nornir restconf get FL ceos-spine-1 openconfig-interfaces
result = client.run_job(
"nornir",
"restconf_get",
workers="nornir-worker-1",
kwargs={
"FL": ["ceos-spine-1"],
"openconfig_interfaces": True,
},
)
Replace the address and token with those of your FastAPI service.
Python requests
import requests
response = requests.post(
"http://localhost:8000/api/nornir/restconf_get/",
headers={"Authorization": "Bearer YOUR_TOKEN"},
json={
"workers": "nornir-worker-1",
"FL": ["ceos-spine-1"],
"openconfig_interfaces": True,
},
timeout=60,
)
response.raise_for_status()
print(response.json())
curl
curl -X POST 'http://localhost:8000/api/nornir/restconf_get/' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
--data '{
"workers": "nornir-worker-1",
"FL": [
"ceos-spine-1"
],
"openconfig_interfaces": true
}'
Use the NorFab Nornir RESTCONF get tool with the OpenConfig interfaces getter
to read interface configuration and state from ceos-spine-1.
Notes¤
Configure the device endpoint, credentials, TLS verification, HTTP timeout and default headers in
HTTP inventory. Relative resource
paths use its RESTCONF base URL. Use params for query parameters and headers when a request
needs different headers. Supplied headers replace the inventory mapping.
The CLI timeout controls waiting for the NorFab job. Device requests use the configured Nornir
runner, including its retry settings. Review those settings before configuration changes.
Task Command Shell Reference¤
nf# man tree nornir.restconf.get
Python API Reference¤
Read a RESTCONF resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
Job
|
NorFab job metadata. |
required |
url
|
str
|
Literal resource relative to inventory base_url, or absolute URL. |
None
|
params
|
dict[str, Any]
|
HTTP query parameters. |
None
|
headers
|
dict[str, str]
|
HTTP headers replacing inventory headers when supplied. |
None
|
openconfig_interfaces
|
bool
|
Retrieve OpenConfig interfaces configuration and state. Defaults to false. Select only one getter or url. Requires device support for the OpenConfig interfaces model. |
False
|
openconfig_lldp
|
bool
|
Retrieve the OpenConfig LLDP subtree. Defaults to false. Requires device model support. Select only one getter or url. |
False
|
openconfig_system
|
bool
|
Retrieve the OpenConfig system subtree. Defaults to false. Requires device model support. Select only one getter or url. |
False
|
**kwargs
|
Any
|
Common Nornir host filters, processors, runner and result options. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
Per-host response payloads keyed by the HTTP verb, or list records. HTTP failures remain failed host results; no_match means no selected hosts. |
Source code in norfab\workers\nornir_worker\restconf_task.py
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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |