gnmic-set
Modify network device configuration using gNMI
TLDR
Update the value of a path
Update the value of a path to match the contents of a JSON file
Replace the value of a path to match the contents of a JSON file
Delete the node at a given path
SYNOPSIS
gnmic [GLOBAL_OPTIONS] set [SET_OPTIONS] [PATH_OR_FILE_ARGUMENTS]
Examples:
gnmic --target device-ip:port --username user --password pass set --update /system/motd-banner="Welcome" --encoding JSON
gnmic --config config.yaml set --replace /system/name="new-router-name" --file config_payload.json
gnmic set --delete /interfaces/interface[name=ethernet0/1]/config/description
PARAMETERS
--update
Adds or modifies a configuration element at the specified path. If value is provided, it sets the value; otherwise, it requires a subsequent --value flag or a file-based input. Can be used multiple times.
--replace
Atomically replaces the configuration at the specified path with new content. If value is provided, it sets the value; otherwise, it requires a subsequent --value flag or a file-based input. Can be used multiple times.
--delete
Removes the configuration element or subtree at the specified path. Can be used multiple times.
--value
Specifies the value for the preceding --update or --replace operation. This is useful for simple key-value sets.
--file
Reads a gNMI SetRequest payload from the specified file. The file typically contains JSON or YAML representing the update, replace, or delete operations.
--encoding
Specifies the gNMI encoding type for the request (e.g., JSON, PROTO, ASCII, BYTES). Defaults to JSON if not specified.
--dry-run
Prints the generated gNMI SetRequest without actually sending it to the target. Useful for debugging and verification.
--skip-verify
Skips schema verification before sending the request. Use with caution as it might lead to malformed requests.
--no-sync
Do not wait for a gNMI SyncResponse, even if the target supports it. This makes the operation non-blocking.
--qos
Sets the Differentiated Services Code Point (DSCP) for the gNMI request, influencing network prioritization.
--target
(Global) Specifies the gNMI target address and port (e.g., 192.168.1.1:50051). This is a mandatory global option for most operations.
--username
(Global) Username for authenticating with the gNMI target.
--password
(Global) Password for authenticating with the gNMI target.
--tls-ca
(Global) Path to the CA certificate file for TLS validation.
--tls-cert
(Global) Path to the client certificate file for mutual TLS authentication.
--tls-key
(Global) Path to the client private key file for mutual TLS authentication.
DESCRIPTION
gnmic-set is a crucial subcommand of the gnmic CLI client, designed to interact with network devices using the gNMI (gRPC Network Management Interface) protocol. It specifically implements the gNMI Set RPC, enabling users to programmatically modify configuration and state on compliant network elements.
The command supports three primary operations: update, replace, and delete. Update adds or modifies a configuration element at a specified path. Replace atomically replaces all configuration under a given path with new content, effectively performing a full overwrite. Delete removes a configuration element or subtree. These operations can be supplied as individual path-value pairs directly on the command line or as a structured gNMI SetRequest payload provided in JSON or YAML format via a file.
gnmic-set is widely used in network automation scripts, CI/CD pipelines, and for ad-hoc configuration changes, offering a powerful, standardized, and vendor-agnostic way to manage network infrastructure. It leverages gnmic's global options for target connectivity, authentication, and secure communication (TLS).
CAVEATS
- Target Support: The target device must be gNMI-enabled and support the specific paths and data models being manipulated.
- Permissions: The authenticated user must have appropriate write permissions on the target device for the requested paths.
- Schema Adherence: All modification requests must conform to the target's YANG schema; malformed requests will be rejected by the device.
- Atomicity: While a single gNMI Set RPC can contain multiple operations (update, replace, delete), the target's behavior regarding atomicity (all or nothing) for these combined operations can vary by vendor implementation.
UNDERSTANDING SET OPERATIONS
The gNMI Set RPC, implemented by gnmic-set, supports distinct modification types:
- Update: Merges new configuration into existing configuration. If a leaf exists, its value is changed; if not, it's created. Non-specified leaves or containers remain untouched.
- Replace: Overwrites the existing configuration at a given path entirely. Any configuration elements under that path not specified in the replace payload will be removed. This is often used for atomic full configuration pushes.
- Delete: Removes the configuration subtree or leaf at the specified path. If the path does not exist, the operation typically succeeds without error.
INPUT FORMATS
gnmic-set offers flexibility in how the SetRequest payload is provided:
- Command-line Arguments: For simple operations, paths and values can be directly specified using --update, --replace, --delete, and --value flags.
- File Input: For complex or large configurations, the --file flag allows reading the gNMI SetRequest from a JSON or YAML file. This file directly represents the `update`, `replace`, and `delete` fields within the gNMI SetRequest protobuf message.
HISTORY
The gnmic project, including its set subcommand, emerged as a vital tool within the OpenConfig and gNMI ecosystem. As network devices increasingly adopted gNMI for programmatic interaction, a robust command-line client was necessary to facilitate direct configuration management. gnmic-set was a core component from early versions, designed to provide a standardized, scriptable, and human-readable interface for modifying network state. Its development paralleled the growth of network automation and the shift from traditional CLI-based management to API-driven approaches, positioning gnmic-set as a cornerstone for modern network programmability.
SEE ALSO
gnmic(1), gnmic-get(1), gnmic-subscribe(1), gnmic-capabilities(1)