Skip to content

Commit 466b36b

Browse files
committed
Merge remote-tracking branch 'upstream/master' into dev
2 parents c31369e + 9b09824 commit 466b36b

File tree

7 files changed

+47
-22
lines changed

7 files changed

+47
-22
lines changed

src/cisco_gnmi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@
3030
from .xe import XEClient
3131
from .builder import ClientBuilder
3232

33-
__version__ = "1.0.7"
33+
__version__ = "1.0.8"

src/cisco_gnmi/builder.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
from .util import gen_target_netloc, get_cert_from_target, get_cn_from_cert
3232

3333

34+
LOGGER = logging.getLogger(__name__)
35+
logger = LOGGER
36+
37+
3438
class ClientBuilder(object):
3539
"""Builder for the creation of a gNMI client.
3640
Supports construction of base Client and XRClient.
@@ -134,8 +138,8 @@ def set_os(self, name=None):
134138
if name not in self.os_class_map.keys():
135139
raise Exception("OS not supported!")
136140
else:
141+
LOGGER.debug("Using %s wrapper.", name or "Client")
137142
self.__client_class = self.os_class_map[name]
138-
logging.debug("Using %s wrapper.", name or "Client")
139143
return self
140144

141145
def set_secure(
@@ -257,7 +261,7 @@ def set_channel_option(self, name, value):
257261
found_index = index
258262
break
259263
if found_index is not None:
260-
logging.warning("Found existing channel option %s, overwriting!", name)
264+
LOGGER.warning("Found existing channel option %s, overwriting!", name)
261265
self.__channel_options[found_index] = new_option
262266
else:
263267
self.__channel_options.append(new_option)
@@ -279,26 +283,26 @@ def construct(self):
279283
self.__root_certificates, self.__private_key, self.__certificate_chain
280284
)
281285
if self.__username and self.__password:
286+
LOGGER.debug("Using username/password call authentication.")
282287
channel_metadata_creds = grpc.metadata_call_credentials(
283288
CiscoAuthPlugin(self.__username, self.__password)
284289
)
285-
logging.debug("Using username/password call authentication.")
286290
if channel_ssl_creds and channel_metadata_creds:
291+
LOGGER.debug("Using SSL/metadata authentication composite credentials.")
287292
channel_creds = grpc.composite_channel_credentials(
288293
channel_ssl_creds, channel_metadata_creds
289294
)
290-
logging.debug("Using SSL/metadata authentication composite credentials.")
291295
else:
296+
LOGGER.debug("Using SSL credentials, no metadata authentication.")
292297
channel_creds = channel_ssl_creds
293-
logging.debug("Using SSL credentials, no metadata authentication.")
294298
if self.__ssl_target_name_override is not False:
295299
if self.__ssl_target_name_override is None:
296300
if not self.__root_certificates:
297301
raise Exception("Deriving override requires root certificate!")
298302
self.__ssl_target_name_override = get_cn_from_cert(
299303
self.__root_certificates
300304
)
301-
logging.warning(
305+
LOGGER.warning(
302306
"Overriding SSL option from certificate could increase MITM susceptibility!"
303307
)
304308
self.set_channel_option(

src/cisco_gnmi/client.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
from . import util
3232

3333

34-
logger = logging.getLogger(__name__)
34+
LOGGER = logging.getLogger(__name__)
35+
logger = LOGGER
3536

3637

3738
class Client(object):
@@ -112,6 +113,7 @@ def capabilities(self):
112113
proto.gnmi_pb2.CapabilityResponse
113114
"""
114115
message = proto.gnmi_pb2.CapabilityRequest()
116+
LOGGER.debug(str(message))
115117
response = self.service.Capabilities(message)
116118
return response
117119

