aboutsummaryrefslogtreecommitdiffstats
path: root/onap-client/onap_client/engine.py
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/engine.py
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/engine.py')
-rw-r--r--onap-client/onap_client/engine.py46
1 files changed, 34 insertions, 12 deletions
diff --git a/onap-client/onap_client/engine.py b/onap-client/onap_client/engine.py
index a352163..daac47d 100644
--- a/onap-client/onap_client/engine.py
+++ b/onap-client/onap_client/engine.py
@@ -37,11 +37,14 @@
import argparse
import json
+import logging
from onap_client.resource import Resource
-from onap_client.config import LOG as logger
from onap_client.client.clients import import_submodules
from onap_client.exceptions import InvalidSpecException, ResourceTypeNotFoundException
+from onap_client.client.clients import get_client
+
+logger = logging.getLogger("ONAP_CLIENT")
def dumper(obj):
@@ -70,7 +73,7 @@ def show_resource_spec(resource_name):
list_spec_resources()
-def load_spec(input_spec, validate_only=False, submit=True):
+def load_spec(input_spec, validate_only=False, submit=True, suppress_out=False, config=None):
try:
with open(input_spec, "r") as f:
jdata = json.loads(f.read())
@@ -79,7 +82,7 @@ def load_spec(input_spec, validate_only=False, submit=True):
raise
engine = SpecEngine()
- return engine.load_spec(jdata, validate_only=validate_only, distribute=submit)
+ return engine.load_spec(jdata, validate_only=validate_only, distribute=submit, suppress_out=suppress_out, config=config)
def spec_cli(args):
@@ -102,10 +105,18 @@ def spec_cli(args):
)
parser.add_argument(
+ "--oc-config", required=False, help="Path to configuration file for ONAP Client."
+ )
+
+ parser.add_argument(
"--no-submit", action="store_false", required=False, default=True, help="Dont execute submit() for each resource in spec."
)
parser.add_argument(
+ "--no-outputs", action="store_true", required=False, default=False, help="Don't return the full output from each created resource."
+ )
+
+ parser.add_argument(
"--list-spec-resources",
action="store_true",
required=False,
@@ -119,9 +130,9 @@ def spec_cli(args):
elif arguments.show_resource_spec:
show_resource_spec(arguments.show_resource_spec)
elif arguments.validate_spec:
- print(json.dumps(load_spec(arguments.validate_spec, validate_only=True), indent=4))
+ print(json.dumps(load_spec(arguments.validate_spec, validate_only=True, suppress_out=arguments.no_outputs), indent=4))
elif arguments.load_spec:
- load_spec(arguments.load_spec, submit=arguments.no_submit)
+ print(json.dumps(load_spec(arguments.load_spec, submit=arguments.no_submit, suppress_out=arguments.no_outputs, config=arguments.oc_config), indent=4))
class SpecEngine:
@@ -132,15 +143,23 @@ class SpecEngine:
def initialize(self):
import_submodules("onap_client")
- def load_spec(self, spec, distribute=True, validate_only=False):
+ def load_spec(self, spec, distribute=True, validate_only=False, suppress_out=False, config=None):
# print("loading spec {}".format(spec))
+
+ if config:
+ oc = get_client(config) # noqa: F841
+
self.spec = resolve_spec(spec)
self.validate(self.spec.get("spec", {}))
+ logger.info("Loading spec into spec engine:")
+ logger.info(json.dumps(self.spec, indent=4))
+
+ out = self.spec
if not validate_only:
- self._create(self.spec.get("spec", {}), distribute)
+ out = self._create(self.spec.get("spec", {}), distribute, suppress_out)
- return self.spec
+ return out
def validate(self, spec):
if not isinstance(spec, list):
@@ -174,7 +193,7 @@ class SpecEngine:
)
subclass.validate(resource_spec)
- def _create(self, spec, distribute):
+ def _create(self, spec, distribute, suppress_out):
full_engine_spec = []
for item_spec in spec:
resource_type = item_spec.get("type")
@@ -186,10 +205,13 @@ class SpecEngine:
)
full_spec = subclass.validate(resource_spec)
logger.debug(json.dumps(full_spec, indent=4))
- subclass.create_from_spec(full_spec, submit=distribute)
- full_engine_spec.append({"type": resource_type, "resource_spec": full_spec})
+ t = subclass.create_from_spec(full_spec, submit=distribute)
+ finished_spec = {"type": resource_type, "resource_spec": full_spec}
+ if not suppress_out:
+ finished_spec["output"] = t._output()
+ full_engine_spec.append(finished_spec)
- logger.info(json.dumps(full_engine_spec, indent=4))
+ return full_engine_spec
def resolve_spec(spec_dict):