Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use enum and not string for some GRPC fields #343

Merged
merged 1 commit into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 72 additions & 31 deletions control/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,53 +296,84 @@ def remove_host(self, args):
argument("-n", "--subnqn", help="Subsystem NQN", required=True),
argument("-g", "--gateway-name", help="Gateway name", required=True),
argument("-t", "--trtype", help="Transport type", default="TCP"),
argument("-f", "--adrfam", help="Address family", default="ipv4"),
argument("-f", "--adrfam", help="Address family", default="IPV4"),
argument("-a", "--traddr", help="NVMe host IP", required=True),
argument("-s", "--trsvcid", help="Port number", default="4420", required=False),
])
def create_listener(self, args):
"""Creates a listener for a subsystem at a given IP/Port."""
traddr = GatewayConfig.escape_address_if_ipv6(args.traddr)
req = pb2.create_listener_req(
nqn=args.subnqn,
gateway_name=args.gateway_name,
trtype=args.trtype,
adrfam=args.adrfam,
traddr=traddr,
trsvcid=args.trsvcid,
)
ret = self.stub.create_listener(req)
self.logger.info(f"Created {args.subnqn} listener at {traddr}:{args.trsvcid}: {ret.status}")
trtype = None
adrfam = None
if args.trtype:
trtype = args.trtype.upper()
if args.adrfam:
adrfam = args.adrfam.lower()
try:
req = pb2.create_listener_req(
nqn=args.subnqn,
gateway_name=args.gateway_name,
trtype=trtype,
adrfam=adrfam,
traddr=traddr,
trsvcid=args.trsvcid,
)
ret = self.stub.create_listener(req)
self.logger.info(f"Created {args.subnqn} listener at {traddr}:{args.trsvcid}: {ret.status}")
except ValueError as err:
self.logger.error(f"{err}")
self.logger.info(f"Created {args.subnqn} listener at {traddr}:{args.trsvcid}: {False}")
raise
except Exception as ex:
self.logger.info(f"Created {args.subnqn} listener at {traddr}:{args.trsvcid}: {False}")
raise

@cli.cmd([
argument("-n", "--subnqn", help="Subsystem NQN", required=True),
argument("-g", "--gateway-name", help="Gateway name", required=True),
argument("-t", "--trtype", help="Transport type", default="TCP"),
argument("-f", "--adrfam", help="Address family", default="ipv4"),
argument("-f", "--adrfam", help="Address family", default="IPV4"),
argument("-a", "--traddr", help="NVMe host IP", required=True),
argument("-s", "--trsvcid", help="Port number", default="4420", required=False),
])
def delete_listener(self, args):
"""Deletes a listener from a subsystem at a given IP/Port."""
traddr = GatewayConfig.escape_address_if_ipv6(args.traddr)
req = pb2.delete_listener_req(
nqn=args.subnqn,
gateway_name=args.gateway_name,
trtype=args.trtype,
adrfam=args.adrfam,
traddr=traddr,
trsvcid=args.trsvcid,
)
ret = self.stub.delete_listener(req)
self.logger.info(f"Deleted {traddr}:{args.trsvcid} from {args.subnqn}: {ret.status}")
trtype = None
adrfam = None
if args.trtype:
trtype = args.trtype.upper()
if args.adrfam:
adrfam = args.adrfam.lower()
gbregman marked this conversation as resolved.
Show resolved Hide resolved
try:
req = pb2.delete_listener_req(
nqn=args.subnqn,
gateway_name=args.gateway_name,
trtype=trtype,
adrfam=adrfam,
traddr=traddr,
trsvcid=args.trsvcid,
)
ret = self.stub.delete_listener(req)
self.logger.info(f"Deleted {traddr}:{args.trsvcid} from {args.subnqn}: {ret.status}")
except ValueError as err:
barakda marked this conversation as resolved.
Show resolved Hide resolved
self.logger.error(f"{err}")
self.logger.info(f"Deleted {traddr}:{args.trsvcid} from {args.subnqn}: {False}")
raise
except Exception as ex:
self.logger.info(f"Deleted {traddr}:{args.trsvcid} from {args.subnqn}: {False}")
raise

@cli.cmd()
def get_subsystems(self, args):
"""Gets subsystems."""
subsystems = json_format.MessageToJson(
self.stub.get_subsystems(pb2.get_subsystems_req()),
indent=4,
indent=4, including_default_value_fields=True,
preserving_proto_field_name=True)
# The address family enum values are lower case, convert them for display
subsystems = subsystems.replace('"adrfam": "ipv4"', '"adrfam": "IPv4"')
subsystems = subsystems.replace('"adrfam": "ipv6"', '"adrfam": "IPv6"')
self.logger.info(f"Get subsystems:\n{subsystems}")

