# -*- coding: utf-8 -*-
import errno
import json
+import traceback
from abc import ABC, abstractmethod
from enum import Enum
from typing import Annotated, Any, Dict, List, NamedTuple, Optional, Type, \
from ..model.nvmeof import CliFieldTransformer, CliFlags, CliHeader
from ..rest_client import RequestException
+from ..exceptions import DashboardException
from .nvmeof_conf import ManagedByOrchestratorException, \
- NvmeofGatewayAlreadyExists, NvmeofGatewaysConfig
-
+ NvmeofGatewayAlreadyExists, NvmeofGatewaysConfig, is_mtls_enabled
+try:
+ from .proto import gateway_pb2 as pb2 # type: ignore
+ from .proto import gateway_pb2_grpc as pb2_grpc # type: ignore
+
@CLIReadCommand('dashboard nvmeof-gateway-list')
def list_nvmeof_gateways(_):
'''
if not (prefix == '' and suffix == 'iB')
}
+@CLIReadCommand('dashboard nvmeof-dbg')
+def list_nvmeof_gateways(_):
+ try:
+ res = NvmeofGatewaysConfig.get_service_info()
+ if res is None:
+ raise DashboardException("Gateway group does not exists")
+ service_name, gateway_addr = res
+ except TypeError as e:
+ raise DashboardException(
+ f'Unable to retrieve the gateway info: {e}'
+ )
+
+ client_key = NvmeofGatewaysConfig.get_client_key(service_name)
+ client_cert = NvmeofGatewaysConfig.get_client_cert(service_name)
+ server_cert = NvmeofGatewaysConfig.get_server_cert(service_name)
+ mtls_enabled = is_mtls_enabled(service_name)
+
+ channel_err = None
+ credentials = None
+ channel = None
+ stub = None
+ gw_info_msg = None
+ msg_dict = None
+ try:
+ credentials = grpc.ssl_channel_credentials(
+ root_certificates=server_cert,
+ private_key=client_key,
+ certificate_chain=client_cert,
+ )
+ channel = grpc.secure_channel(gateway_addr, credentials)
+
+ stub = pb2_grpc.GatewayStub(channel)
+ gw_info_msg = stub.get_gateway_info(NVMeoFClient.pb2.get_gateway_info_req())
+ msg_dict = MessageToDict(gw_info_msg, including_default_value_fields=True,
+ preserving_proto_field_name=True) # type: ignore
+ except Exception as e:
+ channel_err = traceback.format_exc()
+
+ resp = {
+ "gw_addr": gateway_addr,
+ "client_key": client_key,
+ "client_cert": client_cert,
+ "server_cert": server_cert,
+ "gw_config": NvmeofGatewaysConfig.get_gateways_config(),
+
+ "channel_err": channel_err,
+ "channel_flag": bool(channel),
+ "stub_flag": bool(stub),
+ "gw_info_msg_flag": bool(gw_info_msg),
+ "msg_dict": msg_dict,
+
+ }
+ return 0, json.dumps(resp), ''
def convert_to_bytes(size: Union[int, str], default_unit=None):
if isinstance(size, int):