Skip to content

Commit b1e5b70

Browse files
committed
Merge branch 'develop'
2 parents a657af5 + ec45b3c commit b1e5b70

File tree

6 files changed

+311
-176
lines changed

6 files changed

+311
-176
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ mostlyclean:
2222
## Runs tests.
2323
.PHONY: test
2424
test:
25-
pipenv run pytest $(TEST_DIR) -v -s --disable-warnings
25+
pipenv run pytest $(TEST_DIR) -vv -s --disable-warnings
2626

2727
## Creates coverage report.
2828
.PHONY: coverage

src/cisco_gnmi/client.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
import os
3232
from six import string_types
3333

34-
from cisco_gnmi import proto
35-
from cisco_gnmi import util
36-
from cisco_gnmi.xpath_util import get_payload, parse_xpath_to_gnmi_path
34+
from . import proto
35+
from . import util
36+
from .xpath_util import get_payload, parse_xpath_to_gnmi_path
3737

3838

3939
class Client(object):
@@ -268,9 +268,7 @@ def check_configs(self, configs):
268268
logger.debug("Handling already serialized JSON object.")
269269
configs = [configs]
270270
elif not isinstance(configs, (list, set)):
271-
raise Exception(
272-
"{0} must be an iterable of configs!".format(str(configs))
273-
)
271+
raise Exception("{0} must be an iterable of configs!".format(str(configs)))
274272
return configs
275273

276274
def create_updates(self, configs, origin, json_ietf=False):
@@ -310,11 +308,7 @@ def create_updates(self, configs, origin, json_ietf=False):
310308
for update_cfg in update_configs:
311309
xpath, payload = update_cfg
312310
update = proto.gnmi_pb2.Update()
313-
update.path.CopyFrom(
314-
parse_xpath_to_gnmi_path(
315-
xpath, origin=origin
316-
)
317-
)
311+
update.path.CopyFrom(parse_xpath_to_gnmi_path(xpath, origin=origin))
318312
if json_ietf:
319313
update.val.json_ietf_val = payload
320314
else:

src/cisco_gnmi/nx.py

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
import os
3030

3131
from six import string_types
32-
from cisco_gnmi import proto, util
33-
from cisco_gnmi.client import Client
34-
from cisco_gnmi.xpath_util import parse_xpath_to_gnmi_path
32+
from . import proto, util
33+
from .client import Client
34+
from .xpath_util import parse_xpath_to_gnmi_path
3535

3636
logger = logging.getLogger(__name__)
3737

@@ -58,6 +58,7 @@ class NXClient(Client):
5858
>>> capabilities = client.capabilities()
5959
>>> print(capabilities)
6060
"""
61+
6162
def delete_xpaths(self, xpaths, prefix=None):
6263
"""A convenience wrapper for set() which constructs Paths from supplied xpaths
6364
to be passed to set() as the delete parameter.
@@ -90,8 +91,13 @@ def delete_xpaths(self, xpaths, prefix=None):
9091
paths.append(parse_xpath_to_gnmi_path(xpath))
9192
return self.set(deletes=paths)
9293

