aboutsummaryrefslogtreecommitdiffstats
path: root/onap-client/onap_client/client
diff options
context:
space:
mode:
authorstark, steven <steven.stark@att.com>2020-08-03 13:03:24 -0700
committerstark, steven <steven.stark@att.com>2020-08-03 13:03:24 -0700
commit32409110b65b013bc65930f3cfdef09671cd3a5a (patch)
tree4bb6c95c057cdde0f08af78e7abc53e2be02fad4 /onap-client/onap_client/client
parent9df81b14e7203d6c3911f5f36881cb5170afdccc (diff)
[VVP] ONAP Client enhancements
Output hooks for resources. Outputs for each resource are returned as part of the complete onap-client spec when a resource is created. Hooks have been added for the SDC resources, to return the TOSCA model for each created resource. Dynamic config change. Ability to specify and reconfigure the onap-client configuration file at runtime without restarting the current session. Logging. Logging has been upgraded to create its own logging instance rather than the root logging instance, to avoid collisions. Issue-ID: VVP-455 Signed-off-by: stark, steven <steven.stark@att.com> Change-Id: I7b03411d221801fc51b80ee6a73d9491e823da56
Diffstat (limited to 'onap-client/onap_client/client')
-rw-r--r--onap-client/onap_client/client/clients.py34
-rw-r--r--onap-client/onap_client/client/request.py4
-rw-r--r--onap-client/onap_client/client/response.py3
3 files changed, 38 insertions, 3 deletions
diff --git a/onap-client/onap_client/client/clients.py b/onap-client/onap_client/client/clients.py
index 9b7a0c6..f0a0c1d 100644
--- a/onap-client/onap_client/client/clients.py
+++ b/onap-client/onap_client/client/clients.py
@@ -39,18 +39,36 @@ import importlib
import onap_client
import pkgutil
import inspect
+import sys
+import logging
from onap_client.client.catalog import Catalog
+from onap_client import config
+
+CACHED_CLIENT = None
+
+
+def get_client(config_file=None):
+ clients = sys.modules[__name__]
+ if not clients.CACHED_CLIENT or config_file:
+ clients.CACHED_CLIENT = Client(config_file)
+ return clients.CACHED_CLIENT
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):
+ def __init__(self, config_file=None):
+ self.config = config.APP_CONFIG
self.modules = import_submodules(onap_client)
+
super().__init__()
+ if config_file:
+ config.LOG.info("Overriding ONAP Client configuration: {}".format(config_file))
+ self.set_config(config_file)
+
@property
def namespace(self):
return "onap"
@@ -70,6 +88,20 @@ class Client(Catalog):
utility_functions[func[0]] = func[1]
return utility_functions
+ def set_config(self, config_file):
+ self.config = config.load_config(config_file, "onap_client")
+ self._set_logging(self.config.LOG_LEVEL)
+ for attr_name, attr in self.__dict__.items():
+ if isinstance(attr, Client):
+ config.LOG.info("Reloading {} {}".format(attr_name, attr))
+ attr.set_config(config_file)
+ for k, v in attr.catalog_resources.items():
+ attr.load(k, v)
+
+ def _set_logging(self, level):
+ LOG = logging.getLogger("ONAP_CLIENT")
+ LOG.setLevel(getattr(logging, level.upper()))
+
def import_submodules(package, recursive=True):
"""Import all the modules in onap-client, except for those starting
diff --git a/onap-client/onap_client/client/request.py b/onap-client/onap_client/client/request.py
index 0e1ce5c..194dad5 100644
--- a/onap-client/onap_client/client/request.py
+++ b/onap-client/onap_client/client/request.py
@@ -40,12 +40,14 @@ import requests
import json
import os
import copy
+import logging
from onap_client.client.response import ResponseHandler
-from onap_client.config import LOG as logger
from onap_client.exceptions import FilesRequestFailure
from jinja2 import exceptions as jinja_exceptions
+logger = logging.getLogger("ONAP_CLIENT")
+
class RequestHandler:
"""Handles a APICatalogRequestObject to make a request
diff --git a/onap-client/onap_client/client/response.py b/onap-client/onap_client/client/response.py
index ef0aab5..9693af5 100644
--- a/onap-client/onap_client/client/response.py
+++ b/onap-client/onap_client/client/response.py
@@ -36,8 +36,9 @@
# ============LICENSE_END============================================
import simplejson
+import logging
-from onap_client.config import LOG as logger
+logger = logging.getLogger("ONAP_CLIENT")
class ResponseHandler: