You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+107-1Lines changed: 107 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -14,13 +14,119 @@ This library covers the gNMI defined `capabilities`, `get`, `set`, and `subscrib
14
14
15
15
It is *highly* recommended that users of the library learn [Google Protocol Buffers](https://developers.google.com/protocol-buffers/) syntax to significantly ease usage. Understanding how to read Protocol Buffers, and reference [`gnmi.proto`](https://github.com/openconfig/gnmi/blob/master/proto/gnmi/gnmi.proto), will be immensely useful for utilizing gNMI and any other gRPC interface.
16
16
17
+
### ClientBuilder
18
+
Since `v1.0.0` a builder pattern is available with `ClientBuilder`. `ClientBuilder` provides several `set_*` methods which define the intended `Client` connectivity and a `construct` method to construct and return the desired `Client`. There are several major methods involved here:
19
+
20
+
```
21
+
set_target(...)
22
+
Specifies the network element to build a client for.
23
+
set_os(...)
24
+
Specifies which OS wrapper to deliver.
25
+
set_secure(...)
26
+
Specifies that a secure gRPC channel should be used.
27
+
set_secure_from_file(...)
28
+
Loads certificates from file system for secure gRPC channel.
29
+
set_secure_from_target(...)
30
+
Attempts to utilize available certificate from target for secure gRPC channel.
31
+
set_call_authentication(...)
32
+
Specifies username/password to utilize for authentication.
33
+
set_ssl_target_override(...)
34
+
Sets the gRPC option to override the SSL target name.
35
+
set_channel_option(...)
36
+
Sets a gRPC channel option. Implies knowledge of channel options.
37
+
construct()
38
+
Constructs and returns the built Client.
39
+
```
40
+
41
+
#### Initialization Examples
42
+
`ClientBuilder` can be chained for initialization or instantiated line-by-line.
Using an owned root certificate on the filesystem:
72
+
73
+
```python
74
+
from cisco_gnmi import ClientBuilder
75
+
76
+
client = ClientBuilder(
77
+
'127.0.0.1:9339'
78
+
).set_os('IOS XR').set_secure_from_file(
79
+
'ems.pem'
80
+
).set_call_authentication(
81
+
'admin',
82
+
'its_a_secret'
83
+
).construct()
84
+
```
85
+
86
+
Passing certificate content to method:
87
+
88
+
```python
89
+
from cisco_gnmi import ClientBuilder
90
+
91
+
# Note reading as bytes
92
+
withopen('ems.pem', 'rb') as cert_fd:
93
+
root_cert = cert_fd.read()
94
+
95
+
client = ClientBuilder(
96
+
'127.0.0.1:9339'
97
+
).set_os('IOS XR').set_secure(
98
+
root_cert
99
+
).set_call_authentication(
100
+
'admin',
101
+
'its_a_secret'
102
+
).construct()
103
+
```
104
+
105
+
Usage with root certificate, private key, and cert chain:
106
+
107
+
```python
108
+
from cisco_gnmi import ClientBuilder
109
+
110
+
client = ClientBuilder(
111
+
'127.0.0.1:9339'
112
+
).set_os('IOS XR').set_secure_from_file(
113
+
root_certificates='rootCA.pem',
114
+
private_key='client.key',
115
+
certificate_chain='client.crt',
116
+
).set_call_authentication(
117
+
'admin',
118
+
'its_a_secret'
119
+
).construct()
120
+
```
121
+
122
+
17
123
### Client
18
124
`Client` is a very barebones class simply implementing `capabilities`, `get`, `set`, and `subscribe` methods. It provides some context around the expectation for what should be supplied to these RPC functions and helpers for validation.
19
125
20
126
Methods are documented in [`src/cisco_gnmi/client.py`](src/cisco_gnmi/client.py).
21
127
22
128
### XRClient
23
-
`XRClient` inherets from `Client` and provides several wrapper methods which aid with IOS XR-specific behaviors of the gNMI implementation. These are `delete_xpaths`, `get_xpaths`, `set_json`, and `subscribe_xpaths`. These methods make several assumptions about what kind of information will be supplied to them in order to simplify usage of the gNMI RPCs.
129
+
`XRClient` inherets from `Client` and provides several wrapper methods which aid with IOS XR-specific behaviors of the gNMI implementation. These are `delete_xpaths`, `get_xpaths`, `set_json`, and `subscribe_xpaths`. These methods make several assumptions about what kind of information will be supplied to them in order to simplify usage of the gNMI RPCs, detailed in the documentation.
24
130
25
131
Methods are documented in [`src/cisco_gnmi/xr.py`](src/cisco_gnmi/xr.py).
0 commit comments