Skip to content

Config & tools

Reading the configuration, raw CLI access, and on-device reachability tools.

get_config

device.get_config(retrieve="all", sanitized=False, format="text")

Returns the running configuration — by default as a JSON document, straight from the running datastore:

device.get_config(retrieve="running")                  # JSON string
device.get_config(retrieve="running", sanitized=True)  # aaa/tls subtrees removed

Prefer flat CLI commands? Pass format="cli" per call, or set the running_format optional argument to make it the default — the output is then equivalent to info flat:

device.get_config(retrieve="running", format="cli")
set / interface ethernet-1/1 admin-state enable
set / interface ethernet-1/1 subinterface 0 ipv4 admin-state enable
set / interface ethernet-1/1 subinterface 0 ipv4 address 10.0.0.1/30
...

Two notes:

  • sanitized=True (strips aaa and tls secrets) is only available with the JSON format.
  • retrieve="candidate" and retrieve="startup" return "" — the candidate exists only client-side, and the startup config is not exposed via JSON-RPC.

cli

device.cli(commands, encoding="text")

Runs arbitrary CLI commands through the JSON-RPC cli method and returns the output per command:

=== "text"

```python
>>> device.cli(["show version"])
{"show version": "--------------------------------------\nHostname  : srl1\nChassis Type : 7220 IXR-D2L\n..."}
```

=== "json"

```python
>>> device.cli(["show version"], encoding="json")
{"show version": {"basic system info": {"Hostname": "srl1", "Chassis Type": "7220 IXR-D2L", ...}}}
```

With encoding="json" you get SR Linux's structured output instead of rendered text — usually much nicer to post-process than parsing CLI screens. Each command is sent as its own request, so the per-command mapping in the result is always exact.

ping

device.ping(destination, source="", ttl=255, timeout=2,
            size=100, count=5, vrf="", source_interface="")

Pings from the device. vrf selects the network-instance the ping runs in — for management-network targets that's typically vrf="mgmt".

device.ping("172.20.20.1", vrf="mgmt")
Example output
{
    "success": {
        "probes_sent": 5,
        "packet_loss": 0,
        "rtt_min": 2.923,
        "rtt_avg": 3.326,
        "rtt_max": 3.477,
        "rtt_stddev": 0.203,
        "results": [
            {"ip_address": "8.8.8.8", "rtt": 3.48},
            {"ip_address": "8.8.8.8", "rtt": 3.43},
            {"ip_address": "8.8.8.8", "rtt": 2.92},
            {"ip_address": "8.8.8.8", "rtt": 3.41},
            {"ip_address": "8.8.8.8", "rtt": 3.39}
        ]
    }
}

traceroute

device.traceroute(destination, ttl=255, vrf="")

Traceroute from the device, per network-instance via vrf. SR Linux's traceroute does not support the source and timeout options; they are accepted for API compatibility but ignored.

Example output
{
    "success": {
        1: {
            "probes": {
                1: {"rtt": 3.029, "ip_address": "8.8.8.8", "host_name": "8.8.8.8"},
                2: {"rtt": 3.001, "ip_address": "8.8.8.8", "host_name": "8.8.8.8"},
                3: {"rtt": 2.988, "ip_address": "8.8.8.8", "host_name": "8.8.8.8"}
            }
        }
    }
}

Changing configuration

Everything about writing config — the candidate workflow, accepted formats, commit, rollback, and confirmed commits — lives in the user guide: