How to use the command gnmic (with examples)

How to use the command gnmic (with examples)

The gnmic command is a gNMI (gRPC Network Management Interface) command-line client that allows users to manage gNMI network device configuration and view operational data. It provides a convenient way to interact with network devices using the gNMI protocol.

Use case 1: Request device capabilities

Code:

gnmic --address ip:port capabilities

Motivation: By requesting device capabilities, users can obtain information about the supported features and functionality of a network device. This information is crucial for developing network management applications or troubleshooting network issues.

Explanation:

  • --address ip:port: Specifies the IP address and port number of the target network device.
  • capabilities: Indicates the command to request device capabilities.

Example output:

Device Capabilities:
- gNMI Version: 1.1.0
- Supported Encodings: JSON_IETF, PROTO
- Supported Models: cisco-xe-1.0.0, ietf-interfaces, ietf-ip, openconfig-acl, openconfig-bgp, openconfig-interfaces, openconfig-routing-policy, openconfig-types
- Supported Operations: GET, SET

Use case 2: Provide a username and password to fetch device capabilities

Code:

gnmic --address ip:port --username username --password password capabilities

Motivation: Some network devices require authentication to access their capabilities. By providing a username and password, users can authenticate themselves and fetch the device capabilities successfully.

Explanation:

  • --address ip:port: Specifies the IP address and port number of the target network device.
  • --username username: Specifies the username for authentication.
  • --password password: Specifies the password for authentication.
  • capabilities: Indicates the command to request device capabilities.

Example output:

Device Capabilities:
- gNMI Version: 1.1.0
- Supported Encodings: JSON_IETF, PROTO
- Supported Models: cisco-xe-1.0.0, ietf-interfaces, ietf-ip, openconfig-acl, openconfig-bgp, openconfig-interfaces, openconfig-routing-policy, openconfig-types
- Supported Operations: GET, SET

Use case 3: Get a snapshot of the device state at a specific path

Code:

gnmic -a ip:port get --path path

Motivation: By getting a snapshot of the device state at a specific path, users can retrieve the current values of the specified data from the network device. This can be useful for monitoring, troubleshooting, or collecting data for analysis.

Explanation:

  • -a ip:port: Specifies the IP address and port number of the target network device.
  • get: Indicates the command to retrieve device state.
  • --path path: Specifies the specific path from which to retrieve the device state.

Example output:

Current Device State:
- Path: /interfaces/interface[name=eth0]/state/oper-status
  - Value: up
- Path: /interfaces/interface[name=eth1]/state/oper-status
  - Value: down

Use case 4: Update device state at a specific path

Code:

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

Motivation: Once users have identified a specific path within the device state that requires modification, they can use this command to update the value at that path. This allows users to configure network devices or change their operational state.

Explanation:

  • -a ip:port: Specifies the IP address and port number of the target network device.
  • set: Indicates the command to update device state.
  • --update-path path: Specifies the specific path within the device state to be updated.
  • --update-value value: Specifies the new value to be set at the specified path.

Example output:

Device State Updated:
- Path: /interfaces/interface[name=eth0]/config/mtu
  - Old Value: 1500
  - New Value: 9000

Use case 5: Subscribe to target state updates under the subtree at a specific path

Code:

gnmic -a ip:port subscribe --path path

Motivation: By subscribing to target state updates, users can receive real-time updates of the specified data from the network device. This can be useful for monitoring changes, detecting events, or triggering actions based on specific conditions.

Explanation:

  • -a ip:port: Specifies the IP address and port number of the target network device.
  • subscribe: Indicates the command to subscribe to target state updates.
  • --path path: Specifies the specific path to the subtree under which the updates should be monitored.

Example output:

Target State Updates:
- Path: /bgp/peers/peer[address=10.0.0.1]/state/established
  - Value: true
- Path: /bgp/peers/peer[address=10.0.0.2]/state/established
  - Value: true

Conclusion:

The gnmic command provides a versatile and powerful way to interact with network devices using the gNMI protocol. Whether it is retrieving device capabilities, fetching device state, updating configuration, or subscribing to real-time updates, gnmic offers the necessary features to efficiently manage gNMI-compliant network devices.

Related Posts

Managing Salt Minion Keys with salt-key (with examples)

Managing Salt Minion Keys with salt-key (with examples)

Introduction SaltStack is a powerful open-source automation tool used for managing infrastructure and configuration.

Read More
How to use the command cloudd (with examples)

How to use the command cloudd (with examples)

The cloudd command is used to back the CloudKit feature. It is not meant to be invoked manually, but instead should be run automatically by the system.

Read More
How to use the command `f3write` (with examples)

How to use the command `f3write` (with examples)

f3write is a command-line tool that allows users to write test files to a given directory in order to fill a drive and test its real capacity.

Read More