Skip to content

Commit

Permalink
Some more review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
anitashekar committed Oct 27, 2021
1 parent 366c382 commit 83c466a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 60 deletions.
33 changes: 15 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Management gateway daemon to setup access to Ceph storage over NVMeoF

This daemon runs as root. It provides the ability to export existing RBD images as NVMeoF namespaces. Creation of RBD images is not within the scope of this daemon.

# Initial configuration:
# Initial configuration

1. The daemon is a gRPC server, so the host running the server will need to install gRPC packages:

Expand All @@ -16,25 +16,26 @@ This daemon runs as root. It provides the ability to export existing RBD images
gateway_addr = <IP address at which the client can reach the gateway>
gateway_port = <port at which the client can reach the gateway>

2. To [enable mTLS](#mtls-configuration-for-testing-purposes) using self signed certificates, edit the config file to set:
3. To [enable mTLS](#mtls-configuration-for-testing-purposes) using self signed certificates, edit the config file to set:

enable_auth = True # Setting this to False will open an insecure port

3. Compiling protobuf files for grpc:
4. Compiling protobuf files for gRPC:

$ python3 -m grpc_tools.protoc --proto_path=./proto ./proto/nvme_gw.proto --python_out=. --grpc_python_out=.

4. SPDK v21.04 is included in this repository. Edit the config file to set:
5. SPDK v21.04 is included in this repository. Edit the config file to set:

spdk_path = <complete path to SPDK parent directory>
spdk_tgt = <relative path to SPDK target executable>
5. Setup SPDK

6. Setup SPDK

Navigate to the spdk folder & install dependencies:

$ ./scripts/pkgdep.sh

Intialize configuration:
Initialize configuration:

$ apt install librbd-dev
$ ./configure --with-rbd
Expand All @@ -47,18 +48,16 @@ This daemon runs as root. It provides the ability to export existing RBD images

$ sh -c 'echo 4096 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages'


6. Start the gateway server daemon:
7. Start the gateway server daemon:

$ python3 nvme_gw_server.py [-c config_filename]



# CLI Usage

The CLI code can be used to initiate a connection to the gateway and run commands to configure the NVMe targets.
The CLI tool can be used to initiate a connection to the gateway and run commands to configure the NVMe targets.

Run the code with the -h flag to see a list of available commands:
Run the tool with the -h flag to see a list of available commands:

$ python3 ./nvme_gw_cli.py -h
usage: python3 ./nvme_gw_cli.py [-h] [-c CONFIG]
Expand Down Expand Up @@ -92,15 +91,15 @@ Example:

# mTLS Configuration for testing purposes

For testing purposes, self signed certificates & keys can be generated locally using OpenSSL.
For testing purposes, self signed certificates and keys can be generated locally using OpenSSL.

For the server, generate credentials for server name 'my.server' in files called server.key & server.crt:
For the server, generate credentials for server name 'my.server' in files called server.key and server.crt:

% openssl req -x509 -newkey rsa:4096 -nodes -keyout server.key -out server.crt -days 3650 -subj '/CN=my.server'
$ openssl req -x509 -newkey rsa:4096 -nodes -keyout server.key -out server.crt -days 3650 -subj '/CN=my.server'

For client:

% openssl req -x509 -newkey rsa:4096 -nodes -keyout client.key -out client.crt -days 3650 -subj '/CN=client1'
$ openssl req -x509 -newkey rsa:4096 -nodes -keyout client.key -out client.crt -days 3650 -subj '/CN=client1'

Indicate the location of the keys and certificates in the config file:

Expand All @@ -117,7 +116,7 @@ Indicate the location of the keys and certificates in the config file:

$ python3 nvme_gw_server.py
INFO:root:SPDK PATH: /path/to/spdk
INFO:root:Starting /path.to/spdk/tgt/nvmf_tgt all -u
INFO:root:Starting /path/to/spdk/tgt/nvmf_tgt all -u
INFO:root:Attempting to initialize SPDK: server_addr: /var/tmp/spdk.sock, port: 5260, conn_retries: 3, timeout: 60.0
INFO: Setting log level to ERROR
INFO:JSONRPCClient(/var/tmp/spdk.sock):Setting log level to ERROR
Expand Down Expand Up @@ -202,6 +201,4 @@ Indicate the location of the keys and certificates in the config file:

$ ls /mnt
lost+found test.txt


79 changes: 38 additions & 41 deletions nvme_gw_cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Copyright (c) 2021 International Business Machines
# All rights reserved.

# SPDX-License-Identifier: LGPL-3.0-or-later

# Authors: [email protected], [email protected]
#
# Copyright (c) 2021 International Business Machines
# All rights reserved.
#
# SPDX-License-Identifier: LGPL-3.0-or-later
#
# Authors: [email protected], [email protected]
#

import argparse
import grpc
Expand All @@ -13,20 +15,18 @@


def argument(*name_or_flags, **kwargs):
#
# Helper function to format arguments for argparse command decorator.
#
"""Helper function to format arguments for argparse command decorator."""

return (list(name_or_flags), kwargs)


class Parser:
"""Class to simplify creation of client CLI.
# Class to simplify creation of client CLI.

# Instance attributes:
# parser: ArgumentParser object.
# subparsers: Action object to add subcommands to main argument parser.

Instance attributes:
parser: ArgumentParser object.
subparsers: Action object to add subcommands to main argument parser.
"""
def __init__(self):
self.parser = argparse.ArgumentParser(
prog="python3 ./nvme_gw_cli.py",
Expand All @@ -42,12 +42,11 @@ def __init__(self):
self.subparsers = self.parser.add_subparsers(dest="subcommand")

def cmd(self, args=[]):
"""Decorator to create an argparse command.
# Decorator to create an argparse command.

# The arguments to this decorator are used as arguments for the argparse
# command.

The arguments to this decorator are used as arguments for the argparse
command.
"""
def decorator(func):
parser = self.subparsers.add_parser(func.__name__,
description=func.__doc__)
Expand All @@ -62,18 +61,18 @@ def decorator(func):


class GatewayClient:
"""Client for gRPC functionality with a gateway server.
# Client for gRPC functionality with a gateway server.

# Contains methods to send RPC calls to the server and specifications for the
# associated command line arguments.
Contains methods to send RPC calls to the server and specifications for the
associated command line arguments.
# Class attributes:
# cli: Parser object
Class attributes:
cli: Parser object
# Instance attributes: * Must be initialized with GatewayClient.connect *
# stub: Object on which to call server methods
# logger: Logger instance to track client events
Instance attributes: * Must be initialized with GatewayClient.connect *
stub: Object on which to call server methods
logger: Logger instance to track client events
"""

cli = Parser()

Expand All @@ -83,23 +82,22 @@ def __init__(self):

@property
def stub(self):
# Object on which to call server methods.
"""Object on which to call server methods."""

if self._stub is None:
raise AttributeError("stub is None. Set with connect method.")
return self._stub

@property
def logger(self):
# Logger instance to track client events.
"""Logger instance to track client events."""

if self._logger is None:
raise AttributeError("logger is None. Set with connect method.")
return self._logger

def connect(self, nvme_config):

# Connects to server and sets stub and logger.
""" Connects to server and sets stub and logger."""

# Read in configuration parameters
host = nvme_config.get("config", "gateway_addr")
Expand Down Expand Up @@ -136,12 +134,12 @@ def connect(self, nvme_config):
@cli.cmd([
argument("-i", "--image", help="RBD image name", required=True),
argument("-p", "--pool", help="Ceph pool name", required=True),
argument("-b", "--bdev-name", help="Bdev name"),
argument("-b", "--bdev", help="Bdev name"),
argument("-u", "--user", help="User ID"),
argument("-s", "--block-size", help="Block size", default=4096),
])
def create_bdev(self, args):
# Creates a bdev from a Ceph RBD.
"""Creates a bdev from a Ceph RBD."""

try:
create_req = pb2.bdev_create_req(
Expand All @@ -159,8 +157,7 @@ def create_bdev(self, args):
argument("-s", "--serial", help="Serial number", required=True),
])
def create_subsystem(self, args):

# Creates a new subsystem.
"""Creates a new subsystem."""

try:
create_req = pb2.subsystem_create_req(subsystem_nqn=args.subnqn,
Expand All @@ -175,7 +172,7 @@ def create_subsystem(self, args):
argument("-b", "--bdev", help="Bdev name", required=True),
])
def create_namespace(self, args):
# Adds a namespace to a previously created subsystem.
"""Adds a namespace to a previously created subsystem."""

try:
create_req = pb2.subsystem_add_ns_req(subsystem_nqn=args.subnqn,
Expand All @@ -187,7 +184,7 @@ def create_namespace(self, args):

@cli.cmd([argument("-n", "--subnqn", help="Subsystem NQN", required=True)])
def allow_any_hosts(self, args):
# Allows any host to access a subsystem.
"""Allows any host to access a subsystem."""

try:
allow_req = pb2.subsystem_allow_any_host_req(
Expand All @@ -200,7 +197,7 @@ def allow_any_hosts(self, args):
@cli.cmd(
[argument("-t", "--trtype", help="Transport type", default="TCP")])
def create_transport(self, args):
# Sets a transport type.
"""Sets a transport type."""

try:
create_req = pb2.create_transport_req(trtype=args.trtype)
Expand All @@ -217,7 +214,7 @@ def create_transport(self, args):
argument("-f", "--adrfam", help="Address family", default="ipv4"),
])
def create_listener(self, args):
# Adds a listener at a particular TCP/IP address for a given subsystem.
"""Adds a listener at a particular TCP/IP address for a given subsystem."""

try:
create_req = pb2.subsystem_add_listener_req(
Expand Down
1 change: 0 additions & 1 deletion nvme_gw_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import subprocess
import grpc
from concurrent import futures
from distutils import util
import nvme_gw_pb2_grpc as pb2_grpc
import nvme_gw_pb2 as pb2
import nvme_gw_config
Expand Down

0 comments on commit 83c466a

Please sign in to comment.