From f1b9f82234015201302ac2e080b135031b41b273 Mon Sep 17 00:00:00 2001 From: Mykola Golub Date: Sun, 21 Nov 2021 08:30:01 +0000 Subject: [PATCH] nvme_gw: allow to list subsystems Signed-off-by: Mykola Golub --- nvme_gw_cli.py | 15 +++++++++++++++ nvme_gw_server.py | 19 +++++++++++++++++++ proto/nvme_gw.proto | 10 ++++++++++ 3 files changed, 44 insertions(+) diff --git a/nvme_gw_cli.py b/nvme_gw_cli.py index ee71dd283..5b3d2b755 100644 --- a/nvme_gw_cli.py +++ b/nvme_gw_cli.py @@ -9,6 +9,7 @@ import argparse import grpc +import json import nvme_gw_pb2_grpc as pb2_grpc import nvme_gw_pb2 as pb2 import nvme_gw_config @@ -258,6 +259,20 @@ def create_listener(self, args): self.logger.error(f"Failed to create listener: \n {error}") + @cli.cmd() + def get_subsystems(self, args): + """Get subsystems.""" + + try: + get_req = pb2.subsystems_get_req() + ret = self.stub.nvmf_get_subsystems(get_req) + subsystems = json.loads(ret.subsystems) + formatted_subsystems = json.dumps(subsystems, indent=4) + self.logger.info(f"Get subsystems:\n{formatted_subsystems}") + except Exception as error: + self.logger.error(f"Failed to get subsystems: \n {error}") + + def main(): client = GatewayClient() args = client.cli.parser.parse_args() diff --git a/nvme_gw_server.py b/nvme_gw_server.py index 7ecd12ede..42236793a 100644 --- a/nvme_gw_server.py +++ b/nvme_gw_server.py @@ -16,6 +16,7 @@ import nvme_gw_pb2 as pb2 import nvme_gw_config import argparse +import json class GWService(pb2_grpc.NVMEGatewayServicer): @@ -254,6 +255,24 @@ def nvmf_subsystem_add_listener(self, request, context): return pb2.req_status(status=return_string) + def nvmf_get_subsystems(self, request, context): + # Get NVMe Subsystems + self.logger.info({ + f"Received request to get subsystems", + }) + + try: + ret = self.spdk_rpc.nvmf.nvmf_get_subsystems( + self.client, + ) + self.logger.info(f"returned with: {ret}") + except Exception as ex: + self.logger.error(f"get_subsystems failed with: \n {ex}") + context.set_code(grpc.StatusCode.INTERNAL) + context.set_details(f"{ex}") + return pb2.subsystems_info() + + return pb2.subsystems_info(subsystems=json.dumps(ret)) def serve(gw_config_filename): diff --git a/proto/nvme_gw.proto b/proto/nvme_gw.proto index 7490d98f9..8e6c7ecf4 100644 --- a/proto/nvme_gw.proto +++ b/proto/nvme_gw.proto @@ -40,6 +40,9 @@ service NVMEGateway { // Add an SPDK-NVMf listener at a given IP addr/ tcp port rpc nvmf_subsystem_add_listener(subsystem_add_listener_req) returns(req_status) {} + + // Get NVMf Subsystems + rpc nvmf_get_subsystems(subsystems_get_req) returns(subsystems_info) {} } message spdk_start_req { @@ -129,3 +132,10 @@ message subsystem_add_listener_req { string trsvcid = 6; } +message subsystems_get_req { +} + +message subsystems_info { + string subsystems = 1; +} +