93-
def set_json(self, update_json_configs=None, replace_json_configs=None,
94-
origin='device', json_ietf=False):
94+
def set_json(
95+
self,
96+
update_json_configs=None,
97+
replace_json_configs=None,
98+
origin="device",
99+
json_ietf=False,
100+
):
95101
"""A convenience wrapper for set() which assumes JSON payloads and constructs desired messages.
96102
All parameters are optional, but at least one must be present.
97103
@@ -114,22 +120,17 @@ def set_json(self, update_json_configs=None, replace_json_configs=None,
114120
raise Exception("Must supply at least one set of configurations to method!")
115121

116122
updates = self.create_updates(
117-
update_json_configs,
118-
origin=origin,
119-
json_ietf=json_ietf
123+
update_json_configs, origin=origin, json_ietf=json_ietf
120124
)
121125
replaces = self.create_updates(
122-
replace_json_configs,
123-
origin=origin,
124-
json_ietf=json_ietf
126+
replace_json_configs, origin=origin, json_ietf=json_ietf
125127
)
126128
for update in updates + replaces:
127-
logger.debug('\nGNMI set:\n{0}\n{1}'.format(9 * '=', str(update)))
129+
logger.debug("\nGNMI set:\n{0}\n{1}".format(9 * "=", str(update)))
128130

129131
return self.set(updates=updates, replaces=replaces)
130132

131-
def get_xpaths(self, xpaths, data_type="ALL",
132-
encoding="JSON", origin='openconfig'):
133+
def get_xpaths(self, xpaths, data_type="ALL", encoding="JSON", origin="openconfig"):
133134
"""A convenience wrapper for get() which forms proto.gnmi_pb2.Path from supplied xpaths.
134135
135136
Parameters
@@ -167,7 +168,7 @@ def get_xpaths(self, xpaths, data_type="ALL",
167168
raise Exception(
168169
"xpaths must be a single xpath string or iterable of xpath strings!"
169170
)
170-
logger.debug('GNMI get:\n{0}\n{1}'.format(9 * '=', str(gnmi_path)))
171+
logger.debug("GNMI get:\n{0}\n{1}".format(9 * "=", str(gnmi_path)))
171172
return self.get(gnmi_path, data_type=data_type, encoding=encoding)
172173

173174
def subscribe_xpaths(
@@ -177,7 +178,7 @@ def subscribe_xpaths(
177178
sub_mode="SAMPLE",
178179
encoding="PROTO",
179180
sample_interval=Client._NS_IN_S * 10,
180-
origin='openconfig'
181+
origin="openconfig",
181182
):
182183
"""A convenience wrapper of subscribe() which aids in building of SubscriptionRequest
183184
with request as subscribe SubscriptionList. This method accepts an iterable of simply xpath strings,
@@ -241,10 +242,7 @@ def subscribe_xpaths(
241242
if isinstance(xpath_subscription, string_types):
242243
subscription = proto.gnmi_pb2.Subscription()
243244
subscription.path.CopyFrom(
244-
parse_xpath_to_gnmi_path(
245-
xpath_subscription,
246-
origin
247-
)
245+
parse_xpath_to_gnmi_path(xpath_subscription, origin)
248246
)
249247
subscription.mode = util.validate_proto_enum(
250248
"sub_mode",
@@ -255,10 +253,7 @@ def subscribe_xpaths(
255253
)
256254
subscription.sample_interval = sample_interval
257255
elif isinstance(xpath_subscription, dict):
258-
path = parse_xpath_to_gnmi_path(
259-
xpath_subscription["path"],
260-
origin
261-
)
256+
path = parse_xpath_to_gnmi_path(xpath_subscription["path"], origin)
262257
arg_dict = {
263258
"path": path,
264259
"mode": sub_mode,
@@ -280,7 +275,7 @@ def subscribe_xpaths(
280275
raise Exception("xpath in list must be xpath or dict/Path!")
281276
subscriptions.append(subscription)
282277
subscription_list.subscription.extend(subscriptions)
283-
logger.debug('GNMI subscribe:\n{0}\n{1}'.format(
284-
15 * '=', str(subscription_list))
278+
logger.debug(
279+
"GNMI subscribe:\n{0}\n{1}".format(15 * "=", str(subscription_list))
285280
)
286281
return self.subscribe([subscription_list])

src/cisco_gnmi/xe.py

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
import os
2929

3030
from six import string_types
31-
from cisco_gnmi import proto, util
32-
from cisco_gnmi.client import Client
33-
from cisco_gnmi.xpath_util import parse_xpath_to_gnmi_path
31+
from . import proto, util
32+
from .client import Client
33+
from .xpath_util import parse_xpath_to_gnmi_path
3434

3535
logger = logging.getLogger(__name__)
3636
logger.setLevel(logging.DEBUG)
@@ -81,6 +81,7 @@ class XEClient(Client):
8181
...
8282
>>> delete_response = client.delete_xpaths('/Cisco-IOS-XE-native:native/hostname')
8383
"""
84+
8485
def delete_xpaths(self, xpaths, prefix=None):
8586
"""A convenience wrapper for set() which constructs Paths from supplied xpaths
8687
to be passed to set() as the delete parameter.
@@ -113,8 +114,13 @@ def delete_xpaths(self, xpaths, prefix=None):
113114
paths.append(parse_xpath_to_gnmi_path(xpath))
114115
return self.set(deletes=paths)
115116

116-
def set_json(self, update_json_configs=None, replace_json_configs=None,
117-
origin='device', json_ietf=True):
117+
def set_json(
118+
self,
119+
update_json_configs=None,
120+
replace_json_configs=None,
121+
origin="device",
122+
json_ietf=True,
123+
):
118124
"""A convenience wrapper for set() which assumes JSON payloads and constructs desired messages.
119125
All parameters are optional, but at least one must be present.
120126
@@ -137,17 +143,13 @@ def set_json(self, update_json_configs=None, replace_json_configs=None,
137143
raise Exception("Must supply at least one set of configurations to method!")
138144

139145
updates = self.create_updates(
140-
update_json_configs,
141-
origin=origin,
142-
json_ietf=json_ietf
146+
update_json_configs, origin=origin, json_ietf=json_ietf
143147
)
144148
replaces = self.create_updates(
145-
replace_json_configs,
146-
origin=origin,
147-
json_ietf=json_ietf
149+
replace_json_configs, origin=origin, json_ietf=json_ietf
148150
)
149151
for update in updates + replaces:
150-
logger.debug('\nGNMI set:\n{0}\n{1}'.format(9 * '=', str(update)))
152+
logger.debug("\nGNMI set:\n{0}\n{1}".format(9 * "=", str(update)))
151153

152154
return self.set(updates=updates, replaces=replaces)
153155

@@ -189,7 +191,7 @@ def get_xpaths(self, xpaths, data_type="ALL", encoding="JSON_IETF", origin=None)
189191
raise Exception(
190192
"xpaths must be a single xpath string or iterable of xpath strings!"
191193
)
192-
logger.debug('GNMI get:\n{0}\n{1}'.format(9 * '=', str(gnmi_path)))
194+
logger.debug("GNMI get:\n{0}\n{1}".format(9 * "=", str(gnmi_path)))
193195
return self.get(gnmi_path, data_type=data_type, encoding=encoding)
194196

195197
def subscribe_xpaths(
@@ -199,7 +201,7 @@ def subscribe_xpaths(
199201
sub_mode="SAMPLE",
200202
encoding="JSON_IETF",
201203
sample_interval=Client._NS_IN_S * 10,
202-
origin='openconfig'
204+
origin="openconfig",
203205
):
204206
"""A convenience wrapper of subscribe() which aids in building of SubscriptionRequest
205207
with request as subscribe SubscriptionList. This method accepts an iterable of simply xpath strings,
@@ -263,10 +265,7 @@ def subscribe_xpaths(
263265
if isinstance(xpath_subscription, string_types):
264266
subscription = proto.gnmi_pb2.Subscription()
265267
subscription.path.CopyFrom(
266-
parse_xpath_to_gnmi_path(
267-
xpath_subscription,
268-
origin
269-
)
268+
parse_xpath_to_gnmi_path(xpath_subscription, origin)
270269
)
271270
subscription.mode = util.validate_proto_enum(
272271
"sub_mode",
@@ -277,10 +276,7 @@ def subscribe_xpaths(
277276
)
278277
subscription.sample_interval = sample_interval
279278
elif isinstance(xpath_subscription, dict):
280-
path = parse_xpath_to_gnmi_path(
281-
xpath_subscription["path"],
282-
origin
283-
)
279+
path = parse_xpath_to_gnmi_path(xpath_subscription["path"], origin)
284280
arg_dict = {
285281
"path": path,
286282
"mode": sub_mode,
@@ -302,7 +298,7 @@ def subscribe_xpaths(
302298
raise Exception("xpath in list must be xpath or dict/Path!")
303299
subscriptions.append(subscription)
304300
subscription_list.subscription.extend(subscriptions)
305-
logger.debug('GNMI subscribe:\n{0}\n{1}'.format(
306-
15 * '=', str(subscription_list))
301+
logger.debug(
302+
"GNMI subscribe:\n{0}\n{1}".format(15 * "=", str(subscription_list))
307303
)
308304
return self.subscribe([subscription_list])

0 commit comments

Comments
 (0)