1010
1111# from ..cephnvmeof.control.cli import GatewayClient
1212
13+ from typing import Optional
1314from ..security import Scope
1415from ..services .nvmeof_client import NVMeoFClient
15- from . import APIDoc , APIRouter , RESTController , Endpoint , ReadPermission , CreatePermission
16+ # from ..services.proto import gateway_pb2 as pb2
17+ from . import APIDoc , APIRouter , RESTController , Endpoint , ReadPermission , CreatePermission , \
18+ DeletePermission , allow_empty_body , UpdatePermission
19+
1620
17- @APIRouter ('/nvmeof' , Scope .ISCSI )
21+ @APIRouter ('/nvmeof' , Scope .NVME_OF )
1822@APIDoc ('NVMe-oF Management API' , 'NVMe-oF' )
1923class Nvmeof (RESTController ):
2024 @ReadPermission
2125 def list (self ):
2226 """List all NVMeoF gateways"""
2327 return NVMeoFClient ().get_subsystems ()
28+
29+
30+ @APIRouter ('/nvmeof/bdev' , Scope .NVME_OF )
31+ @APIDoc ('NVMe-oF Block Device Management API' , 'NVMe-oF' )
32+ class NvmeofBdev (RESTController ):
33+ @CreatePermission
34+ def create (self , name : str , rbd_pool : str , rbd_image : str , block_size : int , uuid : Optional [str ] = None ):
35+ """Create a new NVMeoF block device"""
36+ return NVMeoFClient ().create_bdev (name , rbd_pool , rbd_image , block_size , uuid )
37+
38+ @DeletePermission
39+ @allow_empty_body
40+ def delete (self , name : str , force : bool ):
41+ """Delete an existing NVMeoF block device"""
42+ return NVMeoFClient ().delete_bdev (name , force )
43+
44+ @Endpoint ('PUT' )
45+ @UpdatePermission
46+ @allow_empty_body
47+ def resize (self , name : str , size : int ):
48+ """Resize an existing NVMeoF block device"""
49+ return NVMeoFClient ().resize_bdev (name , size )
50+
51+
52+ @APIRouter ('/nvmeof/namespace' , Scope .NVME_OF )
53+ @APIDoc ('NVMe-oF Namespace Management API' , 'NVMe-oF' )
54+ class NvmeofNamespace (RESTController ):
55+ @CreatePermission
56+ def create (self , subsystem_nqn : str , bdev_name : str , nsid : int , anagrpid : Optional [str ] = None ):
57+ """Create a new NVMeoF namespace"""
58+ return NVMeoFClient ().create_namespace (subsystem_nqn , bdev_name , nsid , anagrpid )
59+
60+ @Endpoint ('DELETE' , path = '{subsystem_nqn}' )
61+ def delete (self , subsystem_nqn : str , nsid : int ):
62+ """Delete an existing NVMeoF namespace"""
63+ return NVMeoFClient ().delete_namespace (subsystem_nqn , nsid )
64+
65+ @APIRouter ('/nvmeof/subsystem' , Scope .NVME_OF )
66+ @APIDoc ('NVMe-oF Subsystem Management API' , 'NVMe-oF' )
67+ class NvmeofSubsystem (RESTController ):
68+ @CreatePermission
69+ def create (self , subsystem_nqn : str , serial_number : str , max_namespaces : int ,
70+ ana_reporting : bool , enable_ha : bool ) :
71+ """Create a new NVMeoF subsystem"""
72+ return NVMeoFClient ().create_subsystem (subsystem_nqn , serial_number , max_namespaces ,
73+ ana_reporting , enable_ha )
74+
75+ @Endpoint ('DELETE' , path = '{subsystem_nqn}' )
76+ def delete (self , subsystem_nqn : str ):
77+ """Delete an existing NVMeoF subsystem"""
78+ return NVMeoFClient ().delete_subsystem (subsystem_nqn )
79+
80+
81+ @APIRouter ('/nvmeof/hosts' , Scope .NVME_OF )
82+ @APIDoc ('NVMe-oF Host Management API' , 'NVMe-oF' )
83+ class NvmeofHost (RESTController ):
84+ @CreatePermission
85+ def create (self , subsystem_nqn : str , host_nqn : str ):
86+ """Create a new NVMeoF host"""
87+ return NVMeoFClient ().add_host (subsystem_nqn , host_nqn )
88+
89+ @Endpoint ('DELETE' )
90+ def delete (self , subsystem_nqn : str , host_nqn : str ):
91+ """Delete an existing NVMeoF host"""
92+ return NVMeoFClient ().remove_host (subsystem_nqn , host_nqn )
93+
94+
95+ @APIRouter ('/nvmeof/listener' , Scope .NVME_OF )
96+ @APIDoc ('NVMe-oF Listener Management API' , 'NVMe-oF' )
97+ class NvmeofListener (RESTController ):
98+ @CreatePermission
99+ def create (self , nqn : str , gateway : str , trtype : str , adrfam : str ,
100+ traddr : str , trsvcid : str ):
101+ """Create a new NVMeoF listener"""
102+ return NVMeoFClient ().create_listener (nqn , gateway , trtype , adrfam , traddr , trsvcid )
103+
104+ @Endpoint ('DELETE' )
105+ def delete (self , nqn : str , gateway : str , trtype , adrfam ,
106+ traddr : str , trsvcid : str ):
107+ """Delete an existing NVMeoF listener"""
108+ return NVMeoFClient ().delete_listener (nqn , gateway , trtype , adrfam , traddr , trsvcid )
0 commit comments