How to use the command 'gnmic set' (with examples)
The ‘gnmic set’ command is used to modify the configuration of a gnmi network device. It allows users to update, replace, or delete the values of specific paths in the device’s configuration. This can be useful for making changes to the device’s settings, provisioning new configurations, or removing unnecessary paths.
Use case 1: Update the value of a path
Code:
gnmic --address ip:port set --update-path path --update-value value
Motivation: This use case is useful when you want to update the value of a specific path in the device’s configuration. For example, you may need to change the IP address or port of a server in the configuration.
Explanation:
gnmic
: The command name.--address ip:port
: Specifies the IP address and port of the device you want to modify.set
: Specifies that we want to modify the configuration of the device.--update-path path
: Specifies the path in the configuration to be updated.--update-value value
: Specifies the new value to be assigned to the path.
Example OUTPUT:
Updated path 'path' with value 'value'.
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: This use case is useful when you have a JSON file containing the updated values you want to set in the device’s configuration. Using this command, you can easily update the value of a specific path with the contents of the JSON file.
Explanation:
gnmic
: The command name.-a ip:port
: Specifies the IP address and port of the device you want to modify.set
: Specifies that we want to modify the configuration of the device.--update-path path
: Specifies the path in the configuration to be updated.--update-file filepath
: Specifies the path to the JSON file containing the updated value.
Example OUTPUT:
Updated path 'path' with the value from file 'filepath'.
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: This use case is useful when you want to completely replace the value of a specific path in the device’s configuration with the contents of a JSON file. It allows you to easily provision new configurations by providing a JSON file containing the desired values.
Explanation:
gnmic
: The command name.-a ip:port
: Specifies the IP address and port of the device you want to modify.set
: Specifies that we want to modify the configuration of the device.--replace-path path
: Specifies the path in the configuration to be replaced.--replace-file filepath
: Specifies the path to the JSON file containing the new value.
Example OUTPUT:
Replaced path 'path' with the value from file 'filepath'.
Use case 4: Delete the node at a given path
Code:
gnmic -a ip:port set --delete path
Motivation: This use case is useful when you want to remove a specific node from the device’s configuration. It can be used to delete unnecessary paths or undo changes made previously.
Explanation:
gnmic
: The command name.-a ip:port
: Specifies the IP address and port of the device you want to modify.set
: Specifies that we want to modify the configuration of the device.--delete path
: Specifies the path of the node to be deleted.
Example OUTPUT:
Deleted node at path 'path'.
Conclusion:
The ‘gnmic set’ command provides a versatile way to modify the configuration of gnmi network devices. Whether you need to update specific values, replace entire paths, or delete nodes, this command simplifies the process and ensures consistent device configurations.