From 216b60c961a66bc3c132c804045b8744138a1019 Mon Sep 17 00:00:00 2001 From: Ilya Etingof Date: Tue, 9 Apr 2019 13:34:12 +0200 Subject: [PATCH] Respect VIRTUAL_BMC for non-default config path Adds the ability to override default configuration file location by exporting the ``VIRTUALBMC_CONFIG`` variable, pointing to the desired config file, into ``vbmcd`` and ``vbmc`` processes environment. Change-Id: I89f7cab09f4c0b2c1d2517c4b6f607ed291f235c --- doc/source/user/index.rst | 5 +++++ releasenotes/notes/add-config-env-8287bea486821653.yaml | 5 +++++ virtualbmc/config.py | 8 +++----- 3 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 releasenotes/notes/add-config-env-8287bea486821653.yaml diff --git a/doc/source/user/index.rst b/doc/source/user/index.rst index f30b1bf..7212f8c 100644 --- a/doc/source/user/index.rst +++ b/doc/source/user/index.rst @@ -10,6 +10,11 @@ does all the heavy-lifting (speaks IPMI, calls libvirt) while ``vbmc`` client is merely a command-line tool sending commands to the server and rendering responses to the user. +Both tools can optionally consume optional configuration file, which +defaults to ``$HOME/.vbmc/virtualbmc.conf``, +``/etc/virtualbmc/virtualbmc.conf``, but can be overridden with the +``VIRTUALBMC_CONFIG`` environment variable. + You should set up your systemd to launch the ``vbmcd`` server on system start up or you can just run ``vbmcd`` from command line if you do not need the tool running persistently on the system. Once the server is up and diff --git a/releasenotes/notes/add-config-env-8287bea486821653.yaml b/releasenotes/notes/add-config-env-8287bea486821653.yaml new file mode 100644 index 0000000..0124775 --- /dev/null +++ b/releasenotes/notes/add-config-env-8287bea486821653.yaml @@ -0,0 +1,5 @@ +features: + - | + Adds the ability to override default configuration file location by + exporting the ``$VIRTUALBMC_CONFIG`` variable, pointing to the desired + config file, into ``vbmcd`` and ``vbmc`` processes environment. diff --git a/virtualbmc/config.py b/virtualbmc/config.py index 5d7a418..855bd9f 100644 --- a/virtualbmc/config.py +++ b/virtualbmc/config.py @@ -19,15 +19,13 @@ from virtualbmc import utils __all__ = ['get_config'] _CONFIG_FILE_PATHS = ( + os.environ.get('VIRTUALBMC_CONFIG', ''), os.path.join(os.path.expanduser('~'), '.vbmc', 'virtualbmc.conf'), '/etc/virtualbmc/virtualbmc.conf') +CONFIG_FILE = next((x for x in _CONFIG_FILE_PATHS if os.path.exists(x)), '') + CONFIG = None -CONFIG_FILE = '' -for config in _CONFIG_FILE_PATHS: - if os.path.exists(config): - CONFIG_FILE = config - break class VirtualBMCConfig(object):