@@ -167,7 +169,7 @@ def get(
167169
if extension:
168170
request.extension = extension
169171

170-
logger.debug(str(request))
172+
LOGGER.debug(str(request))
171173

172174
get_response = self.service.Get(request)
173175
return get_response
@@ -214,7 +216,7 @@ def set(
214216
if extensions:
215217
request.extension.extend(extensions)
216218

217-
logger.debug(str(request))
219+
LOGGER.debug(str(request))
218220

219221
response = self.service.Set(request)
220222
return response
@@ -254,7 +256,7 @@ def validate_request(request):
254256
if extensions:
255257
subscribe_request.extensions.extend(extensions)
256258

257-
logger.debug(str(subscribe_request))
259+
LOGGER.debug(str(subscribe_request))
258260

259261
return subscribe_request
260262

src/cisco_gnmi/nx.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
from .client import Client, proto, util
3131

3232

33+
LOGGER = logging.getLogger(__name__)
34+
logger = LOGGER
35+
36+
3337
class NXClient(Client):
3438
"""NX-OS-specific wrapper for gNMI functionality.
3539

src/cisco_gnmi/util.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
from urlparse import urlparse
3838

3939

40+
LOGGER = logging.getLogger(__name__)
41+
logger = LOGGER
42+
43+
4044
def gen_target_netloc(target, netloc_prefix="//", default_port=9339):
4145
"""Parses and validates a supplied target URL for gRPC calls.
4246
Uses urllib to parse the netloc property from the URL.
@@ -51,11 +55,11 @@ def gen_target_netloc(target, netloc_prefix="//", default_port=9339):
5155
if not parsed_target.netloc:
5256
raise ValueError("Unable to parse netloc from target URL %s!" % target)
5357
if parsed_target.scheme:
54-
logging.debug("Scheme identified in target, ignoring and using netloc.")
58+
LOGGER.debug("Scheme identified in target, ignoring and using netloc.")
5559
target_netloc = parsed_target
5660
if parsed_target.port is None:
5761
ported_target = "%s:%i" % (parsed_target.hostname, default_port)
58-
logging.debug("No target port detected, reassembled to %s.", ported_target)
62+
LOGGER.debug("No target port detected, reassembled to %s.", ported_target)
5963
target_netloc = gen_target_netloc(ported_target)
6064
return target_netloc
6165

@@ -120,11 +124,11 @@ def get_cn_from_cert(cert_pem):
120124
cert_cns = cert_parsed.subject.get_attributes_for_oid(x509.oid.NameOID.COMMON_NAME)
121125
if len(cert_cns) > 0:
122126
if len(cert_cns) > 1:
123-
logging.warning(
127+
LOGGER.warning(
124128
"Multiple CNs found for certificate, defaulting to the first one."
125129
)
126130
cert_cn = cert_cns[0].value
127-
logging.debug("Using %s as certificate CN.", cert_cn)
131+
LOGGER.debug("Using %s as certificate CN.", cert_cn)
128132
else:
129-
logging.warning("No CN found for certificate.")
133+
LOGGER.warning("No CN found for certificate.")
130134
return cert_cn

src/cisco_gnmi/xe.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
from .client import Client, proto, util
3131

3232

33-
logger = logging.getLogger(__name__)
33+
LOGGER = logging.getLogger(__name__)
34+
logger = LOGGER
3435

3536

3637
class XEClient(Client):
@@ -111,7 +112,13 @@ def delete_xpaths(self, xpaths, prefix=None):
111112
paths.append(self.parse_xpath_to_gnmi_path(xpath))
112113
return self.set(deletes=paths)
113114

114-
def set_json(self, update_json_configs=None, replace_json_configs=None, ietf=True, prefix=None):
115+
def set_json(
116+
self,
117+
update_json_configs=None,
118+
replace_json_configs=None,
119+
ietf=True,
120+
prefix=None,
121+
):
115122
"""A convenience wrapper for set() which assumes JSON payloads and constructs desired messages.
116123
All parameters are optional, but at least one must be present.
117124
@@ -136,14 +143,14 @@ def set_json(self, update_json_configs=None, replace_json_configs=None, ietf=Tru
136143

137144
def check_configs(name, configs):
138145
if isinstance(configs, string_types):
139-
logger.debug("Handling %s as JSON string.", name)
146+
LOGGER.debug("Handling %s as JSON string.", name)
140147
try:
141148
configs = json.loads(configs)
142149
except:
143150
raise Exception("{name} is invalid JSON!".format(name=name))
144151
configs = [configs]
145152
elif isinstance(configs, dict):
146-
logger.debug("Handling %s as already serialized JSON object.", name)
153+
LOGGER.debug("Handling %s as already serialized JSON object.", name)
147154
configs = [configs]
148155
elif not isinstance(configs, (list, set)):
149156
raise Exception(

src/cisco_gnmi/xr.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
from .client import Client, proto, util
3131

3232

33+
LOGGER = logging.getLogger(__name__)
34+
logger = LOGGER
35+
36+
3337
class XRClient(Client):
3438
"""IOS XR-specific wrapper for gNMI functionality.
3539
@@ -130,14 +134,14 @@ def set_json(self, update_json_configs=None, replace_json_configs=None, ietf=Tru
130134

131135
def check_configs(name, configs):
132136
if isinstance(name, string_types):
133-
logging.debug("Handling %s as JSON string.", name)
137+
LOGGER.debug("Handling %s as JSON string.", name)
134138
try:
135139
configs = json.loads(configs)
136140
except:
137141
raise Exception("{name} is invalid JSON!".format(name=name))
138142
configs = [configs]
139143
elif isinstance(name, dict):
140-
logging.debug("Handling %s as already serialized JSON object.", name)
144+
LOGGER.debug("Handling %s as already serialized JSON object.", name)
141145
configs = [configs]
142146
elif not isinstance(configs, (list, set)):
143147
raise Exception(

0 commit comments

Comments
 (0)