Skip to content

Commit ff1b956

Browse files
committed
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 <[email protected]>
1 parent 0b7128e commit ff1b956

File tree

3 files changed

+69
-5
lines changed

3 files changed

+69
-5
lines changed

src/pybind/mgr/dashboard/controllers/nvmeof.py

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,18 @@ def io_stats(self, nqn: str, nsid: str, gw_group: Optional[str] = None):
342342
"create_image": Param(bool, "Create RBD image"),
343343
"size": Param(int, "RBD image size"),
344344
"rbd_image_size": Param(int, "RBD image size"),
345+
"trash_image": Param(bool, "Trash the RBD image when namespace is removed"),
345346
"block_size": Param(int, "NVMeoF namespace block size"),
346347
"load_balancing_group": Param(int, "Load balancing group"),
347348
"gw_group": Param(str, "NVMeoF gateway group", True, None),
349+
"force": Param(
350+
bool,
351+
"Force create namespace even it image is used by other namespace"
352+
),
353+
"no_auto_visible": Param(
354+
bool,
355+
"Namespace will be visible only for the allowed hosts"
356+
)
348357
},
349358
)
350359
@NvmeofCLICommand("nvmeof ns add")
@@ -358,9 +367,12 @@ def create(
358367
create_image: Optional[bool] = True,
359368
size: Optional[int] = 1024,
360369
rbd_image_size: Optional[int] = None,
370+
trash_image: Optional[bool] = False,
361371
block_size: int = 512,
362372
load_balancing_group: Optional[int] = None,
363373
gw_group: Optional[str] = None,
374+
force: Optional[bool] = False,
375+
no_auto_visible: Optional[bool] = False
364376
):
365377
return NVMeoFClient(gw_group=gw_group).stub.namespace_add(
366378
NVMeoFClient.pb2.namespace_add_req(
@@ -370,7 +382,10 @@ def create(
370382
block_size=block_size,
371383
create_image=create_image,
372384
size=rbd_image_size or size,
385+
trash_image=trash_image,
373386
anagrpid=load_balancing_group,
387+
force=force,
388+
no_auto_visible=no_auto_visible
374389
)
375390
)
376391

@@ -386,6 +401,7 @@ def create(
386401
"r_mbytes_per_second": Param(int, "Read MB/s"),
387402
"w_mbytes_per_second": Param(int, "Write MB/s"),
388403
"gw_group": Param(str, "NVMeoF gateway group", True, None),
404+
"trash_image": Param(bool, "Trash RBD image after removing namespace")
389405
},
390406
)
391407
@NvmeofCLICommand("nvmeof ns update")
@@ -401,7 +417,8 @@ def update(
401417
rw_mbytes_per_second: Optional[int] = None,
402418
r_mbytes_per_second: Optional[int] = None,
403419
w_mbytes_per_second: Optional[int] = None,
404-
gw_group: Optional[str] = None
420+
gw_group: Optional[str] = None,
421+
trash_image: Optional[bool] = None,
405422
):
406423
contains_failure = False
407424

@@ -440,11 +457,24 @@ def update(
440457
)
441458
if resp.status != 0:
442459
contains_failure = True
460+
461+
if trash_image is not None:
462+
resp = NVMeoFClient().stub.namespace_set_rbd_trash_image(
463+
NVMeoFClient.pb2.namespace_set_rbd_trash_image_req(
464+
subsystem_nqn=nqn,
465+
nsid=int(nsid),
466+
trash_image=str_to_bool(trash_image)
467+
)
468+
)
469+
if resp.status != 0:
470+
contains_failure = True
471+
472+
if contains_failure:
473+
cherrypy.response.status = 202
474+
443475
response = NVMeoFClient(gw_group=gw_group).stub.list_namespaces(
444476
NVMeoFClient.pb2.list_namespaces_req(subsystem=nqn, nsid=int(nsid))
445477
)
446-
if contains_failure:
447-
cherrypy.response.status = 202
448478
return response
449479

450480
@EndpointDoc(
@@ -453,14 +483,25 @@ def update(
453483
"nqn": Param(str, "NVMeoF subsystem NQN"),
454484
"nsid": Param(str, "NVMeoF Namespace ID"),
455485
"gw_group": Param(str, "NVMeoF gateway group", True, None),
486+
"force": Param(str, "Force remove the RBD image")
456487
},
457488
)
458489
@NvmeofCLICommand("nvmeof ns del")
459490
@empty_response
460491
@handle_nvmeof_error
461-
def delete(self, nqn: str, nsid: str, gw_group: Optional[str] = None):
492+
def delete(
493+
self,
494+
nqn: str,
495+
nsid: str,
496+
gw_group: Optional[str] = None,
497+
force: Optional[str] = "false"
498+
):
462499
return NVMeoFClient(gw_group=gw_group).stub.namespace_delete(
463-
NVMeoFClient.pb2.namespace_delete_req(subsystem_nqn=nqn, nsid=int(nsid))
500+
NVMeoFClient.pb2.namespace_delete_req(
501+
subsystem_nqn=nqn,
502+
nsid=int(nsid),
503+
i_am_sure=str_to_bool(force)
504+
)
464505
)
465506

466507
@APIRouter("/nvmeof/subsystem/{nqn}/host", Scope.NVME_OF)

src/pybind/mgr/dashboard/model/nvmeof.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class Namespace(NamedTuple):
6868
rw_mbytes_per_second: int
6969
r_mbytes_per_second: int
7070
w_mbytes_per_second: int
71+
trash_image: bool
7172

7273

7374
class NamespaceIOStats(NamedTuple):

src/pybind/mgr/dashboard/openapi.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9003,12 +9003,21 @@ paths:
90039003
default: true
90049004
description: Create RBD image
90059005
type: boolean
9006+
force:
9007+
default: false
9008+
description: Force create namespace even it image is used by other
9009+
namespace
9010+
type: boolean
90069011
gw_group:
90079012
description: NVMeoF gateway group
90089013
type: string
90099014
load_balancing_group:
90109015
description: Load balancing group
90119016
type: integer
9017+
no_auto_visible:
9018+
default: false
9019+
description: Namespace will be visible only for the allowed hosts
9020+
type: boolean
90129021
rbd_image_name:
90139022
description: RBD image name
90149023
type: string
@@ -9023,6 +9032,10 @@ paths:
90239032
default: 1024
90249033
description: RBD image size
90259034
type: integer
9035+
trash_image:
9036+
default: false
9037+
description: Trash the RBD image when namespace is removed
9038+
type: boolean
90269039
required:
90279040
- rbd_image_name
90289041
type: object
@@ -9072,6 +9085,12 @@ paths:
90729085
name: gw_group
90739086
schema:
90749087
type: string
9088+
- default: 'false'
9089+
description: Force remove the RBD image
9090+
in: query
9091+
name: force
9092+
schema:
9093+
type: string
90759094
responses:
90769095
'202':
90779096
content:
@@ -9174,6 +9193,9 @@ paths:
91749193
rw_mbytes_per_second:
91759194
description: Read/Write MB/s
91769195
type: integer
9196+
trash_image:
9197+
description: Trash RBD image after removing namespace
9198+
type: boolean
91779199
w_mbytes_per_second:
91789200
description: Write MB/s
91799201
type: integer

0 commit comments

Comments
 (0)