@@ -50,21 +50,17 @@ def main():
50
50
parser = argparse .ArgumentParser (
51
51
description = "gNMI CLI demonstrating library usage." ,
52
52
usage = """
53
- gnmcli <rpc> [<args>]
53
+ gnmcli <rpc> [<args>]
54
54
55
- Supported RPCs:
56
- %s
55
+ Supported RPCs:
56
+ {supported_rpcs}
57
57
58
- See --help for RPC options.
58
+ See <rpc> --help for RPC options.
59
59
""" .format (
60
- "\n " .join (rpc_map .keys ())
60
+ supported_rpcs = "\n " .join (list ( rpc_map .keys () ))
61
61
),
62
62
)
63
63
parser .add_argument ("rpc" , help = "gNMI RPC to perform against network element." )
64
- if len (sys .argv ) < 2 :
65
- logging .error ("Must at minimum provide RPC and required arguments!" )
66
- parser .print_help ()
67
- exit (1 )
68
64
args = parser .parse_args (sys .argv [1 :2 ])
69
65
if args .rpc not in rpc_map .keys ():
70
66
logging .error (
@@ -74,7 +70,7 @@ def main():
74
70
exit (1 )
75
71
try :
76
72
rpc_map [args .rpc ]()
77
- except :
73
+ except Exception :
78
74
logging .exception ("Error during usage!" )
79
75
exit (1 )
80
76
@@ -103,7 +99,7 @@ def gnmi_subscribe():
103
99
"-interval" ,
104
100
help = "Sample interval in seconds for Subscription." ,
105
101
type = int ,
106
- default = 10 * int ( 1e9 ) ,
102
+ default = 10 ,
107
103
)
108
104
parser .add_argument (
109
105
"-dump_file" ,
@@ -124,7 +120,7 @@ def gnmi_subscribe():
124
120
help = "gNMI subscription encoding." ,
125
121
type = str ,
126
122
nargs = "?" ,
127
- choices = list ( proto .gnmi_pb2 .Encoding .keys () ),
123
+ choices = proto .gnmi_pb2 .Encoding .keys (),
128
124
)
129
125
args = __common_args_handler (parser )
130
126
# Set default XPath outside of argparse due to default being persistent in argparse.
@@ -135,8 +131,8 @@ def gnmi_subscribe():
135
131
kwargs = {}
136
132
if args .encoding :
137
133
kwargs ["encoding" ] = args .encoding
138
- if args .sample_interval :
139
- kwargs ["sample_interval" ] = args .sample_interval
134
+ if args .interval :
135
+ kwargs ["sample_interval" ] = args .interval * int ( 1e9 )
140
136
try :
141
137
logging .info (
142
138
"Dumping responses to %s as %s ..." ,
@@ -145,6 +141,7 @@ def gnmi_subscribe():
145
141
)
146
142
logging .info ("Subscribing to:\n %s" , "\n " .join (args .xpath ))
147
143
for subscribe_response in client .subscribe_xpaths (args .xpath , ** kwargs ):
144
+ logging .debug ("SubscribeResponse received." )
148
145
if subscribe_response .sync_response :
149
146
logging .debug ("sync_response received." )
150
147
if args .sync_stop :
@@ -175,18 +172,16 @@ def gnmi_get():
175
172
help = "gNMI subscription encoding." ,
176
173
type = str ,
177
174
nargs = "?" ,
178
- choices = list ( proto .gnmi_pb2 .Encoding .keys () ),
175
+ choices = proto .gnmi_pb2 .Encoding .keys (),
179
176
)
180
177
parser .add_argument (
181
178
"-data_type" ,
182
179
help = "gNMI GetRequest DataType" ,
183
180
type = str ,
184
181
nargs = "?" ,
185
- choices = list (
186
- enum_type_wrapper .EnumTypeWrapper (
187
- proto .gnmi_pb2 ._GETREQUEST_DATATYPE
188
- ).keys ()
189
- ),
182
+ choices = enum_type_wrapper .EnumTypeWrapper (
183
+ proto .gnmi_pb2 ._GETREQUEST_DATATYPE
184
+ ).keys (),
190
185
)
191
186
parser .add_argument (
192
187
"-dump_json" ,
@@ -299,20 +294,16 @@ def __common_args_handler(parser):
299
294
choices = list (ClientBuilder .os_class_map .keys ()),
300
295
)
301
296
parser .add_argument (
302
- "-root_certificates" , description = "Root certificates for secure connection."
303
- )
304
- parser .add_argument (
305
- "-private_key" , description = "Private key for secure connection."
306
- )
307
- parser .add_argument (
308
- "-certificate_chain" , description = "Certificate chain for secure connection."
297
+ "-root_certificates" , help = "Root certificates for secure connection."
309
298
)
299
+ parser .add_argument ("-private_key" , help = "Private key for secure connection." )
310
300
parser .add_argument (
311
- "-ssl_target_override " , description = "gRPC SSL target override option ."
301
+ "-certificate_chain " , help = "Certificate chain for secure connection ."
312
302
)
303
+ parser .add_argument ("-ssl_target_override" , help = "gRPC SSL target override option." )
313
304
parser .add_argument (
314
305
"-auto_ssl_target_override" ,
315
- description = "Root certificates for secure connection." ,
306
+ help = "Root certificates for secure connection." ,
316
307
action = "store_true" ,
317
308
)
318
309
parser .add_argument ("-debug" , help = "Print debug messages" , action = "store_true" )
0 commit comments