diff options
Diffstat (limited to 'onap-client/onap_client/client')
-rw-r--r-- | onap-client/onap_client/client/catalog.py | 4 | ||||
-rw-r--r-- | onap-client/onap_client/client/clients.py | 21 |
2 files changed, 17 insertions, 8 deletions
diff --git a/onap-client/onap_client/client/catalog.py b/onap-client/onap_client/client/catalog.py index 419d00f..a69c501 100644 --- a/onap-client/onap_client/client/catalog.py +++ b/onap-client/onap_client/client/catalog.py @@ -53,7 +53,7 @@ class Catalog(ABC): def __call__(self, **kwargs): return make_request(self.resource, **kwargs) - def __init__(self): + def __init__(self, **kwargs): """Iterates through all child classes and attaches them as attributes, named after the namespace property. @@ -64,7 +64,7 @@ class Catalog(ABC): self.catalog_items = {} for cls in self.__class__.__subclasses__(): - subclass = cls() + subclass = cls(**kwargs) namespace = subclass.namespace catalog_resources = subclass.catalog_resources diff --git a/onap-client/onap_client/client/clients.py b/onap-client/onap_client/client/clients.py index 8a8160f..86c069a 100644 --- a/onap-client/onap_client/client/clients.py +++ b/onap-client/onap_client/client/clients.py @@ -48,10 +48,10 @@ from onap_client import config CACHED_CLIENT = None -def get_client(config_file=None): +def get_client(config_file=None, **kwargs): clients = sys.modules[__name__] if not clients.CACHED_CLIENT or config_file: - clients.CACHED_CLIENT = Client(config_file) + clients.CACHED_CLIENT = Client(config_file, **kwargs) return clients.CACHED_CLIENT @@ -59,14 +59,15 @@ class Client(Catalog): """Base class for the ONAP client. Subclasses are dynamically loaded and added as attributes. Instantiate and use this class to interact with ONAP.""" - def __init__(self, config_file=None): + def __init__(self, config_file=None, **kwargs): self.config = config.APP_CONFIG self.modules = import_submodules(onap_client) + self._config_overrides = kwargs - super().__init__() + super().__init__(**kwargs) if config_file: - logging.info("Overriding ONAP Client configuration: {}".format(config_file)) + logging.debug("Overriding ONAP Client configuration: {}".format(config_file)) self.set_config(config_file) @property @@ -92,11 +93,19 @@ class Client(Catalog): self.config = config.load_config(config_file, "onap_client") for attr_name, attr in self.__dict__.items(): if isinstance(attr, Client): - logging.info("Reloading {} {}".format(attr_name, attr)) + logging.debug("Reloading {} {}".format(attr_name, attr)) attr.set_config(config_file) for k, v in attr.catalog_resources.items(): attr.load(k, v) + def override(override_key): + def decorator(func): + def override_check(self): + o = self._config_overrides.get(override_key) + return o if o else func(self) + return override_check + return decorator + def import_submodules(package, recursive=True): """Import all the modules in onap-client, except for those starting |