)
)
+ def _normalize_enum_key(val):
+ return val.replace("_", " ").title()
+
def _update_hosts(hosts_info_resp):
if hosts_info_resp.get('allow_any_host'):
hosts_info_resp['hosts'].insert(0, {"nqn": "*"})
+ hosts = hosts_info_resp.get('hosts')
+ if not hosts:
+ hosts = []
+ for h in hosts:
+ orig = h.get("dhchap_controller_origin")
+ if orig:
+ h["dhchap_controller_origin"] = _normalize_enum_key(orig)
return hosts_info_resp
@APIRouter("/nvmeof/subsystem/{nqn}/host", Scope.NVME_OF)
@handle_nvmeof_error
def create(
self, nqn: str, host_nqn: str, dhchap_key: Optional[str] = None,
+ dhchap_controller_key: Optional[str] = None,
psk: Optional[str] = None, gw_group: Optional[str] = None,
server_address: Optional[str] = None
):
).stub.add_host(
NVMeoFClient.pb2.add_host_req(
subsystem_nqn=nqn, host_nqn=host_nqn,
- dhchap_key=dhchap_key, psk=psk)
+ dhchap_key=dhchap_key,
+ dhchap_ctrlr_key=dhchap_controller_key,
+ psk=psk)
)
@empty_response
NVMeoFClient.pb2.change_host_key_req(
subsystem_nqn=nqn,
host_nqn=host_nqn,
- dhchap_key=dhchap_key)
+ dhchap_key=dhchap_key,
+ dhchap_ctrlr_key="-")
+ )
+
+ @empty_response
+ @NvmeofCLICommand("nvmeof host change_controller_key", model.RequestStatus)
+ @EndpointDoc(
+ "Change host DH-HMAC-CHAP controller key",
+ parameters={
+ "nqn": Param(str, "NVMeoF subsystem NQN"),
+ "host_nqn": Param(str, 'NVMeoF host NQN'),
+ "dhchap_controller_key": Param(str, 'Host DH-HMAC-CHAP controller key'),
+ "gw_group": Param(str, "NVMeoF gateway group", True, None),
+ "server_address": Param(str, "NVMeoF gateway address", True, None),
+ },
+ )
+ @convert_to_model(model.RequestStatus)
+ @handle_nvmeof_error
+ def change_controller_key(
+ self, nqn: str, host_nqn: str, dhchap_controller_key: str,
+ gw_group: Optional[str] = None, server_address: Optional[str] = None
+ ):
+ return NVMeoFClient(
+ gw_group=gw_group,
+ server_address=server_address
+ ).stub.change_host_key(
+ NVMeoFClient.pb2.change_host_key_req(subsystem_nqn=nqn,
+ host_nqn=host_nqn,
+ dhchap_key="-",
+ dhchap_ctrlr_key=dhchap_controller_key)
)
@empty_response
).stub.change_host_key(
NVMeoFClient.pb2.change_host_key_req(subsystem_nqn=nqn,
host_nqn=host_nqn,
- dhchap_key=None)
+ dhchap_key=None,
+ dhchap_ctrlr_key="-")
)
+ @empty_response
+ @NvmeofCLICommand("nvmeof host del_controller_key", model.RequestStatus)
+ @EndpointDoc(
+ "Delete host DH-HMAC-CHAP controller key",
+ parameters={
+ "nqn": Param(str, "NVMeoF subsystem NQN"),
+ "host_nqn": Param(str, 'NVMeoF host NQN.'),
+ "gw_group": Param(str, "NVMeoF gateway group", True, None),
+ "server_address": Param(str, "NVMeoF gateway address", True, None),
+ },
+ )
+ @convert_to_model(model.RequestStatus)
+ @handle_nvmeof_error
+ def del_controller_key(
+ self, nqn: str, host_nqn: str, gw_group: Optional[str] = None,
+ server_address: Optional[str] = None
+ ):
+ return NVMeoFClient(
+ gw_group=gw_group,
+ server_address=server_address
+ ).stub.change_host_key(
+ NVMeoFClient.pb2.change_host_key_req(subsystem_nqn=nqn,
+ host_nqn=host_nqn,
+ dhchap_key="-",
+ dhchap_ctrlr_key=None)
+ )
+
+ def _update_connections(connection_list_resp):
+ conns = hosts_info_resp.get('connections')
+ if not conns:
+ conns = []
+ for con in conns:
+ orig = con.get("dhchap_controller_origin")
+ if orig:
+ con["dhchap_controller_origin"] = _normalize_enum_key(
+ orig)
+ return connection_list_resp
+
@APIRouter("/nvmeof/subsystem/{nqn}/connection", Scope.NVME_OF)
@APIDoc("NVMe-oF Subsystem Connection Management API", "NVMe-oF Subsystem Connection")
class NVMeoFConnection(RESTController):
"server_address": Param(str, "NVMeoF gateway address", True, None),
},
)
- @convert_to_model(model.ConnectionList)
+ @convert_to_model(model.ConnectionList, finalize=_update_connections)
@handle_nvmeof_error
def list(self, nqn: Optional[str] = None,
gw_group: Optional[str] = None, server_address: Optional[str] = None):