@@ -1726,6 +1726,10 @@ def ns_add(self, args):
1726
1726
self .cli .parser .error ("--size argument is not allowed for add command when "
1727
1727
"RBD image creation is disabled" )
1728
1728
1729
+ if args .rbd_trash_image_on_delete and not args .rbd_create_image :
1730
+ self .cli .parser .error ("Can't trash associated RBD image on delete if it wasn't "
1731
+ "created automatically by the gateway" )
1732
+
1729
1733
req = pb2 .namespace_add_req (rbd_pool_name = args .rbd_pool ,
1730
1734
rbd_image_name = args .rbd_image ,
1731
1735
subsystem_nqn = args .subsystem ,
@@ -1736,7 +1740,8 @@ def ns_add(self, args):
1736
1740
create_image = args .rbd_create_image ,
1737
1741
size = img_size ,
1738
1742
force = args .force ,
1739
- no_auto_visible = args .no_auto_visible )
1743
+ no_auto_visible = args .no_auto_visible ,
1744
+ trash_image = args .rbd_trash_image_on_delete )
1740
1745
try :
1741
1746
ret = self .stub .namespace_add (req )
1742
1747
except Exception as ex :
@@ -1776,7 +1781,7 @@ def ns_del(self, args):
1776
1781
1777
1782
try :
1778
1783
ret = self .stub .namespace_delete (pb2 .namespace_delete_req (
1779
- subsystem_nqn = args .subsystem , nsid = args .nsid ))
1784
+ subsystem_nqn = args .subsystem , nsid = args .nsid , are_you_sure = args . are_you_sure ))
1780
1785
except Exception as ex :
1781
1786
ret = pb2 .req_status (status = errno .EINVAL ,
1782
1787
error_message = f"Failure deleting namespace:\n { ex } " )
@@ -1925,15 +1930,15 @@ def ns_list(self, args):
1925
1930
namespaces_list = []
1926
1931
for ns in namespaces_info .namespaces :
1927
1932
if args .subsystem == GatewayUtils .ALL_SUBSYSTEMS :
1928
- if not ns .subsystem_nqn :
1933
+ if not ns .ns_subsystem_nqn :
1929
1934
err_func (f"Got namespace with ID { ns .nsid } on an unknown subsystem" )
1930
1935
subsys_nqn = "<n/a>"
1931
1936
else :
1932
- subsys_nqn = ns .subsystem_nqn
1937
+ subsys_nqn = ns .ns_subsystem_nqn
1933
1938
else :
1934
- if ns .subsystem_nqn and ns .subsystem_nqn != args .subsystem :
1939
+ if ns .ns_subsystem_nqn and ns .ns_subsystem_nqn != args .subsystem :
1935
1940
err_func (f"Got a namespace with ID { ns .nsid } in subsystem "
1936
- f"{ ns .subsystem_nqn } which is different than the "
1941
+ f"{ ns .ns_subsystem_nqn } which is different than the "
1937
1942
f"requested one { args .subsystem } " )
1938
1943
return errno .ENODEV
1939
1944
subsys_nqn = namespaces_info .subsystem_nqn
@@ -1960,10 +1965,11 @@ def ns_list(self, args):
1960
1965
else :
1961
1966
visibility = "Restrictive"
1962
1967
1968
+ trash_msg = "\n (trash on deletion)" if ns .trash_image else ""
1963
1969
namespaces_list .append ([subsys_nqn ,
1964
1970
ns .nsid ,
1965
1971
break_string (ns .bdev_name , "-" , 2 ),
1966
- f"{ ns .rbd_pool_name } /{ ns .rbd_image_name } " ,
1972
+ f"{ ns .rbd_pool_name } /{ ns .rbd_image_name } { trash_msg } " ,
1967
1973
self .format_size (ns .rbd_image_size ),
1968
1974
self .format_size (ns .block_size ),
1969
1975
break_string (ns .uuid , "-" , 3 ),
@@ -2454,12 +2460,20 @@ def ns_change_visibility(self, args):
2454
2460
help = "Make the namespace visible only to specific hosts" ,
2455
2461
action = 'store_true' ,
2456
2462
required = False ),
2463
+ argument ("--rbd-trash-image-on-delete" ,
2464
+ help = "When deleting the namespace, trash associated RBD image. "
2465
+ "Only applies to images created automatically by the gateway" ,
2466
+ action = 'store_true' ,
2467
+ required = False ),
2457
2468
]
2458
2469
ns_del_args_list = ns_common_args + [
2459
2470
argument ("--nsid" ,
2460
2471
help = "Namespace ID" ,
2461
2472
type = int ,
2462
2473
required = True ),
2474
+ argument ("--are-you-sure" ,
2475
+ help = "If you choose to delete the associated RBD image, set this to \" yes\" " ,
2476
+ required = False ),
2463
2477
]
2464
2478
ns_resize_args_list = ns_common_args + [
2465
2479
argument ("--nsid" ,
0 commit comments