日常场景中,总会出现需要修改配置文件的情况,为了实现修改配置文件可以动态生效,oslo_config 提供了reload的功能。
oslo_config 中cfg.py的源码
@__clear_cache
@__clear_drivers_cache
def reload_config_files(self):
"""Reload configure files and parse all options
:return: False if reload configure files failed or else return True
"""
try:
namespace = self._reload_config_files()
except SystemExit as exc:
LOG.warning("Caught SystemExit while reloading configure "
"files with exit code: %d", exc.code)
return False
except Error as err:
LOG.warning("Caught Error while reloading configure files: "
"%s", err)
return False
else:
self._namespace = namespace
return True
使用方法
可以直接调用reload_config_files()方法
from oslo_config import cfg
CONF = cfg.CONF
CONF.reload_config_files()