Created
January 8, 2013 21:43
-
-
Save markmc/4488261 to your computer and use it in GitHub Desktop.
LazyPluggable and config groups
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
diff --git a/nova/utils.py b/nova/utils.py | |
index 30e2d80..c73af06 100644 | |
--- a/nova/utils.py | |
+++ b/nova/utils.py | |
@@ -507,14 +507,18 @@ def str_dict_replace(s, mapping): | |
class LazyPluggable(object): | |
"""A pluggable backend loaded lazily based on some value.""" | |
- def __init__(self, pivot, **backends): | |
+ def __init__(self, pivot, **backends, config_group=None): | |
self.__backends = backends | |
self.__pivot = pivot | |
self.__backend = None | |
+ self.__config_group = config_group | |
def __get_backend(self): | |
if not self.__backend: | |
- backend_name = CONF[self.__pivot] | |
+ if self.__config_group is None: | |
+ backend_name = CONF[self.__pivot] | |
+ else: | |
+ backend_name = CONF[self.__config_group][self.__pivot] | |
if backend_name not in self.__backends: | |
msg = _('Invalid backend: %s') % backend_name | |
raise exception.NovaException(msg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment