summaryrefslogtreecommitdiffstats
path: root/openstack
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-08-13 12:29:40 +0000
committerGerrit Code Review <review@openstack.org>2012-08-13 12:29:40 +0000
commit815c8f35b5fe75f013a99156118023d82598e003 (patch)
tree3595b709e100307692f0fe3b1805e3b54e0de300 /openstack
parent0a36c92e84be0f432b8ce792834dc297196e09af (diff)
parent513bd3a917207099125cc044705aee438fee7143 (diff)
downloadoslo-815c8f35b5fe75f013a99156118023d82598e003.tar.gz
oslo-815c8f35b5fe75f013a99156118023d82598e003.tar.xz
oslo-815c8f35b5fe75f013a99156118023d82598e003.zip
Merge "Allow set_default and set_override to use None"
Diffstat (limited to 'openstack')
-rw-r--r--openstack/common/cfg.py41
1 files changed, 39 insertions, 2 deletions
diff --git a/openstack/common/cfg.py b/openstack/common/cfg.py
index 09f3b88..5a10b2d 100644
--- a/openstack/common/cfg.py
+++ b/openstack/common/cfg.py
@@ -1178,6 +1178,9 @@ class ConfigOpts(collections.Mapping):
__import__(module_str)
self._get_opt_info(name, group)
+ class _NoneValue(object):
+ pass
+
@__clear_cache
def set_override(self, name, override, group=None):
"""Override an opt value.
@@ -1190,6 +1193,8 @@ class ConfigOpts(collections.Mapping):
:param group: an option OptGroup object or group name
:raises: NoSuchOptError, NoSuchGroupError
"""
+ if override is None:
+ override = self._NoneValue()
opt_info = self._get_opt_info(name, group)
opt_info['override'] = override
@@ -1205,9 +1210,38 @@ class ConfigOpts(collections.Mapping):
:param group: an option OptGroup object or group name
:raises: NoSuchOptError, NoSuchGroupError
"""
+ if default is None:
+ default = self._NoneValue()
opt_info = self._get_opt_info(name, group)
opt_info['default'] = default
+ @__clear_cache
+ def clear_override(self, name, group=None):
+ """Clear an override an opt value.
+
+ Clear a previously set override of the command line, config file
+ and default values of a given option.
+
+ :param name: the name/dest of the opt
+ :param group: an option OptGroup object or group name
+ :raises: NoSuchOptError, NoSuchGroupError
+ """
+ opt_info = self._get_opt_info(name, group)
+ opt_info['override'] = None
+
+ @__clear_cache
+ def clear_default(self, name, group=None):
+ """Clear an override an opt's default value.
+
+ Clear a previously set override of the default value of given option.
+
+ :param name: the name/dest of the opt
+ :param group: an option OptGroup object or group name
+ :raises: NoSuchOptError, NoSuchGroupError
+ """
+ opt_info = self._get_opt_info(name, group)
+ opt_info['default'] = None
+
def _all_opt_infos(self):
"""A generator function for iteration opt infos."""
for info in self._opts.values():
@@ -1350,8 +1384,11 @@ class ConfigOpts(collections.Mapping):
info = self._get_opt_info(name, group)
default, opt, override = [info[k] for k in sorted(info.keys())]
+ def _convert_none(value):
+ return None if isinstance(value, self._NoneValue) else value
+
if override is not None:
- return override
+ return _convert_none(override)
values = []
if self._cparser is not None:
@@ -1380,7 +1417,7 @@ class ConfigOpts(collections.Mapping):
return values
if default is not None:
- return default
+ return _convert_none(default)
return opt.default