From: Nizamudeen A Date: Tue, 4 Feb 2025 12:03:11 +0000 (+0530) Subject: mgr/dashboard: nvmeof trash rbd image on namespace rm X-Git-Tag: v20.0.0~7^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ff1b956551169078b53defa05cf4b3973bba2188;p=ceph.git mgr/dashboard: nvmeof trash rbd image on namespace rm A trash_image param is introduced to create namespace API. When that is set, if the user force remove the namepsace it'll also remove the rbd image. Fixes: https://tracker.ceph.com/issues/69787 Signed-off-by: Nizamudeen A --- diff --git a/src/pybind/mgr/dashboard/controllers/nvmeof.py b/src/pybind/mgr/dashboard/controllers/nvmeof.py index 4ae3f79ed30..3ca1775349a 100644 --- a/src/pybind/mgr/dashboard/controllers/nvmeof.py +++ b/src/pybind/mgr/dashboard/controllers/nvmeof.py @@ -342,9 +342,18 @@ else: "create_image": Param(bool, "Create RBD image"), "size": Param(int, "RBD image size"), "rbd_image_size": Param(int, "RBD image size"), + "trash_image": Param(bool, "Trash the RBD image when namespace is removed"), "block_size": Param(int, "NVMeoF namespace block size"), "load_balancing_group": Param(int, "Load balancing group"), "gw_group": Param(str, "NVMeoF gateway group", True, None), + "force": Param( + bool, + "Force create namespace even it image is used by other namespace" + ), + "no_auto_visible": Param( + bool, + "Namespace will be visible only for the allowed hosts" + ) }, ) @NvmeofCLICommand("nvmeof ns add") @@ -358,9 +367,12 @@ else: create_image: Optional[bool] = True, size: Optional[int] = 1024, rbd_image_size: Optional[int] = None, + trash_image: Optional[bool] = False, block_size: int = 512, load_balancing_group: Optional[int] = None, gw_group: Optional[str] = None, + force: Optional[bool] = False, + no_auto_visible: Optional[bool] = False ): return NVMeoFClient(gw_group=gw_group).stub.namespace_add( NVMeoFClient.pb2.namespace_add_req( @@ -370,7 +382,10 @@ else: block_size=block_size, create_image=create_image, size=rbd_image_size or size, + trash_image=trash_image, anagrpid=load_balancing_group, + force=force, + no_auto_visible=no_auto_visible ) ) @@ -386,6 +401,7 @@ else: "r_mbytes_per_second": Param(int, "Read MB/s"), "w_mbytes_per_second": Param(int, "Write MB/s"), "gw_group": Param(str, "NVMeoF gateway group", True, None), + "trash_image": Param(bool, "Trash RBD image after removing namespace") }, ) @NvmeofCLICommand("nvmeof ns update") @@ -401,7 +417,8 @@ else: rw_mbytes_per_second: Optional[int] = None, r_mbytes_per_second: Optional[int] = None, w_mbytes_per_second: Optional[int] = None, - gw_group: Optional[str] = None + gw_group: Optional[str] = None, + trash_image: Optional[bool] = None, ): contains_failure = False @@ -440,11 +457,24 @@ else: ) if resp.status != 0: contains_failure = True + + if trash_image is not None: + resp = NVMeoFClient().stub.namespace_set_rbd_trash_image( + NVMeoFClient.pb2.namespace_set_rbd_trash_image_req( + subsystem_nqn=nqn, + nsid=int(nsid), + trash_image=str_to_bool(trash_image) + ) + ) + if resp.status != 0: + contains_failure = True + + if contains_failure: + cherrypy.response.status = 202 + response = NVMeoFClient(gw_group=gw_group).stub.list_namespaces( NVMeoFClient.pb2.list_namespaces_req(subsystem=nqn, nsid=int(nsid)) ) - if contains_failure: - cherrypy.response.status = 202 return response @EndpointDoc( @@ -453,14 +483,25 @@ else: "nqn": Param(str, "NVMeoF subsystem NQN"), "nsid": Param(str, "NVMeoF Namespace ID"), "gw_group": Param(str, "NVMeoF gateway group", True, None), + "force": Param(str, "Force remove the RBD image") }, ) @NvmeofCLICommand("nvmeof ns del") @empty_response @handle_nvmeof_error - def delete(self, nqn: str, nsid: str, gw_group: Optional[str] = None): + def delete( + self, + nqn: str, + nsid: str, + gw_group: Optional[str] = None, + force: Optional[str] = "false" + ): return NVMeoFClient(gw_group=gw_group).stub.namespace_delete( - NVMeoFClient.pb2.namespace_delete_req(subsystem_nqn=nqn, nsid=int(nsid)) + NVMeoFClient.pb2.namespace_delete_req( + subsystem_nqn=nqn, + nsid=int(nsid), + i_am_sure=str_to_bool(force) + ) ) @APIRouter("/nvmeof/subsystem/{nqn}/host", Scope.NVME_OF) diff --git a/src/pybind/mgr/dashboard/model/nvmeof.py b/src/pybind/mgr/dashboard/model/nvmeof.py index 2888f2c6573..7661bae305d 100644 --- a/src/pybind/mgr/dashboard/model/nvmeof.py +++ b/src/pybind/mgr/dashboard/model/nvmeof.py @@ -68,6 +68,7 @@ class Namespace(NamedTuple): rw_mbytes_per_second: int r_mbytes_per_second: int w_mbytes_per_second: int + trash_image: bool class NamespaceIOStats(NamedTuple): diff --git a/src/pybind/mgr/dashboard/openapi.yaml b/src/pybind/mgr/dashboard/openapi.yaml index b55463af77b..faca08a773f 100755 --- a/src/pybind/mgr/dashboard/openapi.yaml +++ b/src/pybind/mgr/dashboard/openapi.yaml @@ -9003,12 +9003,21 @@ paths: default: true description: Create RBD image type: boolean + force: + default: false + description: Force create namespace even it image is used by other + namespace + type: boolean gw_group: description: NVMeoF gateway group type: string load_balancing_group: description: Load balancing group type: integer + no_auto_visible: + default: false + description: Namespace will be visible only for the allowed hosts + type: boolean rbd_image_name: description: RBD image name type: string @@ -9023,6 +9032,10 @@ paths: default: 1024 description: RBD image size type: integer + trash_image: + default: false + description: Trash the RBD image when namespace is removed + type: boolean required: - rbd_image_name type: object @@ -9072,6 +9085,12 @@ paths: name: gw_group schema: type: string + - default: 'false' + description: Force remove the RBD image + in: query + name: force + schema: + type: string responses: '202': content: @@ -9174,6 +9193,9 @@ paths: rw_mbytes_per_second: description: Read/Write MB/s type: integer + trash_image: + description: Trash RBD image after removing namespace + type: boolean w_mbytes_per_second: description: Write MB/s type: integer