2929import os
3030
3131from 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
3636logger = 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 (' \n GNMI set:\n {0}\n {1}' .format (9 * '=' , str (update )))
129+ logger .debug (" \n GNMI 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 ])
0 commit comments