sma: load configuration from file
This patch adds support for loading configuration from a yaml-formatted file. The command-line options takes precedence over those from the config file. Signed-off-by: Konrad Sztyber <konrad.sztyber@intel.com> Change-Id: Iafb5b4aec0a64afe358fce2d6c55361fc4093223 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11712 Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Karol Latecki <karol.latecki@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Monica Kenguva <monica.kenguva@intel.com>
This commit is contained in:
parent
7791085984
commit
d2db395987
@ -11,6 +11,7 @@ pip install ijson
|
||||
pip install python-magic
|
||||
pip install grpcio
|
||||
pip install grpcio-tools
|
||||
pip install pyyaml
|
||||
# Additional dependencies for DPDK
|
||||
pacman -Sy --needed --noconfirm numactl nasm
|
||||
# Additional dependencies for ISA-L used in compression
|
||||
|
@ -17,6 +17,7 @@ pip3 install ijson
|
||||
pip3 install python-magic
|
||||
pip3 install grpcio
|
||||
pip3 install grpcio-tools
|
||||
pip3 install pyyaml
|
||||
# Additional dependencies for SPDK CLI - not available on older Ubuntus
|
||||
apt-get install -y python3-configshell-fb python3-pexpect || echo \
|
||||
"Note: Some SPDK CLI dependencies could not be installed."
|
||||
|
@ -105,6 +105,7 @@ pip3 install ijson
|
||||
pip3 install python-magic
|
||||
pip3 install grpcio
|
||||
pip3 install grpcio-tools
|
||||
pip3 install pyyaml
|
||||
|
||||
# Additional dependencies for SPDK CLI - not available in rhel and centos
|
||||
if ! echo "$ID $VERSION_ID" | grep -E -q 'rhel 7|centos 7'; then
|
||||
|
@ -5,6 +5,7 @@ import importlib
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import yaml
|
||||
|
||||
sys.path.append(os.path.dirname(__file__) + '/../python')
|
||||
|
||||
@ -12,15 +13,34 @@ import spdk.sma as sma # noqa
|
||||
from spdk.rpc.client import JSONRPCClient # noqa
|
||||
|
||||
|
||||
def parse_config(path):
|
||||
if path is None:
|
||||
return {}
|
||||
with open(path, 'r') as cfgfile:
|
||||
config = yaml.load(cfgfile, Loader=yaml.FullLoader)
|
||||
return {**config} if config is not None else {}
|
||||
|
||||
|
||||
def parse_argv():
|
||||
parser = ArgumentParser(description='Storage Management Agent command line interface')
|
||||
parser.add_argument('--address', '-a', default='localhost',
|
||||
help='IP address to listen on')
|
||||
parser.add_argument('--socket', '-s', default='/var/tmp/spdk.sock',
|
||||
help='SPDK RPC socket')
|
||||
parser.add_argument('--port', '-p', default=8080, type=int,
|
||||
help='IP port to listen on')
|
||||
return parser.parse_args()
|
||||
parser.add_argument('--address', '-a', help='IP address to listen on')
|
||||
parser.add_argument('--socket', '-s', help='SPDK RPC socket')
|
||||
parser.add_argument('--port', '-p', type=int, help='IP port to listen on')
|
||||
parser.add_argument('--config', '-c', help='Path to config file')
|
||||
defaults = {'address': 'localhost',
|
||||
'socket': '/var/tmp/spdk.sock',
|
||||
'port': 8080}
|
||||
# Merge the default values, config file, and the command-line
|
||||
args = vars(parser.parse_args())
|
||||
config = parse_config(args.get('config'))
|
||||
for argname, argvalue in defaults.items():
|
||||
if args.get(argname) is not None:
|
||||
if config.get(argname) is not None:
|
||||
logging.info(f'Overriding "{argname}" value from command-line')
|
||||
config[argname] = args[argname]
|
||||
if config.get(argname) is None:
|
||||
config[argname] = argvalue
|
||||
return config
|
||||
|
||||
|
||||
def get_build_client(sock):
|
||||
@ -44,10 +64,12 @@ def load_plugins(agent, client, plugins):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
argv = parse_argv()
|
||||
logging.basicConfig(level=os.environ.get('SMA_LOGLEVEL', 'WARNING').upper())
|
||||
agent = sma.StorageManagementAgent(argv.address, argv.port)
|
||||
register_device(agent, sma.NvmfTcpDeviceManager(get_build_client(argv.socket)))
|
||||
load_plugins(agent, get_build_client(argv.socket),
|
||||
|
||||
config = parse_argv()
|
||||
agent = sma.StorageManagementAgent(config['address'], config['port'])
|
||||
register_device(agent, sma.NvmfTcpDeviceManager(get_build_client(config['socket'])))
|
||||
load_plugins(agent, get_build_client(config['socket']), config.get('plugins') or [])
|
||||
load_plugins(agent, get_build_client(config['socket']),
|
||||
filter(None, os.environ.get('SMA_PLUGINS', '').split(':')))
|
||||
agent.run()
|
||||
|
Loading…
Reference in New Issue
Block a user