How to use the command 'gnmic set' (with examples)

How to use the command 'gnmic set' (with examples)

The gnmic set command is a powerful tool used for interacting with gNMI-enabled network devices, allowing users to modify the device configuration directly. This command facilitates various configuration tasks such as updating, replacing, or deleting specific values in a network device’s configuration, making it highly useful for network administrators and engineers who need to maintain and manage network devices efficiently.

Use case 1: Update the value of a path

Code:

gnmic --address ip:port set --update-path path --update-value value

Motivation:

Updating a specific configuration value on a network device is commonplace for network administrators. Suppose you have a network device where you need to modify a particular parameter, such as changing the bandwidth of a link or updating an IP address. This command allows you to precisely target and update the desired configuration without altering other parts of the device settings.

Explanation:

  • --address ip:port: Specifies the IP address and port of the gNMI-enabled network device you want to connect to. This is the unique identifier where the command needs to be executed.
  • set: Invokes the set operation, indicating you’re going to make changes to the configuration.
  • --update-path path: Defines the specific path in the device’s configuration that you wish to update.
  • --update-value value: Provides the new value that you want to set at the specified path.

Example Output:

Executing this command successfully should yield a confirmation message like “Update successful at path [specified-path] with value [specified-value]”, reassuring that the configuration change has been made.

Use case 2: Update the value of a path to match the contents of a JSON file

Code:

gnmic -a ip:port set --update-path path --update-file filepath

Motivation:

For complex configurations involving multiple parameters, it is often more efficient to prepare all details in a structured format, such as a JSON file. This enables administrators to verify and replicate configuration changes with accuracy and ease. Using a JSON file allows for batch updates and ensures consistency across configurations.

Explanation:

  • -a ip:port: Shorthand version of --address, specifying the network device connection details.
  • set: Commands the system to prepare for a configuration change on the device.
  • --update-path path: Identifies the exact location in the configuration that needs updating.
  • --update-file filepath: Points to the JSON file that contains the new configuration data. This file’s content will overwrite the current configuration at the specified path.

Example Output:

The response will typically indicate “Update applied using file [filepath] at path [path]”, confirming that the JSON file was used to update the configuration successfully.

Use case 3: Replace the value of a path to match the contents of a JSON file

Code:

gnmic -a ip:port set --replace-path path --replace-file filepath

Motivation:

In scenarios where you need to completely overwrite an existing configuration segment, using a replace operation is ideal. If a configuration error is detected or if a device needs to be updated with a company-wide standard configuration, this method ensures that the old settings are entirely superseded by the new, accurate data from the JSON file.

Explanation:

  • -a ip:port: Specifies the target device’s address details.
  • set: Indicates the intention to modify the device settings.
  • --replace-path path: Signals the path where the configuration will be wholly replaced.
  • --replace-file filepath: Specifies the file source of the new configuration data, which will replace the existing settings.

Example Output:

Upon completion, the output might read “Replacement complete at path [path] using file [filepath]”, confirming the successful replacement of configuration values.

Use case 4: Delete the node at a given path

Code:

gnmic -a ip:port set --delete path

Motivation:

There are circumstances where removing a configuration node is necessary — for instance, decommissioning a feature that’s no longer needed or adjusting settings to prevent a conflict. This command allows administrators to efficiently excise unwanted or redundant configurations without manually editing configuration files on the device itself.

Explanation:

  • -a ip:port: Connects to the desired network device.
  • set: Prepares for modifying the current configuration.
  • --delete path: Identifies the specific configuration node or path to be deleted. This action helps in cleaning up or rearranging configurations as needed.

Example Output:

The command will typically return a message such as “Node [path] deleted successfully”, confirming that the specified configuration node has been removed.

Conclusion:

The gnmic set command is a comprehensive tool for managing network device configurations via gNMI, allowing for updates, replacements, and deletions with precision. Whether you’re applying new configurations through JSON files or directly updating specific paths, this command offers flexibility and efficiency. It’s essential for network professionals who maintain, update, and optimize network operations.

Related Posts

How to Use the Command 'raspinfo' (with examples)

How to Use the Command 'raspinfo' (with examples)

The raspinfo command is a convenient tool for displaying comprehensive system information about a Raspberry Pi.

Read More
How to Use the Command 'rage' (with Examples)

How to Use the Command 'rage' (with Examples)

‘rage’ is a simple, secure, and modern file encryption tool written in Rust.

Read More
Securely Removing Files with 'srm' (with Examples)

Securely Removing Files with 'srm' (with Examples)

The srm command is a powerful tool designed to securely delete files and directories by overwriting the existing data multiple times.

Read More