@cli.cmd()
Expand All @@ -363,21 +394,31 @@ def disable_spdk_nvmf_logs(self, args):
f"Disable SPDK nvmf logs: {ret.status}")

@cli.cmd([
argument("-f", "--flags", help="SPDK nvmf enable flags", \
action='store_true', required=True),
argument("-l", "--log_level", \
help="SPDK nvmf log level (ERROR, WARNING, NOTICE, INFO, DEBUG)", required=False),
argument("-p", "--log_print_level", \
help="SPDK nvmf log print level (ERROR, WARNING, NOTICE, INFO, DEBUG)", \
required=False),
])
def set_spdk_nvmf_logs(self, args):
"""Set spdk nvmf log and flags"""
req = pb2.set_spdk_nvmf_logs_req(flags=args.flags, log_level=args.log_level, \
print_level=args.log_print_level)
ret = self.stub.set_spdk_nvmf_logs(req)
self.logger.info(
f"Set SPDK nvmf logs : {ret.status}")
"""Set spdk nvmf log and print levels"""
log_level = None
print_level = None
if args.log_level:
log_level = args.log_level.upper()
if args.log_print_level:
print_level = args.log_print_level.upper()
try:
req = pb2.set_spdk_nvmf_logs_req(log_level=log_level, print_level=print_level)
ret = self.stub.set_spdk_nvmf_logs(req)
self.logger.info(f"Set SPDK nvmf logs: {ret.status}")
except ValueError as err:
self.logger.error(f"{err}")
self.logger.info(f"Set SPDK nvmf logs: {False}")
raise
except Exception as ex:
self.logger.info(f"Set SPDK nvmf logs: {False}")
raise

@cli.cmd()
def get_gateway_info(self, args):
Expand Down
3 changes: 3 additions & 0 deletions control/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class GatewayConfig:
Instance attributes:
config: Config parser object
"""

DISCOVERY_NQN = "nqn.2014-08.org.nvmexpress.discovery"

def __init__(self, conffile):
self.filepath = conffile
self.conffile_logged = False
Expand Down
31 changes: 10 additions & 21 deletions control/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import logging
from .config import GatewayConfig
from .state import GatewayState, LocalGatewayState, OmapGatewayState, GatewayStateHandler
from .grpc import GatewayEnumUtils
from .proto import gateway_pb2 as pb2

import rados
from typing import Dict, Optional
Expand Down Expand Up @@ -82,21 +84,6 @@ class NVMF_SUBTYPE(enum.IntFlag):
# NVMe type for NVM subsystem
NVME = 0x2

# NVMe over Fabrics transport types
class TRANSPORT_TYPES(enum.IntFlag):
RDMA = 0x1
FC = 0x2
TCP = 0x3
INTRA_HOST = 0xfe

# Address family types
class ADRFAM_TYPES(enum.IntFlag):
ipv4 = 0x1
ipv6 = 0x2
ib = 0x3
fc = 0x4
intra_host = 0xfe

# Transport requirement, secure channel requirements
# Connections shall be made over a fabric secure channel
class NVMF_TREQ_SECURE_CHANNEL(enum.IntFlag):
Expand Down Expand Up @@ -304,8 +291,6 @@ class DiscoveryService:
discovery_port: Discovery controller's listening port
"""

DISCOVERY_NQN = "nqn.2014-08.org.nvmexpress.discovery"

def __init__(self, config):
self.version = 1
self.config = config
Expand Down Expand Up @@ -733,14 +718,18 @@ def reply_get_log_page(self, conn, data, cmd_id):
log_entry_counter = 0
while log_entry_counter < len(allow_listeners):
log_entry = DiscoveryLogEntry()
trtype = TRANSPORT_TYPES[allow_listeners[log_entry_counter]["trtype"].upper()]
log_trtype = allow_listeners[log_entry_counter]["trtype"]
log_adrfam = allow_listeners[log_entry_counter]["adrfam"]
trtype = GatewayEnumUtils.get_value_from_key(pb2.TransportType, log_trtype, True)
adrfam = GatewayEnumUtils.get_value_from_key(pb2.AddressFamily, log_adrfam, True)

if trtype is None:
self.logger.error("unsupported transport type")
self.logger.error(f"unsupported transport type {log_trtype}")
else:
log_entry.trtype = trtype
adrfam = ADRFAM_TYPES[allow_listeners[log_entry_counter]["adrfam"].lower()]

if adrfam is None:
self.logger.error("unsupported adress family")
self.logger.error(f"unsupported address family {log_adrfam}")
else:
log_entry.adrfam = adrfam
log_entry.subtype = NVMF_SUBTYPE.NVME
Expand Down
Loading