@@ -138,9 +138,73 @@ def get_args_parser():
138
138
)
139
139
subparser = parser .add_subparsers (dest = 'command' )
140
140
#
141
+ # usage
142
+ _ = def_usage_parser (subparser )
143
+ #
141
144
# sync
142
- sync_parser = subparser .add_parser ('sync' ,
143
- description = 'Try to attach available block devices.'
145
+ _ = def_sync_parser (subparser )
146
+ #
147
+ # show-all
148
+ _ = def_show_all_parser (subparser )
149
+ #
150
+ # show
151
+ _ = def_show_parser (subparser )
152
+ #
153
+ # create
154
+ _ = def_create_parser (subparser )
155
+ #
156
+ # attach
157
+ _ = def_attach_parser (subparser )
158
+ #
159
+ # detach
160
+ _ = def_detach_parser (subparser )
161
+ #
162
+ # destroy
163
+ _ = def_destroy_parser (subparser )
164
+
165
+ return parser
166
+
167
+
168
+ def def_usage_parser (s_parser ):
169
+ """
170
+ Define the usage parser.
171
+
172
+ Parameters
173
+ ----------
174
+ s_parser: subparsers.
175
+
176
+ Returns
177
+ -------
178
+ ArgumentParser: the usage subcommand parser.
179
+ """
180
+ usage_parser = s_parser .add_parser ('usage' ,
181
+ description = 'Displays usage' ,
182
+ help = 'Displays usage'
183
+ )
184
+ # for compatibility mode
185
+ usage_parser .add_argument ('--compat' ,
186
+ action = 'store_true' ,
187
+ default = False ,
188
+ help = argparse .SUPPRESS
189
+ )
190
+ return usage_parser
191
+
192
+
193
+ def def_sync_parser (s_parser ):
194
+ """
195
+ Define the sync subparser.
196
+
197
+ Parameters
198
+ ----------
199
+ s_parser: subparsers.
200
+
201
+ Returns
202
+ -------
203
+ ArgumentParser: the sync subcommand parser.
204
+ """
205
+ sync_parser = s_parser .add_parser ('sync' ,
206
+ description = 'Try to attach available block devices.' ,
207
+ help = 'Try to attach available block devices.'
144
208
)
145
209
sync_parser .add_argument ('-a' , '--apply' ,
146
210
action = 'store_true' ,
@@ -157,22 +221,28 @@ def get_args_parser():
157
221
default = False ,
158
222
help = argparse .SUPPRESS
159
223
)
160
- #
161
- # usage
162
- usage_parser = subparser .add_parser ('usage' ,
163
- description = 'Displays usage.' )
164
- # for compatibility mode
165
- usage_parser .add_argument ('--compat' ,
166
- action = 'store_true' ,
167
- default = False ,
168
- help = argparse .SUPPRESS
169
- )
224
+ return sync_parser
225
+
226
+
227
+ def def_show_all_parser (s_parser ):
228
+ """
229
+ Define the show-all parser
230
+
231
+ Parameters
232
+ ----------
233
+ s_parser: subparsers.
234
+
235
+ Returns
236
+ -------
237
+ ArgumentParser: the show-all subcommand parser.
238
+
239
+ """
170
240
#
171
241
# show all volumes all details
172
- show_all_parser = subparser .add_parser ('show-all' ,
173
- description = 'Show all volumes with details '
174
- ' in this availability domain.'
175
- )
242
+ show_all_parser = s_parser .add_parser ('show-all' ,
243
+ description = 'Show all volumes with details in this availability domain.' ,
244
+ help = 'Show all volumes with details in this availability domain.'
245
+ )
176
246
show_all_parser .add_argument ('-t' , '--truncate' ,
177
247
action = 'store_true' ,
178
248
help = argparse .SUPPRESS
@@ -182,11 +252,25 @@ def get_args_parser():
182
252
help = 'Set output mode.' ,
183
253
default = 'table'
184
254
)
185
- #
186
- # show
187
- show_parser = subparser .add_parser ('show' ,
188
- description = 'Show block volumes and iSCSI information.'
189
- )
255
+ return show_all_parser
256
+
257
+
258
+ def def_show_parser (s_parser ):
259
+ """
260
+ Define the show parser
261
+
262
+ Parameters
263
+ ----------
264
+ s_parser: subparsers.
265
+
266
+ Returns
267
+ -------
268
+ ArgumentParser: the show subcommand parser.
269
+ """
270
+ show_parser = s_parser .add_parser ('show' ,
271
+ description = 'Show block volumes and iSCSI information.' ,
272
+ help = 'Show block volumes and iSCSI information.'
273
+ )
190
274
show_parser .add_argument ('-C' , '--compartments' ,
191
275
metavar = 'COMP' ,
192
276
default = (),
@@ -219,11 +303,25 @@ def get_args_parser():
219
303
default = False ,
220
304
help = argparse .SUPPRESS
221
305
)
222
- #
223
- # create
224
- create_parser = subparser .add_parser ('create' ,
225
- description = 'Creates a block volume.'
226
- )
306
+ return show_parser
307
+
308
+
309
+ def def_create_parser (s_parser ):
310
+ """
311
+ Define the create parser
312
+
313
+ Parameters
314
+ ----------
315
+ s_parser: subparsers
316
+
317
+ Returns
318
+ -------
319
+ ArgumentParser: the create subcommand parser
320
+ """
321
+ create_parser = s_parser .add_parser ('create' ,
322
+ description = 'Creates a block volume.' ,
323
+ help = 'Creates a block volume.'
324
+ )
227
325
create_parser .add_argument ('-S' , '--size' ,
228
326
type = volume_size_validator ,
229
327
required = True ,
@@ -245,12 +343,27 @@ def get_args_parser():
245
343
default = False ,
246
344
help = argparse .SUPPRESS
247
345
)
248
- #
249
- # attach
250
- attach_parser = subparser .add_parser ('attach' ,
251
- description = 'Attach a block volume to this instance '
252
- 'and make it available to the system.'
253
- )
346
+ return create_parser
347
+
348
+
349
+ def def_attach_parser (s_parser ):
350
+ """
351
+ Define the attach parser.
352
+
353
+ Parameters
354
+ ----------
355
+ s_parser: subparsers
356
+
357
+ Returns
358
+ -------
359
+ ArgumentParser: the attach subcommand parser
360
+ """
361
+ attach_parser = s_parser .add_parser ('attach' ,
362
+ description = 'Attach a block volume to this instance and make it available ' \
363
+ 'to the system.' ,
364
+ help = 'Attach a block volume to this instance and make it available to the ' \
365
+ 'system.'
366
+ )
254
367
ocidiqn = attach_parser .add_mutually_exclusive_group (required = True )
255
368
ocidiqn .add_argument ('-I' , '--iqns' ,
256
369
type = attachable_iqn_list_validator ,
@@ -282,10 +395,24 @@ def get_args_parser():
282
395
default = False ,
283
396
help = argparse .SUPPRESS
284
397
)
285
- #
286
- # detach
287
- detach_parser = subparser .add_parser ('detach' ,
288
- description = 'Detach a block volume'
398
+ return attach_parser
399
+
400
+
401
+ def def_detach_parser (s_parser ):
402
+ """
403
+ Define the detach subcommand parser.
404
+
405
+ Parameters
406
+ ----------
407
+ s_parser: subparsers
408
+
409
+ Returns
410
+ -------
411
+ ArgumentParser: the detach subcommand parser
412
+ """
413
+ detach_parser = s_parser .add_parser ('detach' ,
414
+ description = 'Detach a block volume' ,
415
+ help = 'Detach a block volume'
289
416
)
290
417
detach_parser .add_argument ('-I' , '--iqns' ,
291
418
required = True ,
@@ -305,10 +432,24 @@ def get_args_parser():
305
432
default = False ,
306
433
help = argparse .SUPPRESS
307
434
)
308
- #
309
- # destroy
310
- destroy_parser = subparser .add_parser ('destroy' ,
311
- description = 'Destroy a block volume.'
435
+ return detach_parser
436
+
437
+
438
+ def def_destroy_parser (s_parser ):
439
+ """
440
+ Define the destroy subcommand parser.
441
+
442
+ Parameters
443
+ ----------
444
+ s_parser: subparsers
445
+
446
+ Returns
447
+ -------
448
+ ArgumentParser: the destroy subcommand parser
449
+ """
450
+ destroy_parser = s_parser .add_parser ('destroy' ,
451
+ description = 'Destroy a block volume.' ,
452
+ help = 'Destroy a block volume.'
312
453
)
313
454
destroy_parser .add_argument ('-O' , '--ocids' ,
314
455
required = True ,
@@ -329,7 +470,7 @@ def get_args_parser():
329
470
default = False ,
330
471
help = argparse .SUPPRESS
331
472
)
332
- return parser
473
+ return destroy_parser
333
474
334
475
335
476
def _getch ():
@@ -1541,7 +1682,7 @@ def do_create_volume(sess, size, display_name, attach_it, detached, chap_credent
1541
1682
#
1542
1683
# Something wrong if passing here.
1543
1684
try :
1544
- _logger .debug ('Destroying the volume' )
1685
+ _logger .debug ('Trying to destroy the volume' )
1545
1686
vol .destroy ()
1546
1687
except Exception as e :
1547
1688
_logger .debug ("Failed to destroy volume" , exc_info = True )
0 commit comments