github.com/aristanetworks/goarista@v0.0.0-20240514173732-cca2755bbd44/cmd/gnmi/README.md (about)

     1  # gnmi
     2  
     3  `gnmi` is a command-line client for interacting with a
     4  [gNMI service](https://github.com/openconfig/reference/tree/master/rpc/gnmi).
     5  
     6  # Installation
     7  
     8  Compiling `gnmi` requires Go 1.16 or later. Instructions for
     9  installing Go can be found [here](https://go.dev/doc/install). Once Go
    10  is installed you can run:
    11  
    12  ```
    13  go install github.com/aristanetworks/goarista/cmd/gnmi@latest
    14  ```
    15  
    16  This will install the `gnmi` binary in the `$HOME/go/bin` directory by
    17  default. Run `go help install` for more information.
    18  
    19  # Usage
    20  
    21  ```
    22  $ gnmi [OPTIONS] [OPERATION]
    23  ```
    24  
    25  When running on the switch in a non-default VRF:
    26  
    27  ```
    28  $ ip netns exec ns-<VRF> gnmi [OPTIONS] [OPERATION]
    29  ```
    30  
    31  ## Options
    32  
    33  * `-addr [<VRF-NAME>/]ADDR:PORT`  
    34  Address of the gNMI endpoint (REQUIRED) with VRF name (OPTIONAL)
    35  * `-username USERNAME`  
    36  Username to authenticate with
    37  * `-password PASSWORD`  
    38  Password to authenticate with
    39  * `-tls`  
    40  Enable TLS
    41  * `-cafile PATH`  
    42  Path to server TLS certificate file
    43  * `-certfile PATH`  
    44  Path to client TLS certificate file
    45  * `-keyfile PATH`  
    46  Path to client TLS private key file
    47  
    48  ## Operations
    49  
    50  `gnmi` supports the following operations: `capabilites`, `get`,
    51  `subscribe`, `update`, `replace`, `delete`, and `union_replace`.
    52  
    53  ### capabilities
    54  
    55  `capabilities` prints the result of calling the
    56  [Capabilities gNMI RPC](https://github.com/openconfig/reference/blob/master/rpc/gnmi/gnmi-specification.md#32-capability-discovery).
    57  
    58  Example:
    59  
    60  ```
    61  $ gnmi [OPTIONS] capabilities
    62  ```
    63  
    64  ### get
    65  
    66  `get` requires a path and calls the
    67  [Get gNMI RPC](https://github.com/openconfig/reference/blob/master/rpc/gnmi/gnmi-specification.md#222-paths).
    68  
    69  Example:
    70  
    71  Get all configuration in the default network instance:
    72  ```
    73  $ gnmi [OPTIONS] get '/network-instances/network-instance[name=default]'
    74  ```
    75  
    76  ### subscribe
    77  
    78  `subscribe` requires a path and calls the
    79  [Subscribe gNMI RPC](https://github.com/openconfig/reference/blob/master/rpc/gnmi/gnmi-specification.md#35-subscribing-to-telemetry-updates).
    80  This command will continuously print out results until signalled to
    81  exit, for example by typing `Ctrl-C`.
    82  
    83  Example:
    84  
    85  Subscribe to interface counters:
    86  ```
    87  $ gnmi [OPTIONS] subscribe '/interfaces/interface[name=*]/state/counters'
    88  ```
    89  
    90  ### update/replace/delete/union_replace
    91  
    92  `update`, `replace`, `delete`, and `union_replace` are used to
    93  [modify the configuration of a gNMI endpoint](https://github.com/openconfig/reference/blob/master/rpc/gnmi/gnmi-specification.md#34-modifying-state).
    94  All of these operations take a path that must specify a single node
    95  element. In other words all list members must be fully-specified.
    96  
    97  `delete` takes a path and will delete that path.
    98  
    99  Example:
   100  
   101  Delete BGP configuration in the default network instance:
   102  ```
   103  $ gnmi [OPTIONS] delete '/network-instances/network-instance[name=default]/protocols/protocol[name=BGP][identifier=BGP]/'
   104  ```
   105  
   106  `update`, `replace`, and `union_replace` take a path and a value in JSON
   107  format. The JSON data may be provided in a file. See
   108  [here](https://github.com/openconfig/reference/blob/master/rpc/gnmi/gnmi-specification.md#344-modes-of-update-union-replace-replace-and-update)
   109  for documentation on the differences between `update`, `replace`, and `union_replace`.
   110  
   111  Examples:
   112  
   113  Disable interface Ethernet3/42:
   114  ```
   115  gnmi [OPTIONS] update '/interfaces/interface[name=Ethernet3/42]/config/enabled' 'false'
   116  ```
   117  
   118  Replace the BGP global configuration:
   119  ```
   120  gnmi [OPTIONS] replace '/network-instances/network-instance[name=default]/protocols/protocol[name=BGP][identifier=BGP]/bgp/global' '{"config":{"as": 1234, "router-id": "1.2.3.4"}}'
   121  ```
   122  
   123  Note: String values need to be quoted if they look like JSON. For example, setting the login banner to `tor[13]`:
   124  ```
   125  gnmi [OPTIONS] update '/system/config/login-banner '"tor[13]"'
   126  ```
   127  
   128  #### JSON in a file
   129  
   130  The value argument to `update`, `replace`, and `union_replace` may be a file. The
   131  content of the file is used to make the request.
   132  
   133  Example:
   134  
   135  File `path/to/subintf100.json` contains the following:
   136  
   137  ```
   138  {
   139    "subinterface": [
   140      {
   141        "config": {
   142          "enabled": true,
   143          "index": 100
   144        },
   145        "index": 100
   146      }
   147    ]
   148  }
   149  ```
   150  
   151  Add subinterface 100 to interfaces Ethernet4/1/1 and Ethernet4/2/1 in
   152  one transaction:
   153  
   154  ```
   155  gnmi [OPTIONS] update '/interfaces/interface[name=Ethernet4/1/1]/subinterfaces' path/to/subintf100.json \
   156                 update '/interfaces/interface[name=Ethernet4/2/1]/subinterfaces' path/to/subintf100.json
   157  ```
   158  
   159  ### CLI requests
   160  `gnmi` offers the ability to send CLI text inside an `update`, `replace`, or
   161  `union_replace` operation. This is achieved by doing an `update`, `replace`, or
   162  `union_replace` and specifying `"origin=cli"` along with an empty path and a set of configure-mode
   163  CLI commands separated by `\n`.
   164  
   165  Example:
   166  
   167  Configure the idle-timeout on SSH connections
   168  ```
   169  gnmi [OPTIONS] update 'origin=cli' "" 'management ssh
   170  idle-timeout 300'
   171  ```
   172  
   173  ### P4 Config
   174  `gnmi` offers the ability to send p4 config files inside a `replace` operation.
   175  This is achieved by doing a `replace` and specifying `"origin=p4_config"`
   176  along with the path of the p4 config file to send.
   177  
   178  Example:
   179  
   180  Send the config.p4 file
   181  ```
   182  gnmi [OPTIONS] replace 'origin=p4_config' 'config.p4'
   183  ```
   184  
   185  ## Paths
   186  
   187  Paths in `gnmi` use a simplified xpath style. Path elements are
   188  separated by `/`. Selectors may be used on list to select certain
   189  members. Selectors are of the form `[key-leaf=value]`. All members of a
   190  list may be selected by not specifying any selectors, or by using a
   191  `*` as the value in a selector. The following are equivalent:
   192  
   193  * `/interfaces/interface`
   194  * `/interfaces/interface[name=*]`
   195  
   196  All characters, including `/` are allowed inside a selector value. The
   197  character `]` must be escaped, for example `[key=[\]]` selects the
   198  element in the list whose `key` leaf is value `[]`.
   199  
   200  See more examples of paths in the examples above.
   201  
   202  See
   203  [here](https://github.com/openconfig/reference/blob/master/rpc/gnmi/gnmi-specification.md#222-paths)
   204  for more information.