Skip to content

Commit 2b5720f

Browse files
authored
Merge pull request ceph#61643 from rhcs-dashboard/nvmeof-img-trash
mgr/dashboard: nvmeof trash rbd image on namespace rm Reviewed-by: Afreen Misbah <[email protected]>
2 parents 58faf00 + ff1b956 commit 2b5720f

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
@@ -9006,12 +9006,21 @@ paths:
90069006
default: true
90079007
description: Create RBD image
90089008
type: boolean
9009+
force:
9010+
default: false
9011+
description: Force create namespace even it image is used by other
9012+
namespace
9013+
type: boolean
90099014
gw_group:
90109015
description: NVMeoF gateway group
90119016
type: string
90129017
load_balancing_group:
90139018
description: Load balancing group
90149019
type: integer
9020+
no_auto_visible:
9021+
default: false
9022+
description: Namespace will be visible only for the allowed hosts
9023+
type: boolean
90159024
rbd_image_name:
90169025
description: RBD image name
90179026
type: string
@@ -9026,6 +9035,10 @@ paths:
90269035
default: 1024
90279036
description: RBD image size
90289037
type: integer
9038+
trash_image:
9039+
default: false
9040+
description: Trash the RBD image when namespace is removed
9041+
type: boolean
90299042
required:
90309043
- rbd_image_name
90319044
type: object
@@ -9075,6 +9088,12 @@ paths:
90759088
name: gw_group
90769089
schema:
90779090
type: string
9091+
- default: 'false'
9092+
description: Force remove the RBD image
9093+
in: query
9094+
name: force
9095+
schema:
9096+
type: string
90789097
responses:
90799098
'202':
90809099
content:
@@ -9177,6 +9196,9 @@ paths:
91779196
rw_mbytes_per_second:
91789197
description: Read/Write MB/s
91799198
type: integer
9199+
trash_image:
9200+
description: Trash RBD image after removing namespace
9201+
type: boolean
91809202
w_mbytes_per_second:
91819203
description: Write MB/s
91829204
type: integer

0 commit comments

Comments
 (0)