22
22
_password = os .environ [constants .HAAS_PASSWORD_VARIABLE ]
23
23
24
24
25
+ def bmi_exception_wrapper (func ):
26
+ def function_wrapper (* args ,** kwargs ):
27
+ try :
28
+ return func (* args ,** kwargs )
29
+ except BMIException as e :
30
+ click .echo (str (e ))
31
+
32
+ return function_wrapper
33
+
25
34
@click .group ()
26
35
def cli ():
27
36
"""
@@ -98,6 +107,7 @@ def deprovision(project, node, network, nic):
98
107
@cli .command (name = 'showpro' ,
99
108
short_help = 'Lists Provisioned Nodes' )
100
109
@click .argument (constants .PROJECT_PARAMETER )
110
+ @bmi_exception_wrapper
101
111
def list_provisioned_nodes (project ):
102
112
"""
103
113
Lists Provisioned Nodes under a Project.
@@ -243,14 +253,15 @@ def project_grp():
243
253
244
254
245
255
@project_grp .command (name = 'ls' , short_help = 'Lists Projects' )
256
+ @bmi_exception_wrapper
246
257
def list_projects ():
247
258
"""
248
259
Lists Projects From DB
249
260
250
261
\b
251
262
WARNING = User Must be An Admin
252
263
"""
253
- with BMI (_username , _password , "bmi_admin" ) as bmi :
264
+ with BMI (_username , _password , constants . BMI_ADMIN_PROJECT ) as bmi :
254
265
ret = bmi .list_projects ()
255
266
if ret [constants .STATUS_CODE_KEY ] == 200 :
256
267
table = PrettyTable (field_names = ["Id" , "Name" , "Provision Network" ])
@@ -266,6 +277,7 @@ def list_projects():
266
277
@click .argument (constants .PROJECT_PARAMETER )
267
278
@click .argument (constants .NETWORK_PARAMETER )
268
279
@click .option ('--id' , default = None , help = 'Specify what id to use for project' )
280
+ @bmi_exception_wrapper
269
281
def add_project (project , network , id ):
270
282
"""
271
283
Create Project in DB
@@ -278,7 +290,7 @@ def add_project(project, network, id):
278
290
PROJECT = The Name of Project (A HIL Project must exist)
279
291
NETWORK = The Name of the Provisioning Network
280
292
"""
281
- with BMI (_username , _password , "bmi_admin" ) as bmi :
293
+ with BMI (_username , _password , constants . BMI_ADMIN_PROJECT ) as bmi :
282
294
ret = bmi .add_project (project , network , id )
283
295
if ret [constants .STATUS_CODE_KEY ] == 200 :
284
296
click .echo ("Success" )
@@ -288,6 +300,7 @@ def add_project(project, network, id):
288
300
289
301
@project_grp .command (name = 'rm' , help = 'Deletes Project From DB' )
290
302
@click .argument (constants .PROJECT_PARAMETER )
303
+ @bmi_exception_wrapper
291
304
def delete_project (project ):
292
305
"""
293
306
Remove Project From DB
@@ -299,7 +312,7 @@ def delete_project(project):
299
312
Arguments:
300
313
PROJECT = The Name of Project (A HIL Project must exist)
301
314
"""
302
- with BMI (_username , _password , "bmi_admin" ) as bmi :
315
+ with BMI (_username , _password , constants . BMI_ADMIN_PROJECT ) as bmi :
303
316
ret = bmi .delete_project (project )
304
317
if ret [constants .STATUS_CODE_KEY ] == 200 :
305
318
click .echo ("Success" )
@@ -318,6 +331,7 @@ def db():
318
331
@db .command (name = 'rm' , help = 'Deletes Image From DB' )
319
332
@click .argument (constants .PROJECT_PARAMETER )
320
333
@click .argument (constants .IMAGE_NAME_PARAMETER )
334
+ @bmi_exception_wrapper
321
335
def delete_image (project , img ):
322
336
"""
323
337
Delete Image in DB
@@ -330,7 +344,7 @@ def delete_image(project, img):
330
344
PROJECT = The Name of Project
331
345
IMG = The Name of the Image to insert
332
346
"""
333
- with BMI (_username , _password , "bmi_admin" ) as bmi :
347
+ with BMI (_username , _password , constants . BMI_ADMIN_PROJECT ) as bmi :
334
348
ret = bmi .delete_image (project , img )
335
349
if ret [constants .STATUS_CODE_KEY ] == 200 :
336
350
click .echo ("Success" )
@@ -345,6 +359,7 @@ def delete_image(project, img):
345
359
@click .option ('--snap' , is_flag = True , help = 'If image is snapshot' )
346
360
@click .option ('--parent' , default = None , help = 'Specify parent name' )
347
361
@click .option ('--public' , is_flag = True , help = 'If image is public' )
362
+ @bmi_exception_wrapper
348
363
def add_image (project , img , id , snap , parent , public ):
349
364
"""
350
365
Create Image in DB
@@ -357,7 +372,7 @@ def add_image(project, img, id, snap, parent, public):
357
372
PROJECT = The Name of Project (A HIL Project must exist)
358
373
IMG = The Name of the Image to insert
359
374
"""
360
- with BMI (_username , _password , "bmi_admin" ) as bmi :
375
+ with BMI (_username , _password , constants . BMI_ADMIN_PROJECT ) as bmi :
361
376
ret = bmi .add_image (project , img , id , snap , parent , public )
362
377
if ret [constants .STATUS_CODE_KEY ] == 200 :
363
378
click .echo ("Success" )
@@ -372,6 +387,7 @@ def add_image(project, img, id, snap, parent, public):
372
387
@click .option ('--project' , default = None , help = 'Filter By Project' )
373
388
@click .option ('--name' , default = None , help = 'Filter By Name' )
374
389
@click .option ('--ceph' , default = None , help = "Filter By Ceph Name" )
390
+ @bmi_exception_wrapper
375
391
def list_all_images (s , c , p , project , name , ceph ):
376
392
"""
377
393
List All Image Present in DB
@@ -400,7 +416,7 @@ def second_filter():
400
416
401
417
return (f1 and f2 and f3 ) or f4
402
418
403
- with BMI (_username , _password , "bmi_admin" ) as bmi :
419
+ with BMI (_username , _password , constants . BMI_ADMIN_PROJECT ) as bmi :
404
420
ret = bmi .list_all_images ()
405
421
if ret [constants .STATUS_CODE_KEY ] == 200 :
406
422
table = PrettyTable (
@@ -430,6 +446,7 @@ def second_filter():
430
446
@click .argument (constants .PROJECT_PARAMETER )
431
447
@click .argument (constants .IMAGE_NAME_PARAMETER )
432
448
@click .option ('--snap' , default = None , help = 'Specifies what snapshot to import' )
449
+ @bmi_exception_wrapper
433
450
def import_ceph_image (project , img , snap ):
434
451
"""
435
452
Import an existing CEPH image into BMI
@@ -453,10 +470,11 @@ def import_ceph_image(project, img, snap):
453
470
454
471
455
472
@cli .command (name = 'cp' , help = "Copy an existing image not clones" )
456
- @click .argument ('src_project' )
457
- @click .argument ('img1' )
458
- @click .argument ('dest_project' )
459
- @click .argument ('img2' , default = None )
473
+ @click .argument (constants .SRC_PROJECT_PARAMETER )
474
+ @click .argument (constants .IMAGE1_NAME_PARAMETER )
475
+ @click .argument (constants .DEST_PROJECT_PARAMETER )
476
+ @click .argument (constants .IMAGE2_NAME_PARAMETER , default = None )
477
+ @bmi_exception_wrapper
460
478
def copy_image (src_project , img1 , dest_project , img2 ):
461
479
"""
462
480
Copy an image from one project to another
@@ -477,10 +495,11 @@ def copy_image(src_project, img1, dest_project, img2):
477
495
478
496
479
497
@cli .command (name = 'mv' , help = 'Move Image From Project to Another' )
480
- @click .argument ('src_project' )
481
- @click .argument ('img1' )
482
- @click .argument ('dest_project' )
483
- @click .argument ('img2' , default = None )
498
+ @click .argument (constants .SRC_PROJECT_PARAMETER )
499
+ @click .argument (constants .IMAGE1_NAME_PARAMETER )
500
+ @click .argument (constants .DEST_PROJECT_PARAMETER )
501
+ @click .argument (constants .IMAGE2_NAME_PARAMETER , default = None )
502
+ @bmi_exception_wrapper
484
503
def move_image (src_project , img1 , dest_project , img2 ):
485
504
"""
486
505
Move an image from one project to another
@@ -508,6 +527,7 @@ def node():
508
527
@node .command ('ip' , help = 'Get IP on Provisioning Network' )
509
528
@click .argument (constants .PROJECT_PARAMETER )
510
529
@click .argument (constants .NODE_NAME_PARAMETER )
530
+ @bmi_exception_wrapper
511
531
def get_node_ip (project , node ):
512
532
"""
513
533
Get the IP of Provisioned Node on Provisioning Network
@@ -533,6 +553,7 @@ def iscsi():
533
553
@iscsi .command (name = 'create' , help = 'Create ISCSI Mapping' )
534
554
@click .argument (constants .PROJECT_PARAMETER )
535
555
@click .argument (constants .IMAGE_NAME_PARAMETER )
556
+ @bmi_exception_wrapper
536
557
def create_mapping (project , img ):
537
558
"""
538
559
Mount image on iscsi server
@@ -556,6 +577,7 @@ def create_mapping(project, img):
556
577
@iscsi .command (name = 'rm' , help = 'Remove ISCSI Mapping' )
557
578
@click .argument (constants .PROJECT_PARAMETER )
558
579
@click .argument (constants .IMAGE_NAME_PARAMETER )
580
+ @bmi_exception_wrapper
559
581
def delete_mapping (project , img ):
560
582
"""
561
583
Unmount image from iscsi server
@@ -578,6 +600,7 @@ def delete_mapping(project, img):
578
600
579
601
@iscsi .command (name = 'ls' , help = 'Show ISCSI Mappings' )
580
602
@click .argument (constants .PROJECT_PARAMETER )
603
+ @bmi_exception_wrapper
581
604
def show_mappings (project ):
582
605
"""
583
606
Show mounted images on iscsi
0 commit comments