@@ -42,7 +42,11 @@ def main():
42
42
logging .error ("%s not in supported RPCs: %s!" , args .rpc , ', ' .join (rpc_map .keys ()))
43
43
parser .print_help ()
44
44
exit (1 )
45
- rpc_map [args .rpc ]()
45
+ try :
46
+ rpc_map [args .rpc ]()
47
+ except :
48
+ logging .exception ("Error during usage!" )
49
+ exit (1 )
46
50
47
51
def gnmi_capabilities ():
48
52
parser = argparse .ArgumentParser (
@@ -124,6 +128,9 @@ def gnmi_subscribe():
124
128
logging .exception ("Stopping due to exception!" )
125
129
126
130
def gnmi_get ():
131
+ """Provides Get RPC usage. Assumes JSON or JSON_IETF style configurations.
132
+ TODO: This is the least well understood/implemented. Need to validate if there is an OOO for update/replace/delete.
133
+ """
127
134
parser = argparse .ArgumentParser (
128
135
description = "Performs Get RPC against network element."
129
136
)
@@ -163,12 +170,71 @@ def gnmi_get():
163
170
logging .info (formatted_message )
164
171
165
172
def gnmi_set ():
173
+ """Provides Set RPC usage. Assumes JSON or JSON_IETF style configurations.
174
+ Applies update/replace operations, and then delete operations.
175
+ TODO: This is the least well understood/implemented. Need to validate if there is an OOO for update/replace/delete.
176
+ """
166
177
parser = argparse .ArgumentParser (
167
178
description = "Performs Set RPC against network element."
168
179
)
180
+ parser .add_argument (
181
+ "-update_json_config" ,
182
+ description = "JSON-modeled config to apply as an update."
183
+ )
184
+ parser .add_argument (
185
+ "-replace_json_config" ,
186
+ description = "JSON-modeled config to apply as an update."
187
+ )
188
+ parser .add_argument (
189
+ "-delete_xpath" ,
190
+ help = "XPaths to delete." ,
191
+ type = str ,
192
+ action = "append"
193
+ )
194
+ parser .add_argument (
195
+ "-no_ietf" ,
196
+ help = "JSON is not IETF conformant." ,
197
+ action = "store_true"
198
+ )
199
+ parser .add_argument (
200
+ "-dump_json" ,
201
+ help = "Dump as JSON instead of textual protos." ,
202
+ action = "store_true"
203
+ )
169
204
args = __common_args_handler (parser )
205
+ if not any ([args .update_json_config , args .replace_json_config , args .delete_xpath ]):
206
+ raise Exception ("Must specify update, replace, or delete parameters!" )
207
+ def load_json_file (filename ):
208
+ config = None
209
+ with open (filename , "r" ) as config_fd :
210
+ config = json .load (config_fd )
211
+ return config
212
+ kwargs = {}
213
+ if args .update_json_config :
214
+ kwargs ["update_json_configs" ] = load_json_file (args .update_json_config )
215
+ if args .replace_json_config :
216
+ kwargs ["replace_json_configs" ] = load_json_file (args .replace_json_config )
217
+ if args .no_ietf :
218
+ kwargs ["ietf" ] = False
170
219
client = __gen_client (args )
171
-
220
+ set_response = client .set_json (** kwargs )
221
+ formatted_message = None
222
+ if args .dump_json :
223
+ formatted_message = json_format .MessageToJson (set_response , sort_keys = True )
224
+ else :
225
+ formatted_message = text_format .MessageToString (set_response )
226
+ logging .info (formatted_message )
227
+ if args .delete_xpath :
228
+ if getattr (client , "delete_xpaths" , None ) is not None :
229
+ delete_response = client .delete_xpaths (args .xpath )
230
+ formatted_message = None
231
+ if args .dump_json :
232
+ formatted_message = json_format .MessageToJson (delete_response , sort_keys = True )
233
+ else :
234
+ formatted_message = text_format .MessageToString (delete_response )
235
+ logging .info (formatted_message )
236
+ else :
237
+ raise Exception ("Convenience delete_xpaths is not supported in the client library!" )
172
238
173
239
def __gen_client (args ):
174
240
builder = ClientBuilder (args .netloc )
0 commit comments