99from .. import mgr
1010from ..model import nvmeof as model
1111from ..security import Scope
12- from ..services .nvmeof_cli import NvmeofCLICommand
12+ from ..services .nvmeof_cli import NvmeofCLICommand , convert_to_bytes
1313from ..services .orchestrator import OrchClient
1414from ..tools import str_to_bool
1515from . import APIDoc , APIRouter , BaseController , CreatePermission , \
@@ -425,7 +425,6 @@ def io_stats(self, nqn: str, nsid: str, gw_group: Optional[str] = None,
425425 )
426426 },
427427 )
428- @NvmeofCLICommand ("nvmeof ns add" , model .NamespaceCreation )
429428 @convert_to_model (model .NamespaceCreation )
430429 @handle_nvmeof_error
431430 def create (
@@ -463,6 +462,49 @@ def create(
463462 )
464463 )
465464
465+ @NvmeofCLICommand ("nvmeof ns add" , model .NamespaceCreation )
466+ @convert_to_model (model .NamespaceCreation )
467+ @handle_nvmeof_error
468+ def create_cli (
469+ self ,
470+ nqn : str ,
471+ rbd_image_name : str ,
472+ rbd_pool : str = "rbd" ,
473+ create_image : Optional [bool ] = False ,
474+ size : Optional [str ] = None ,
475+ rbd_image_size : Optional [str ] = None ,
476+ trash_image : Optional [bool ] = False ,
477+ block_size : int = 512 ,
478+ load_balancing_group : Optional [int ] = None ,
479+ force : Optional [bool ] = False ,
480+ no_auto_visible : Optional [bool ] = False ,
481+ disable_auto_resize : Optional [bool ] = False ,
482+ read_only : Optional [bool ] = False ,
483+ gw_group : Optional [str ] = None ,
484+ traddr : Optional [str ] = None ,
485+ ):
486+ size_b = rbd_image_size_b = None
487+ if size :
488+ size_b = convert_to_bytes (size , default_unit = 'MB' )
489+ if rbd_image_size :
490+ rbd_image_size_b = convert_to_bytes (rbd_image_size , default_unit = 'MB' )
491+ return NVMeoFClient (gw_group = gw_group , traddr = traddr ).stub .namespace_add (
492+ NVMeoFClient .pb2 .namespace_add_req (
493+ subsystem_nqn = nqn ,
494+ rbd_image_name = rbd_image_name ,
495+ rbd_pool_name = rbd_pool ,
496+ block_size = block_size ,
497+ create_image = create_image ,
498+ size = rbd_image_size_b or size_b ,
499+ trash_image = trash_image ,
500+ anagrpid = load_balancing_group ,
501+ force = force ,
502+ no_auto_visible = no_auto_visible ,
503+ disable_auto_resize = disable_auto_resize ,
504+ read_only = read_only
505+ )
506+ )
507+
466508 @ReadPermission
467509 @Endpoint ('PUT' , '{nsid}/set_qos' )
468510 @EndpointDoc (
@@ -556,7 +598,6 @@ def change_load_balancing_group(
556598 "traddr" : Param (str , "NVMeoF gateway address" , True , None ),
557599 },
558600 )
559- @NvmeofCLICommand ("nvmeof ns resize" , model = model .RequestStatus )
560601 @convert_to_model (model .RequestStatus )
561602 @handle_nvmeof_error
562603 def resize (
@@ -576,6 +617,28 @@ def resize(
576617 )
577618 )
578619
620+ @NvmeofCLICommand ("nvmeof ns resize" , model = model .RequestStatus )
621+ @convert_to_model (model .RequestStatus )
622+ @handle_nvmeof_error
623+ def resize_cli (
624+ self ,
625+ nqn : str ,
626+ nsid : str ,
627+ rbd_image_size : str ,
628+ gw_group : Optional [str ] = None ,
629+ traddr : Optional [str ] = None
630+ ):
631+ if rbd_image_size :
632+ rbd_image_size_b = convert_to_bytes (rbd_image_size , default_unit = 'MB' )
633+ mib = 1024 * 1024
634+ rbd_image_size_mb = rbd_image_size_b // mib
635+
636+ return NVMeoFClient (gw_group = gw_group , traddr = traddr ).stub .namespace_resize (
637+ NVMeoFClient .pb2 .namespace_resize_req (
638+ subsystem_nqn = nqn , nsid = int (nsid ), new_size = rbd_image_size_mb
639+ )
640+ )
641+
579642 @ReadPermission
580643 @Endpoint ('PUT' , '{nsid}/add_host' )
581644 @EndpointDoc (
0 commit comments