google gNMI Protocol Version 0.4.0 — Connecting the gNMI Client

Device# show gnxi state State Status -------------------------------- Enabled Up Connecting the gNMI Client The gNMI client is connected by using the client and root certificates that are previously configured. The following example shows how to connect the gNMI client using Python: # gRPC Must be compiled in local dir under path below: >>> import sys >>> sys.path.insert(0, "reference/rpc/gnmi/") >>> import grpc >>> import gnmi_pb2 >>> import gnmi_pb2_grpc >>> gnmi_dir = '/path/to/where/openssl/creds/were/generated/' # Certs must be read in as bytes >>> with open(gnmi_dir + 'rootCA.pem', 'rb') as f: >>> ca_cert = f.read() >>> with open(gnmi_dir + 'client.crt', 'rb') as f:

>>> client_cert = f.read() >>> with open(gnmi_dir + 'client.key', 'rb') as f: >>> client_key = f.read() # Create credentials object >>> credentials = grpc.ssl_channel_credentials(root_certificates=ca_cert, private_key=client_key, certificate_chain=client_cert) # Create a secure channel: # Default port is 9339, can be changed on ios device with 'gnxi secure-port ####' >>> port = 9339 >>> host = FQDN> >>> secure_channel = grpc.secure_channel("%s:%d" % (host, port), credentials) # Create secure stub: >>> secure_stub = gnmi_pb2_grpc.gNMIStub(secure_channel) # Done! Let's test to make sure it works:

>>> secure_stub.Capabilities(gnmi_pb2.CapabilityRequest()) supported_models { } supported_encodings: gNMI_version: "0.4.0" gNMI Protocol Connecting the gNMI Client gNMI Protocol 19