-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
366c382
commit 83c466a
Showing
3 changed files
with
53 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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", | ||
|
@@ -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__) | ||
|
@@ -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() | ||
|
||
|
@@ -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") | ||
|
@@ -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( | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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( | ||
|
@@ -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) | ||
|
@@ -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( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters