Skip to content

Commit ef247c8

Browse files
committed
Adding NX support
1 parent 466b36b commit ef247c8

File tree

3 files changed

+64
-11
lines changed

3 files changed

+64
-11
lines changed

src/cisco_gnmi/builder.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,61 @@ def construct(self):
271271
"""Constructs and returns the desired Client object.
272272
The instance of this class will reset to default values for further building.
273273
274+
Returns
275+
-------
276+
Client or NXClient or XEClient or XRClient
277+
"""
278+
channel = None
279+
channel_ssl_creds = None
280+
channel_metadata_creds = None
281+
channel_creds = None
282+
channel_ssl_creds = None
283+
if any((self.__root_certificates, self.__private_key, self.__certificate_chain)):
284+
channel_ssl_creds = grpc.ssl_channel_credentials(
285+
self.__root_certificates, self.__private_key, self.__certificate_chain
286+
)
287+
if self.__username and self.__password:
288+
channel_metadata_creds = grpc.metadata_call_credentials(
289+
CiscoAuthPlugin(self.__username, self.__password)
290+
)
291+
logging.debug("Using username/password call authentication.")
292+
if channel_ssl_creds and channel_metadata_creds:
293+
channel_creds = grpc.composite_channel_credentials(
294+
channel_ssl_creds, channel_metadata_creds
295+
)
296+
logging.debug("Using SSL/metadata authentication composite credentials.")
297+
elif channel_ssl_creds:
298+
channel_creds = channel_ssl_creds
299+
logging.debug("Using SSL credentials, no metadata authentication.")
300+
if channel_creds:
301+
if self.__ssl_target_name_override is not False:
302+
if self.__ssl_target_name_override is None:
303+
if not self.__root_certificates:
304+
raise Exception("Deriving override requires root certificate!")
305+
self.__ssl_target_name_override = get_cn_from_cert(
306+
self.__root_certificates
307+
)
308+
logging.warning(
309+
"Overriding SSL option from certificate could increase MITM susceptibility!"
310+
)
311+
self.set_channel_option(
312+
"grpc.ssl_target_name_override", self.__ssl_target_name_override
313+
)
314+
channel = grpc.secure_channel(
315+
self.__target_netloc.netloc, channel_creds, self.__channel_options
316+
)
317+
else:
318+
channel = grpc.insecure_channel(self.__target_netloc.netloc)
319+
if self.__client_class is None:
320+
self.set_os()
321+
client = self.__client_class(channel)
322+
self._reset()
323+
return client
324+
325+
def save_construct(self):
326+
"""Constructs and returns the desired Client object.
327+
The instance of this class will reset to default values for further building.
328+
274329
Returns
275330
-------
276331
Client or NXClient or XEClient or XRClient

src/cisco_gnmi/client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ def set(
217217
request.extension.extend(extensions)
218218

219219
LOGGER.debug(str(request))
220-
221220
response = self.service.Set(request)
222221
return response
223222

src/cisco_gnmi/nx.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
"""Wrapper for NX-OS to simplify usage of gNMI implementation."""
2525

26-
26+
import json
2727
import logging
2828

2929
from six import string_types
@@ -159,7 +159,7 @@ def create_updates(name, configs):
159159
replaces = create_updates("replace_json_configs", replace_json_configs)
160160
return self.set(prefix=prefix, updates=updates, replaces=replaces)
161161

162-
def get_xpaths(self, xpaths, data_type="ALL", encoding="JSON_IETF"):
162+
def get_xpaths(self, xpaths, data_type="ALL", encoding="JSON"):
163163
"""A convenience wrapper for get() which forms proto.gnmi_pb2.Path from supplied xpaths.
164164
165165
Parameters
@@ -178,7 +178,7 @@ def get_xpaths(self, xpaths, data_type="ALL", encoding="JSON_IETF"):
178178
-------
179179
get()
180180
"""
181-
supported_encodings = ["JSON", "JSON_IETF"]
181+
supported_encodings = ["JSON"]
182182
encoding = util.validate_proto_enum(
183183
"encoding",
184184
encoding,
@@ -288,19 +288,18 @@ def subscribe_xpaths(
288288

289289
def parse_xpath_to_gnmi_path(self, xpath, origin=None):
290290
"""Attempts to determine whether origin should be YANG (device) or DME.
291-
Errors on OpenConfig until support is present.
292291
"""
293-
if xpath.startswith("openconfig"):
294-
raise NotImplementedError(
295-
"OpenConfig data models not yet supported on NX-OS!"
296-
)
297292
if origin is None:
298293
if any(
299-
map(xpath.startswith, ["Cisco-NX-OS-device", "/Cisco-NX-OS-device"])
294+
map(xpath.startswith, [
295+
"Cisco-NX-OS-device",
296+
"/Cisco-NX-OS-device",
297+
"cisco-nx-os-device",
298+
"/Cisco-nx-os-device"])
300299
):
301300
origin = "device"
302301
# Remove the module
303302
xpath = xpath.split(":", 1)[1]
304303
else:
305-
origin = "DME"
304+
origin = "openconfig"
306305
return super(NXClient, self).parse_xpath_to_gnmi_path(xpath, origin)

0 commit comments

Comments
 (0)