diff options
Diffstat (limited to 'onap-client/onap_client')
69 files changed, 1615 insertions, 587 deletions
diff --git a/onap-client/onap_client/aai/catalog/business_catalog.py b/onap-client/onap_client/aai/catalog/business_catalog.py index 283521c..51c2409 100644 --- a/onap-client/onap_client/aai/catalog/business_catalog.py +++ b/onap-client/onap_client/aai/catalog/business_catalog.py @@ -37,12 +37,8 @@ import uuid from functools import partial -from onap_client import config from onap_client.aai.client import AAIClient -PAYLOADS_DIR = config.PAYLOADS_DIR -application_id = config.APPLICATION_ID - class BusinessClient(AAIClient): @property @@ -66,7 +62,7 @@ class BusinessClient(AAIClient): "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,), }, @@ -83,7 +79,7 @@ class BusinessClient(AAIClient): "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,), }, @@ -101,7 +97,7 @@ class BusinessClient(AAIClient): "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,), }, @@ -118,7 +114,7 @@ class BusinessClient(AAIClient): "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,), }, @@ -136,7 +132,7 @@ class BusinessClient(AAIClient): "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,), }, @@ -153,7 +149,7 @@ class BusinessClient(AAIClient): "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,), }, @@ -171,7 +167,7 @@ class BusinessClient(AAIClient): "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,), }, @@ -188,7 +184,7 @@ class BusinessClient(AAIClient): "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,), }, @@ -205,7 +201,7 @@ class BusinessClient(AAIClient): "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,), }, @@ -219,13 +215,13 @@ class BusinessClient(AAIClient): ), "uri-parameters": ["customer_name"], "payload-parameters": ["customer_name", "subscriber_name"], - "payload": "{}/aai_create_customer.jinja".format(PAYLOADS_DIR), + "payload": "{}/aai_create_customer.jinja".format(self.config.payload_directory), "success_code": 201, "headers": { "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,), }, @@ -243,7 +239,7 @@ class BusinessClient(AAIClient): "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,), }, @@ -261,7 +257,7 @@ class BusinessClient(AAIClient): "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,), }, diff --git a/onap-client/onap_client/aai/catalog/cloud_infrastructure_catalog.py b/onap-client/onap_client/aai/catalog/cloud_infrastructure_catalog.py index 4ebe34a..d22ab0e 100644 --- a/onap-client/onap_client/aai/catalog/cloud_infrastructure_catalog.py +++ b/onap-client/onap_client/aai/catalog/cloud_infrastructure_catalog.py @@ -34,16 +34,11 @@ # limitations under the License. # # ============LICENSE_END============================================ - import uuid from functools import partial -from onap_client import config from onap_client.aai.client import AAIClient -PAYLOADS_DIR = config.PAYLOADS_DIR -application_id = config.APPLICATION_ID - class CloudInfrastructureClient(AAIClient): @property @@ -66,7 +61,7 @@ class CloudInfrastructureClient(AAIClient): "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,), }, @@ -84,7 +79,7 @@ class CloudInfrastructureClient(AAIClient): "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,), }, @@ -102,7 +97,7 @@ class CloudInfrastructureClient(AAIClient): "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,), }, @@ -120,7 +115,25 @@ class CloudInfrastructureClient(AAIClient): "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, + }, + "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,), + }, + "GET_VOLUME_GROUPS": { + "verb": "GET", + "description": "Queries AAI for the list of volume groups", + "uri": partial( + "{endpoint}{service_path}/cloud-regions/cloud-region/{cloud_owner}/{cloud_region}/volume-groups".format, + endpoint=self.config.aai.AAI_BE_ENDPOINT, + service_path=self.config.aai.AAI_CLOUD_INFRASTRUCTURE_PATH, + ), + "uri-parameters": ["cloud_region", "cloud_owner"], + "success_code": 200, + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "X-TransactionId": str(uuid.uuid4()), + "X-FromAppId": self.config.application_id, }, "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,), }, diff --git a/onap-client/onap_client/aai/client.py b/onap-client/onap_client/aai/client.py index 5820fdd..c4ab03b 100644 --- a/onap-client/onap_client/aai/client.py +++ b/onap-client/onap_client/aai/client.py @@ -34,14 +34,10 @@ # limitations under the License. # # ============LICENSE_END============================================ - import uuid from functools import partial from onap_client.client.clients import Client -from onap_client import config - -application_id = config.APPLICATION_ID class AAIClient(Client): @@ -65,7 +61,7 @@ class AAIClient(Client): "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.aai.AAI_USERNAME, self.config.aai.AAI_PASSWORD,), }, diff --git a/onap-client/onap_client/cli.py b/onap-client/onap_client/cli.py index 1013403..c8d8657 100644 --- a/onap-client/onap_client/cli.py +++ b/onap-client/onap_client/cli.py @@ -48,9 +48,9 @@ from onap_client.util import utility_cli, get_actions def main(*args): cli_arguments = list(args) request_arguments = {} + configure_logging() oc = Client() - configure_logging() if len(args) > 0 and args[0] == "spec-engine": # use engine cli instead @@ -180,7 +180,7 @@ def help_table(data, utility_data={}): x.add_row(["", "", ""]) for item in data.get("clients"): - name = item + name = item.lower().replace("_", "-") description = "Various actions available for {}".format(name) parameters = ["--help"] x.add_row([name, description, "\n".join(parameters)]) diff --git a/onap-client/onap_client/client/catalog.py b/onap-client/onap_client/client/catalog.py index a69c501..03f10ff 100644 --- a/onap-client/onap_client/client/catalog.py +++ b/onap-client/onap_client/client/catalog.py @@ -34,9 +34,25 @@ # limitations under the License. # # ============LICENSE_END============================================ +import onap_client +import pkgutil +import inspect +import sys +import os +import importlib from abc import ABC, abstractmethod from onap_client.lib import make_request +from onap_client import config + +CACHED_MODULES = {} + + +def get_modules(): + catalog = sys.modules[__name__] + if not catalog.CACHED_MODULES: + catalog.CACHED_MODULES = import_submodules(onap_client) + return catalog.CACHED_MODULES class Catalog(ABC): @@ -53,7 +69,7 @@ class Catalog(ABC): def __call__(self, **kwargs): return make_request(self.resource, **kwargs) - def __init__(self, **kwargs): + def __init__(self, config_file=None, **kwargs): """Iterates through all child classes and attaches them as attributes, named after the namespace property. @@ -61,10 +77,15 @@ class Catalog(ABC): catalog_resources property, they will be added as attributes to the child attribute as a CallHandle object. """ + if not config_file: + config_file = os.environ.get("OC_CONFIG") or "/etc/onap_client/config.yaml" + self.catalog_items = {} + self.modules = get_modules() + self._config_overrides = kwargs for cls in self.__class__.__subclasses__(): - subclass = cls(**kwargs) + subclass = cls(config_file=config_file, **kwargs) namespace = subclass.namespace catalog_resources = subclass.catalog_resources @@ -73,6 +94,8 @@ class Catalog(ABC): setattr(self, namespace, subclass) + self.set_config(config_file) + def load(self, item_name, resource_data): """Consume a catalog resource entry as an APICatalogResource, and set it as an attribute on this.class as a CallHandle object""" @@ -91,6 +114,33 @@ class Catalog(ABC): def catalog_resources(self): raise NotImplementedError + @property + def utility_functions(self): + utility_functions = {} + for module_name, module in self.modules.items(): + all_functions = inspect.getmembers(module, inspect.isfunction) + for func in all_functions: + function = func[1] + if hasattr(function, "utility_function"): + utility_functions[func[0]] = func[1] + return utility_functions + + def set_config(self, config_file): + self.config = config.load_config(config_file, "onap_client") + for attr_name, attr in self.__dict__.items(): + if isinstance(attr, Catalog): + 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 + class APICatalogResource: """Class representation of a single catalog entry""" @@ -154,3 +204,19 @@ class APICatalogResource: @property def auth(self): return self.catalog_resource_data.get("auth", None) + + +def import_submodules(package, recursive=True): + """Import all the modules in onap-client, except for those starting + with tests*. This is needed so that the Client object can register child classes""" + if isinstance(package, str): + package = importlib.import_module(package) + results = {} + for loader, name, is_pkg in pkgutil.walk_packages(package.__path__): + full_name = package.__name__ + "." + name + if full_name.find("tests") == -1: + results[full_name] = importlib.import_module(full_name) + if recursive and is_pkg: + results.update(import_submodules(full_name)) + + return results diff --git a/onap-client/onap_client/client/clients.py b/onap-client/onap_client/client/clients.py index 86c069a..a8202e4 100644 --- a/onap-client/onap_client/client/clients.py +++ b/onap-client/onap_client/client/clients.py @@ -34,16 +34,9 @@ # limitations under the License. # # ============LICENSE_END============================================ - -import importlib -import logging -import onap_client -import pkgutil -import inspect import sys from onap_client.client.catalog import Catalog -from onap_client import config CACHED_CLIENT = None @@ -59,17 +52,6 @@ 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, **kwargs): - self.config = config.APP_CONFIG - self.modules = import_submodules(onap_client) - self._config_overrides = kwargs - - super().__init__(**kwargs) - - if config_file: - logging.debug("Overriding ONAP Client configuration: {}".format(config_file)) - self.set_config(config_file) - @property def namespace(self): return "onap" @@ -77,47 +59,3 @@ class Client(Catalog): @property def catalog_resources(self): return {} - - @property - def utility_functions(self): - utility_functions = {} - for module_name, module in self.modules.items(): - all_functions = inspect.getmembers(module, inspect.isfunction) - for func in all_functions: - function = func[1] - if hasattr(function, "utility_function"): - utility_functions[func[0]] = func[1] - return utility_functions - - def set_config(self, config_file): - self.config = config.load_config(config_file, "onap_client") - for attr_name, attr in self.__dict__.items(): - if isinstance(attr, Client): - 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 - with tests*. This is needed so that the Client object can register child classes""" - if isinstance(package, str): - package = importlib.import_module(package) - results = {} - for loader, name, is_pkg in pkgutil.walk_packages(package.__path__): - full_name = package.__name__ + "." + name - if full_name.find("tests") == -1: - results[full_name] = importlib.import_module(full_name) - if recursive and is_pkg: - results.update(import_submodules(full_name)) - - return results diff --git a/onap-client/onap_client/config.py b/onap-client/onap_client/config.py index 6fe43e9..3b85bf8 100644 --- a/onap-client/onap_client/config.py +++ b/onap-client/onap_client/config.py @@ -34,11 +34,12 @@ # limitations under the License. # # ============LICENSE_END============================================ - -import distutils.sysconfig import logging import os import yaml +from importlib_resources import files + +from onap_client import etc class Config: @@ -75,24 +76,24 @@ class Config: ) if not config_data: - with open("{}/config.example.yaml".format(PATH), "r") as f: + with open(os.path.join(files(etc), "config.example.yaml"), "r") as f: config_data = yaml.safe_load(f) self.config = config_data for key in keys: self.config = self.config.get(key, {}) + @property + def payload_directory(self): + return os.path.join(files(etc), "payloads") + + @property + def application_id(self): + return "robot-ete" + def load_config(config_file, *config_args): config = Config(config_file) config.load(*config_args) return config - - -PATH = "{}/onap_client".format(distutils.sysconfig.PREFIX) -PAYLOADS_DIR = "{}/payloads".format(PATH) -APPLICATION_ID = "robot-ete" -CONFIG_ENV = os.environ.get("OC_CONFIG") -CONFIG_FILE = CONFIG_ENV or "/etc/onap_client/config.yaml" -APP_CONFIG = load_config(CONFIG_FILE, "onap_client") diff --git a/onap-client/onap_client/engine.py b/onap-client/onap_client/engine.py index 8f42507..f04d36d 100644 --- a/onap-client/onap_client/engine.py +++ b/onap-client/onap_client/engine.py @@ -70,7 +70,7 @@ def show_resource_spec(resource_name): list_spec_resources() -def load_spec(input_spec, validate_only=False, submit=True, suppress_out=False, config=None): +def load_spec(input_spec, validate_only=False, submit=True, suppress_out=False, config=None, delete=False): try: with open(input_spec, "r") as f: jdata = json.loads(f.read()) @@ -79,7 +79,7 @@ def load_spec(input_spec, validate_only=False, submit=True, suppress_out=False, raise engine = SpecEngine(config_file=config) - return engine.load_spec(jdata, validate_only=validate_only, distribute=submit, suppress_out=suppress_out) + return engine.load_spec(jdata, validate_only=validate_only, distribute=submit, suppress_out=suppress_out, delete=delete) def spec_cli(args): @@ -92,6 +92,12 @@ def spec_cli(args): ) parser.add_argument( + "--delete-spec", + required=False, + help="Delete the resources from a local spec file.", + ) + + parser.add_argument( "--validate-spec", required=False, help="Validates a local spec file for the spec engine.", @@ -127,9 +133,41 @@ 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, suppress_out=arguments.no_outputs), indent=4)) + print( + json.dumps( + load_spec( + arguments.validate_spec, + validate_only=True, + suppress_out=arguments.no_outputs + ), + indent=4 + ) + ) elif arguments.load_spec: - print(json.dumps(load_spec(arguments.load_spec, submit=arguments.no_submit, suppress_out=arguments.no_outputs, config=arguments.oc_config), indent=4)) + print( + json.dumps( + load_spec( + arguments.load_spec, + submit=arguments.no_submit, + suppress_out=arguments.no_outputs, + config=arguments.oc_config + ), + indent=4 + ) + ) + elif arguments.delete_spec: + print( + json.dumps( + load_spec( + arguments.delete_spec, + submit=arguments.no_submit, + suppress_out=arguments.no_outputs, + config=arguments.oc_config, + delete=True + ), + indent=4 + ) + ) class SpecEngine: @@ -137,7 +175,7 @@ class SpecEngine: self.spec = {} self.oc = get_client(config_file=config_file, **oc_kwargs) - def load_spec(self, spec, distribute=True, validate_only=False, suppress_out=False): + def load_spec(self, spec, distribute=True, validate_only=False, suppress_out=False, delete=False): self.spec = resolve_spec(spec) self.validate(self.spec.get("spec", {})) @@ -146,7 +184,9 @@ class SpecEngine: out = self.spec if not validate_only: - out = self._create(self.spec.get("spec", {}), distribute, suppress_out) + resources = self.spec.get("spec", []) + resources = list(reversed(resources)) if delete else resources + out = self._load(resources, distribute, suppress_out, delete) return out @@ -182,22 +222,32 @@ class SpecEngine: ) subclass.validate(resource_spec) - def _create(self, spec, distribute, suppress_out): + def _load(self, resources, distribute, suppress_out, delete): full_engine_spec = [] - for item_spec in spec: + for item_spec in resources: resource_type = item_spec.get("type") resource_spec = item_spec.get("resource_spec") subclass = get_resource_subclass(resource_type) + if not subclass: raise ResourceTypeNotFoundException( "Resource type {} was not found".format(resource_type) ) + full_spec = subclass.validate(resource_spec) + logger.debug(json.dumps(full_spec, indent=4)) - t = subclass.create_from_spec(full_spec, submit=distribute) + + if delete: + t = subclass.delete_from_spec(full_spec, oc=self.oc) + else: + t = subclass.create_from_spec(full_spec, submit=distribute, oc=self.oc) + finished_spec = {"type": resource_type, "resource_spec": full_spec} - if not suppress_out: + + if not suppress_out and not delete: finished_spec["output"] = t._output() + full_engine_spec.append(finished_spec) return {"spec": full_engine_spec} diff --git a/onap-client/onap_client/etc/__init__.py b/onap-client/onap_client/etc/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/onap-client/onap_client/etc/__init__.py diff --git a/onap-client/onap_client/etc/config.example.yaml b/onap-client/onap_client/etc/config.example.yaml new file mode 100644 index 0000000..b3a6575 --- /dev/null +++ b/onap-client/onap_client/etc/config.example.yaml @@ -0,0 +1,101 @@ +# -*- coding: utf8 -*- +# ============LICENSE_START======================================================= +# org.onap.vvp/validation-scripts +# =================================================================== +# Copyright © 2020 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the "License"); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ +onap_client: + sdc: + SDC_BE_ENDPOINT: https://sdc.api.be.simpledemo.onap.org:30204 + SDC_FE_ENDPOINT: https://sdc.api.be.simpledemo.onap.org:30207 + SDC_HC_ENDPOINT: https://sdc.api.be.simpledemo.onap.org:30207 + SDC_BE_ONBOARD_ENDPOINT: https://sdc.api.be.simpledemo.onap.org:31360 + SDC_CONSUMER_USERNAME: vid + SDC_CONSUMER_PASSWORD: Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U + SDC_DESIGNER_USER_ID: cs0008 + SDC_TESTER_USER_ID: jm0007 + SDC_OPS_USER_ID: op0001 + SDC_GOVERNOR_USER_ID: gv0001 + SDC_DESIGNER_PASSWORD: demo123456! + GLOBAL_SDC_USERNAME: beep + GLOBAL_SDC_PASSWORD: boop + SDC_CONSUMER_CATALOG_PATH: /sdc/v1/catalog + SDC_SCREEN_PATH: /sdc2/rest/v1/screen + SDC_HEALTH_CHECK_PATH: /sdc1/rest/healthCheck + SDC_CATALOG_SERVICES_PATH: /sdc2/rest/v1/catalog/services + SDC_RESOURCE_CATEGORIES_PATH: /sdc2/rest/v1/categories/resources + SDC_VENDOR_SOFTWARE_PRODUCT_PATH: /onboarding-api/v1.0/vendor-software-products + SDC_CATALOG_RESOURCES_PATH: /sdc2/rest/v1/catalog/resources + SDC_VENDOR_LICENSE_MODEL_PATH: /onboarding-api/v1.0/vendor-license-models + SDC_VENDOR_ITEMS_PATH: /onboarding-api/v1.0/items + SDC_FE_CATALOG_RESOURCES_PATH: /sdc1/feProxy/rest/v1/catalog/resources + ABSTRACT_NODE_PREFIX: abstract_ + POLICIES: + SCALING_FIXED: org.openecomp.policies.scaling.Fixed + EXTERNAL: org.openecomp.policies.External + PLACEMENT: tosca.policies.Placement + GROUPS: + NETWORK_COLLECTION: org.openecomp.groups.NetworkCollection + PLACEMENT_GROUP: tosca.groups.nfv.PlacementGroup + VFC_INSTANCE: org.openecomp.groups.VfcInstanceGroup + SERVICE_DISTRIBUTION: + - "request_service_certification" + - "start_service_certification" + - "finish_service_certification" + - "approve_service_certification" + POLL_INTERVAL: 30 + aai: + AAI_BE_ENDPOINT: https://aai.api.simpledemo.onap.org:30233 + AAI_BUSINESS_PATH: /aai/v16/business + AAI_CLOUD_INFRASTRUCTURE_PATH: /aai/v16/cloud-infrastructure + AAI_HEALTH_CHECK_PATH: /aai/util/echo + AAI_USERNAME: AAI + AAI_PASSWORD: AAI + sdnc: + SDNC_ENDPOINT: http://sdnc.api.simpledemo.onap.org:30267 + SDNC_OPERATIONS_PATH: /restconf/operations + SDNC_CONFIG_PATH: /restconf/config + SDNC_USERNAME: admin + SDNC_PASSWORD: Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U + vid: + VID_ENDPOINT: http://vid.api.simpledemo.onap.org:30238 + VID_MAINTENANCE_PATH: /vid/maintenance + VID_HEALTH_CHECK_PATH: /vid/healthCheck + so: + SO_ENDPOINT: http://sdc.so.be.simpledemo.onap.org:30277 + SO_HEALTH_CHECK_PATH: /globalhealthcheck + SO_USERNAME: bpel + SO_PASSWORD: password1$ + SO_SERVICE_INSTANCE_PATH: /onap/so/infra/serviceInstantiation/v7/serviceInstances + SO_ORCHESTRATION_PATH: /onap/so/infra/orchestrationRequests/v7/ + LOG_LEVEL: DEBUG diff --git a/onap-client/onap_client/etc/payloads/__init__.py b/onap-client/onap_client/etc/payloads/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/onap-client/onap_client/etc/payloads/__init__.py diff --git a/onap-client/onap_client/etc/payloads/aai_create_customer.jinja b/onap-client/onap_client/etc/payloads/aai_create_customer.jinja new file mode 100644 index 0000000..cbf2b96 --- /dev/null +++ b/onap-client/onap_client/etc/payloads/aai_create_customer.jinja @@ -0,0 +1,5 @@ +{ + "global-customer-id": "{{customer_name}}", + "subscriber-name": "{{subscriber_name}}", + "subscriber-type": "INFRA" +} diff --git a/onap-client/onap_client/etc/payloads/action.jinja b/onap-client/onap_client/etc/payloads/action.jinja new file mode 100644 index 0000000..3ef9f60 --- /dev/null +++ b/onap-client/onap_client/etc/payloads/action.jinja @@ -0,0 +1,3 @@ +{ + "action": "{{action}}" +}
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/add_resource_relationship.jinja b/onap-client/onap_client/etc/payloads/add_resource_relationship.jinja new file mode 100644 index 0000000..38c8bf5 --- /dev/null +++ b/onap-client/onap_client/etc/payloads/add_resource_relationship.jinja @@ -0,0 +1,17 @@ +{ + "fromNode": "{{from_node_resource_id}}", + "toNode": "{{to_node_resource_id}}", + "relationships": [{ + "relation": { + "relationship": { + "type": "{{relationship_type}}" + }, + "capability": "{{capability_name}}", + "capabilityOwnerId": "{{capability_owner_id}}", + "capabilityUid": "{{capability_id}}", + "requirement": "{{requirement_name}}", + "requirementOwnerId": "{{from_node_resource_id}}", + "requirementUid": "{{requirement_id}}" + } + }] +}
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/add_vsp_contributer.jinja b/onap-client/onap_client/etc/payloads/add_vsp_contributer.jinja new file mode 100644 index 0000000..ac75634 --- /dev/null +++ b/onap-client/onap_client/etc/payloads/add_vsp_contributer.jinja @@ -0,0 +1 @@ +{"removedUsersIds":[],"addedUsersIds":["{{user_id}}"]}
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/catalog_resource.jinja b/onap-client/onap_client/etc/payloads/catalog_resource.jinja new file mode 100644 index 0000000..7489912 --- /dev/null +++ b/onap-client/onap_client/etc/payloads/catalog_resource.jinja @@ -0,0 +1,27 @@ +{ + "artifacts": {}, + "toscaArtifacts": {}, + "contactId": "{{contact_id}}", + "categories": {{categories|tojson(indent=4)}}, + "description": "{{vnf_description}}", + "icon": "defaulticon", + "componentInstancesProperties": {}, + "componentInstancesAttributes": {}, + "name": "{{vnf_name}}", + "tags": [ + "{{vnf_name}}" + ], + "capabilities": {}, + "requirements": {}, + "deploymentArtifacts": {}, + "componentType": "RESOURCE", + "vendorName": "{{vendor_name}}", + "vendorRelease": "1.0", + "componentInstances": [], + "properties": [], + "attributes": [], + "groups": [], + "resourceType": "{{resource_type}}", + "csarUUID": "{{software_product_id}}", + "csarVersion": "1.0" +}
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/catalog_service.jinja b/onap-client/onap_client/etc/payloads/catalog_service.jinja new file mode 100644 index 0000000..a692888 --- /dev/null +++ b/onap-client/onap_client/etc/payloads/catalog_service.jinja @@ -0,0 +1,47 @@ +{ + "artifacts": {}, + "toscaArtifacts": {}, + "contactId": "{{contact_id}}", + "categories": [ + { + "name": "{{category_name}}", + "normalizedName": "{{category_name_lower}}", + "uniqueId": "{{category_id}}", + "icons": [ + "{{category_name_icon}}" + ], + "subcategories": null, + "version": null, + "ownerId": null, + "empty": false, + "type": null + } + ], + "description": "{{description}}", + "icon": "defaulticon", + "componentInstancesProperties": {}, + "componentInstancesAttributes": {}, + "name": "{{service_name}}", + "tags": [ + "{{tag}}", + "{{service_name}}" + ], + "capabilities": {}, + "requirements": {}, + "deploymentArtifacts": {}, + "componentType": "SERVICE", + {% if project_code != '' %} + "projectCode": "{{project_code}}", + {% endif %} + "componentInstances": [], + "properties": [], + "attributes": [], + "forwardingPaths": {}, + "ecompGeneratedNaming": {{ecomp_generated_naming}}, + "serviceApiArtifacts": {}, + "instantiationType": "{{instantiation_type}}", + "environmentContext": "{{environment_context}}", + "serviceType": "{{service_type}}", + "serviceRole": "{{service_role}}", + "namingPolicy": "{{naming_policy}}" +} diff --git a/onap-client/onap_client/etc/payloads/catalog_service_property.jinja b/onap-client/onap_client/etc/payloads/catalog_service_property.jinja new file mode 100644 index 0000000..584002a --- /dev/null +++ b/onap-client/onap_client/etc/payloads/catalog_service_property.jinja @@ -0,0 +1,40 @@ +[ +{ + "uniqueId": "{{unique_id}}", + "type": "{{property_type}}", + "required": false, + "definition": false, + "defaultValue": null, + "description": null, + "schema": null, + "password": false, + "name": "{{input_name}}", + "value": "{{input_value}}", + "label": null, + "hidden": false, + "immutable": false, + "inputPath": null, + "status": null, + "inputId": null, + "instanceUniqueId": null, + "propertyId": null, + "parentPropertyType": null, + "subPropertyInputPath": null, + "annotations": null, + "parentUniqueId": "{{parent_unique_id}}", + "getInputValues": null, + "isDeclaredListInput": false, + "getPolicyValues": null, + "constraints": null, + "inputs": null, + "properties": null, + {% if schema_type != "" %} + "schemaType": "{{schema_type}}", + {% endif %} + "schemaProperty": null, + "getInputProperty": false, + "version": null, + "ownerId": "{{owner_id}}", + "empty": false +} +]
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/catalog_vnf_group.jinja b/onap-client/onap_client/etc/payloads/catalog_vnf_group.jinja new file mode 100644 index 0000000..99d8dcb --- /dev/null +++ b/onap-client/onap_client/etc/payloads/catalog_vnf_group.jinja @@ -0,0 +1,3 @@ +[ + "{{instance_id}}" +] diff --git a/onap-client/onap_client/etc/payloads/catalog_vnf_group_property.jinja b/onap-client/onap_client/etc/payloads/catalog_vnf_group_property.jinja new file mode 100644 index 0000000..0211add --- /dev/null +++ b/onap-client/onap_client/etc/payloads/catalog_vnf_group_property.jinja @@ -0,0 +1,26 @@ +[ + { + "constraints": null, + "defaultValue": null, + "description": "{{description}}", + "name": "{{property_name}}", + "parentUniqueId": "{{parent_unique_id}}", + "password": false, + "required": true, + "schema": { + "property": {} + }, + "schemaType": null, + "type": "{{property_type}}", + "uniqueId": "{{unique_id}}", + "value": "{{property_default_value}}", + "definition": false, + "getInputValues": null, + "parentPropertyType": null, + "subPropertyInputPath": null, + "getPolicyValues": null, + "inputPath": null, + "valueUniqueUid": null, + "ownerId": "{{owner_id}}" + } +]
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/catalog_vnf_input.jinja b/onap-client/onap_client/etc/payloads/catalog_vnf_input.jinja new file mode 100644 index 0000000..1bb129a --- /dev/null +++ b/onap-client/onap_client/etc/payloads/catalog_vnf_input.jinja @@ -0,0 +1,24 @@ +[ + { + "defaultValue": "{{input_default_value}}", + "description": null, + "name": "{{input_name}}", + "parentUniqueId": "{{input_parent_unique_id}}", + "password": false, + "required": false, + "schema": { + "property": {} + }, + "type": "string", + "uniqueId": "{{input_unique_id}}", + "value": null, + "definition": false, + "getInputValues": null, + "instanceUniqueId": null, + "propertyId": null, + "properties": null, + "inputs": null, + "ownerId": "{{input_owner_id}}", + "inputPath": null + } +]
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/catalog_vnf_policy.jinja b/onap-client/onap_client/etc/payloads/catalog_vnf_policy.jinja new file mode 100644 index 0000000..f89fcdd --- /dev/null +++ b/onap-client/onap_client/etc/payloads/catalog_vnf_policy.jinja @@ -0,0 +1,13 @@ +[ + { + "type": "component_Instances", + "uniqueIds": [ + {% for id in instance_ids %} + "{{id}}" + {% if loop.index < loop.length %} + , + {% endif %} + {% endfor %} + ] + } +] diff --git a/onap-client/onap_client/etc/payloads/catalog_vnf_policy_property.jinja b/onap-client/onap_client/etc/payloads/catalog_vnf_policy_property.jinja new file mode 100644 index 0000000..57ba2b1 --- /dev/null +++ b/onap-client/onap_client/etc/payloads/catalog_vnf_policy_property.jinja @@ -0,0 +1,24 @@ +[ + { + "defaultValue": null, + "description": "{{description}}", + "name": "{{property_name}}", + "parentUniqueId": null, + "password": false, + "required": true, + "schema": { + "property": {} + }, + "schemaType": null, + "type": "{{property_type}}", + "uniqueId": "{{unique_id}}", + "value": "{{property_default_value}}", + "definition": true, + "getInputValues": null, + "parentPropertyType": null, + "subPropertyInputPath": null, + "getPolicyValues": null, + "inputPath": null, + "ownerId": null + } +]
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/catalog_vnf_property.jinja b/onap-client/onap_client/etc/payloads/catalog_vnf_property.jinja new file mode 100644 index 0000000..cebc0a8 --- /dev/null +++ b/onap-client/onap_client/etc/payloads/catalog_vnf_property.jinja @@ -0,0 +1,20 @@ +[ + { + "constraints": [], + "name": "{{property_name}}", + "parentUniqueId": "{{parent_unique_id}}", + "password": false, + "required": false, + "schema": {"property": {}}, + {% if schema_type != "" %} + "schemaType": "{{schema_type}}", + {% endif %} + "type": "{{property_type}}", + "uniqueId": "{{unique_id}}", + "value": "{{property_default_value}}", + "definition": false, + "toscaPresentation": { + "ownerId": "{{owner_id}}" + } + } +]
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/entitlement_pool.jinja b/onap-client/onap_client/etc/payloads/entitlement_pool.jinja new file mode 100644 index 0000000..4ca68dd --- /dev/null +++ b/onap-client/onap_client/etc/payloads/entitlement_pool.jinja @@ -0,0 +1,13 @@ +{ + "name": "{{entitlement_pool_name}}", + "description": "vendor entitlement pool", + "thresholdValue": "100", + "thresholdUnits": "Percentage", + "time": { + "choice": "", + "other": "" + }, + "startDate": "{{license_start_date}}", + "expiryDate": "{{license_end_date}}", + "manufacturerReferenceNumber": "111111" +}
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/feature_group.jinja b/onap-client/onap_client/etc/payloads/feature_group.jinja new file mode 100644 index 0000000..cc3fec1 --- /dev/null +++ b/onap-client/onap_client/etc/payloads/feature_group.jinja @@ -0,0 +1,11 @@ +{ + "name": "{{feature_group_name}}", + "description": "vendor feature group", + "partNumber": "123abc456", + "addedLicenseKeyGroupsIds": [ + "{{key_group_id}}" + ], + "addedEntitlementPoolsIds": [ + "{{entitlement_pool_id}}" + ] +}
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/generic_payload.jinja b/onap-client/onap_client/etc/payloads/generic_payload.jinja new file mode 100644 index 0000000..4c6075f --- /dev/null +++ b/onap-client/onap_client/etc/payloads/generic_payload.jinja @@ -0,0 +1 @@ +{{payload_data}}
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/key_group.jinja b/onap-client/onap_client/etc/payloads/key_group.jinja new file mode 100644 index 0000000..e58639b --- /dev/null +++ b/onap-client/onap_client/etc/payloads/key_group.jinja @@ -0,0 +1,10 @@ +{ + "name": "{{key_group_name}}", + "description": "vendor license key group", + "type": "Universal", + "thresholdValue": "100", + "thresholdUnits": "Percentage", + "startDate": "{{license_start_date}}", + "expiryDate": "{{license_end_date}}", + "manufacturerReferenceNumber": "11111" +}
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/license_agreement.jinja b/onap-client/onap_client/etc/payloads/license_agreement.jinja new file mode 100644 index 0000000..66776f4 --- /dev/null +++ b/onap-client/onap_client/etc/payloads/license_agreement.jinja @@ -0,0 +1,12 @@ +{ + "name": "{{license_agreement_name}}", + "description": "vendor license agreement", + "requirementsAndConstrains": "abcdef", + "licenseTerm": { + "choice": "Fixed_Term", + "other": "" + }, + "addedFeatureGroupsIds": [ + "{{feature_group_id}}" + ] +}
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/license_model.jinja b/onap-client/onap_client/etc/payloads/license_model.jinja new file mode 100644 index 0000000..27fe266 --- /dev/null +++ b/onap-client/onap_client/etc/payloads/license_model.jinja @@ -0,0 +1,5 @@ +{ + "vendorName": "{{vendor_name}}", + "description": "vendor license model", + "iconRef": "icon" +}
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/resource_instance.jinja b/onap-client/onap_client/etc/payloads/resource_instance.jinja new file mode 100644 index 0000000..c2c279c --- /dev/null +++ b/onap-client/onap_client/etc/payloads/resource_instance.jinja @@ -0,0 +1,10 @@ +{ + "uniqueId": "{{catalog_resource_id}}{{milli_timestamp}}", + "posX": {{posX}}, + "posY": {{posY}}, + "name": "{{catalog_resource_name}}", + "componentVersion": "1.0", + "originType": "{{originType}}", + "icon": "defaulticon", + "componentUid": "{{catalog_resource_id}}" +}
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/resource_instance_vnf.jinja b/onap-client/onap_client/etc/payloads/resource_instance_vnf.jinja new file mode 100644 index 0000000..78bcf70 --- /dev/null +++ b/onap-client/onap_client/etc/payloads/resource_instance_vnf.jinja @@ -0,0 +1,10 @@ +{ + "uniqueId": "{{new_catalog_resource_id}}{{milli_timestamp}}", + "posX": {{posX}}, + "posY": {{posY}}, + "name": "{{new_catalog_resource_name}}", + "componentVersion": "1.0", + "originType": "{{originType}}", + "icon": "defaulticon", + "componentUid": "{{new_catalog_resource_id}}" +}
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/so_create_module.jinja b/onap-client/onap_client/etc/payloads/so_create_module.jinja new file mode 100644 index 0000000..263a3a9 --- /dev/null +++ b/onap-client/onap_client/etc/payloads/so_create_module.jinja @@ -0,0 +1,55 @@ +{ + "requestDetails": { + "requestInfo": { + "instanceName": "{{module_instance_name}}", + "source": "VID", + "suppressRollback": false, + "requestorId": "test" + }, + "modelInfo": { + "modelType": "vfModule", + "modelInvariantId": "{{model_invariant_id}}", + "modelVersionId": "{{model_version_id}}", + "modelName": "{{model_name}}", + "modelVersion": "{{model_version}}", + "modelCustomizationId": "{{model_customization_id}}", + "modelCustomizationName": "{{model_name}} 0" + }, + "requestParameters": { + "userParams": [], + "testApi": "{{api_type}}", + "usePreload": true + }, + "cloudConfiguration": { + "tenantId": "{{tenant_id}}", + "cloudOwner": "{{cloud_owner}}", + "lcpCloudRegionId": "{{cloud_region}}" + }, + "relatedInstanceList": [{ + "relatedInstance": { + "instanceId": "{{service_instance_id}}", + "modelInfo": { + "modelType": "service", + "modelName": "{{service_model_name}}", + "modelInvariantId": "{{service_model_invariant_id}}", + "modelVersion": "{{service_model_version}}", + "modelVersionId": "{{service_model_version_id}}" + } + } + }, + { + "relatedInstance": { + "instanceId": "{{vnf_instance_id}}", + "modelInfo": { + "modelType": "vnf", + "modelName": "{{vnf_model_name}}", + "modelInvariantId": "{{vnf_model_invariant_id}}", + "modelVersion": "{{vnf_model_version}}", + "modelVersionId": "{{vnf_model_version_id}}", + "modelCustomizationId": "{{vnf_model_customization_id}}", + "modelCustomizationName": "{{vnf_model_name}} 0" + } + } + }] + } +}
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/so_create_volume_module.jinja b/onap-client/onap_client/etc/payloads/so_create_volume_module.jinja new file mode 100644 index 0000000..b08663d --- /dev/null +++ b/onap-client/onap_client/etc/payloads/so_create_volume_module.jinja @@ -0,0 +1,55 @@ +{ + "requestDetails": { + "requestInfo": { + "instanceName": "{{volume_module_instance_name}}", + "source": "VID", + "suppressRollback": false, + "requestorId": "test" + }, + "modelInfo": { + "modelType": "volumeGroup", + "modelInvariantId": "{{model_invariant_id}}", + "modelVersionId": "{{model_version_id}}", + "modelName": "{{model_name}}", + "modelVersion": "{{model_version}}", + "modelCustomizationId": "{{model_customization_id}}", + "modelCustomizationName": "{{model_name}} 0" + }, + "requestParameters": { + "userParams": [], + "testApi": "{{api_type}}", + "usePreload": true + }, + "cloudConfiguration": { + "tenantId": "{{tenant_id}}", + "cloudOwner": "{{cloud_owner}}", + "lcpCloudRegionId": "{{cloud_region}}" + }, + "relatedInstanceList": [{ + "relatedInstance": { + "instanceId": "{{service_instance_id}}", + "modelInfo": { + "modelType": "service", + "modelName": "{{service_model_name}}", + "modelInvariantId": "{{service_model_invariant_id}}", + "modelVersion": "{{service_model_version}}", + "modelVersionId": "{{service_model_version_id}}" + } + } + }, + { + "relatedInstance": { + "instanceId": "{{vnf_instance_id}}", + "modelInfo": { + "modelType": "vnf", + "modelName": "{{vnf_model_name}}", + "modelInvariantId": "{{vnf_model_invariant_id}}", + "modelVersion": "{{vnf_model_version}}", + "modelVersionId": "{{vnf_model_version_id}}", + "modelCustomizationId": "{{vnf_model_customization_id}}", + "modelCustomizationName": "{{vnf_model_name}} 0" + } + } + }] + } +}
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/so_delete_module.jinja b/onap-client/onap_client/etc/payloads/so_delete_module.jinja new file mode 100644 index 0000000..f97ce10 --- /dev/null +++ b/onap-client/onap_client/etc/payloads/so_delete_module.jinja @@ -0,0 +1,22 @@ + { + "requestDetails": { + "requestInfo": { + "source": "VID", + "requestorId": "cs0008" + }, + "modelInfo": { + "modelType": "vfModule", + "modelInvariantId": "{{module_invariant_id}}", + "modelName": "{{module_name}}", + "modelVersion": "{{module_version}}" + }, + "requestParameters": { + "testApi": "{{api_type}}" + }, + "cloudConfiguration": { + "lcpCloudRegionId": "{{cloud_region}}", + "tenantId": "{{tenant_id}}", + "cloudOwner": "{{cloud_owner}}" + } + } + }
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/so_delete_service.jinja b/onap-client/onap_client/etc/payloads/so_delete_service.jinja new file mode 100644 index 0000000..21bcc7f --- /dev/null +++ b/onap-client/onap_client/etc/payloads/so_delete_service.jinja @@ -0,0 +1,22 @@ + { + "requestDetails": { + "requestInfo": { + "source": "VID", + "requestorId": "cs0008" + }, + "modelInfo": { + "modelType": "vnf", + "modelInvariantId": "{{service_invariant_id}}", + "modelName": "{{service_name}}", + "modelVersion": "{{service_version}}" + }, + "requestParameters": { + "testApi": "{{api_type}}" + }, + "cloudConfiguration": { + "cloudOwner": "CloudOwner", + "lcpCloudRegionId": "None", + "tenantId": "NoTenant" + } + } + }
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/so_delete_vnf.jinja b/onap-client/onap_client/etc/payloads/so_delete_vnf.jinja new file mode 100644 index 0000000..c39ac28 --- /dev/null +++ b/onap-client/onap_client/etc/payloads/so_delete_vnf.jinja @@ -0,0 +1,22 @@ + { + "requestDetails": { + "requestInfo": { + "source": "VID", + "requestorId": "cs0008" + }, + "modelInfo": { + "modelType": "vnf", + "modelInvariantId": "{{vnf_invariant_id}}", + "modelName": "{{vnf_name}}", + "modelVersion": "{{vnf_version}}" + }, + "requestParameters": { + "testApi": "{{api_type}}" + }, + "cloudConfiguration": { + "lcpCloudRegionId": "{{cloud_region}}", + "tenantId": "{{tenant_id}}", + "cloudOwner": "{{cloud_owner}}" + } + } + }
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/so_delete_volume_module.jinja b/onap-client/onap_client/etc/payloads/so_delete_volume_module.jinja new file mode 100644 index 0000000..39f7d86 --- /dev/null +++ b/onap-client/onap_client/etc/payloads/so_delete_volume_module.jinja @@ -0,0 +1,22 @@ + { + "requestDetails": { + "requestInfo": { + "source": "VID", + "requestorId": "cs0008" + }, + "modelInfo": { + "modelType": "volumeGroup", + "modelInvariantId": "{{module_invariant_id}}", + "modelName": "{{module_name}}", + "modelVersion": "{{module_version}}" + }, + "requestParameters": { + "testApi": "{{api_type}}" + }, + "cloudConfiguration": { + "lcpCloudRegionId": "{{cloud_region}}", + "tenantId": "{{tenant_id}}", + "cloudOwner": "{{cloud_owner}}" + } + } + }
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/so_service_instance.jinja b/onap-client/onap_client/etc/payloads/so_service_instance.jinja new file mode 100644 index 0000000..abdfe84 --- /dev/null +++ b/onap-client/onap_client/etc/payloads/so_service_instance.jinja @@ -0,0 +1,37 @@ +{ + "requestDetails": { + "requestInfo": { + "instanceName": "{{service_instance_name}}", + "source": "onap_client", + "suppressRollback": false, + "requestorId": "{{requestor_id}}" + }, + "modelInfo": { + "modelType": "service", + "modelInvariantId": "{{model_invariant_id}}", + "modelVersionId": "{{model_version_id}}", + "modelName": "{{model_name}}", + "modelVersion": "{{model_version}}" + }, + "cloudConfiguration": { + "tenantId": "{{tenant_id}}", + "cloudOwner": "{{cloud_owner}}", + "lcpCloudRegionId": "{{cloud_region}}" + }, + "requestParameters": { + "userParams": [], + "testApi": "{{api_type}}", + "subscriptionServiceType": "{{service_type}}", + "aLaCarte": true + }, + "subscriberInfo": { + "globalSubscriberId": "{{customer_id}}" + }, + "project": { + "projectName": "{{project_name}}" + }, + "owningEntity": { + "owningEntityId": "{{owning_entity_id}}" + } + } +}
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/so_vnf_instance.jinja b/onap-client/onap_client/etc/payloads/so_vnf_instance.jinja new file mode 100644 index 0000000..4419847 --- /dev/null +++ b/onap-client/onap_client/etc/payloads/so_vnf_instance.jinja @@ -0,0 +1,48 @@ +{ + "requestDetails": { + "requestInfo": { + "instanceName": "{{vnf_instance_name}}", + "source": "VID", + "suppressRollback": false, + "requestorId": "{{requestor_id}}", + "productFamilyId": "1234" + }, + "modelInfo": { + "modelType": "vnf", + "modelInvariantId": "{{model_invariant_id}}", + "modelVersionId": "{{model_version_id}}", + "modelName": "{{model_name}}", + "modelVersion": "{{model_version}}", + "modelCustomizationId": "{{model_customization_id}}", + "modelCustomizationName": "{{model_name}} 0" + }, + "requestParameters": { + "userParams": [], + "aLaCarte": true, + "testApi": "{{api_type}}" + }, + "cloudConfiguration": { + "tenantId": "{{tenant_id}}", + "cloudOwner": "{{cloud_owner}}", + "lcpCloudRegionId": "{{cloud_region}}" + }, + "lineOfBusiness": { + "lineOfBusinessName": "{{line_of_business}}" + }, + "platform": { + "platformName": "{{platform}}" + }, + "relatedInstanceList": [{ + "relatedInstance": { + "instanceId": "{{service_instance_id}}", + "modelInfo": { + "modelType": "service", + "modelName": "{{service_model_name}}", + "modelInvariantId": "{{service_model_invariant_id}}", + "modelVersion": "{{service_model_version}}", + "modelVersionId": "{{service_model_version_id}}" + } + } + }] + } +}
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/software_product.jinja b/onap-client/onap_client/etc/payloads/software_product.jinja new file mode 100644 index 0000000..e7bb590 --- /dev/null +++ b/onap-client/onap_client/etc/payloads/software_product.jinja @@ -0,0 +1,17 @@ +{ + "name": "{{software_product_name}}", + "description": "{{description}}", + "category": "resourceNewCategory.{{category}}", + "subCategory": "resourceNewCategory.{{category}}.{{sub_category}}", + "onboardingMethod" : "NetworkPackage", + "licensingVersion": "{{license_model_version_id}}", + "vendorName": "{{vendor_name}}", + "vendorId": "{{license_model_id}}", + "icon": "icon", + "licensingData": { + "licenseAgreement": "{{license_agreement_id}}", + "featureGroups": [ + "{{feature_group_id}}" + ] + } +}
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/software_product_update.jinja b/onap-client/onap_client/etc/payloads/software_product_update.jinja new file mode 100644 index 0000000..50e97ff --- /dev/null +++ b/onap-client/onap_client/etc/payloads/software_product_update.jinja @@ -0,0 +1 @@ +{"description":"{{description}}","creationMethod":"major"}
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/update_resource_instance.jinja b/onap-client/onap_client/etc/payloads/update_resource_instance.jinja new file mode 100644 index 0000000..d19c33d --- /dev/null +++ b/onap-client/onap_client/etc/payloads/update_resource_instance.jinja @@ -0,0 +1 @@ +{"componentUid":"{{component_id}}"}
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/user_remarks.jinja b/onap-client/onap_client/etc/payloads/user_remarks.jinja new file mode 100644 index 0000000..ea01a24 --- /dev/null +++ b/onap-client/onap_client/etc/payloads/user_remarks.jinja @@ -0,0 +1 @@ +{"userRemarks":"{{user_remarks}}"}
\ No newline at end of file diff --git a/onap-client/onap_client/etc/payloads/vid_maintenance.jinja b/onap-client/onap_client/etc/payloads/vid_maintenance.jinja new file mode 100644 index 0000000..1672140 --- /dev/null +++ b/onap-client/onap_client/etc/payloads/vid_maintenance.jinja @@ -0,0 +1,3 @@ +{ + "options": ["{{name}}"] +}
\ No newline at end of file diff --git a/onap-client/onap_client/exceptions.py b/onap-client/onap_client/exceptions.py index 8e3b843..fe7d5c0 100644 --- a/onap-client/onap_client/exceptions.py +++ b/onap-client/onap_client/exceptions.py @@ -146,3 +146,7 @@ class TenantNotFound(Exception): class ResourceCreationFailure(Exception): pass + + +class ResourceDeleteFailure(Exception): + pass diff --git a/onap-client/onap_client/resource.py b/onap-client/onap_client/resource.py index cd7c677..abe7bf0 100644 --- a/onap-client/onap_client/resource.py +++ b/onap-client/onap_client/resource.py @@ -35,7 +35,12 @@ # # ============LICENSE_END============================================ from abc import ABC -from onap_client.exceptions import InvalidSpecException, ResourceAlreadyExistsException, ResourceCreationFailure +from onap_client.exceptions import ( + InvalidSpecException, + ResourceAlreadyExistsException, + ResourceCreationFailure, + ResourceDeleteFailure +) from onap_client.client.clients import get_client as Client @@ -43,9 +48,14 @@ class Resource(ABC): resource_name = "abstract" spec = {} - def __init__(self, **kwargs): + def __init__(self, oc=None, **kwargs): self.attributes = {} - self.oc = Client() + + if not oc: + self.oc = Client() + else: + self.oc = oc + self.input_spec = self.validate(kwargs, spec=self.spec) def __getattr__(self, attr): @@ -56,9 +66,15 @@ class Resource(ABC): self.resolve_attributes(attributes) self._post_create() + def delete(self): + self._delete(self.input_spec) + def _create(self, input): pass + def _delete(self, input): + pass + def _post_create(self): pass @@ -72,8 +88,8 @@ class Resource(ABC): return None @classmethod - def create_from_spec(cls, spec, submit=True): - instance = cls(**spec) + def create_from_spec(cls, spec, submit=True, oc=None): + instance = cls(**spec, oc=oc) try: instance.create() @@ -89,6 +105,19 @@ class Resource(ABC): return instance + @classmethod + def delete_from_spec(cls, spec, oc=None): + instance = cls(**spec, oc=oc) + + try: + instance.delete() + except Exception as e: + raise ResourceDeleteFailure( + "Failed to delete resource {}: {}".format(instance.resource_name, str(e)) + ) + + return instance + def resolve_attributes(self, attributes): for key, val in attributes.items(): self.attributes[key] = val diff --git a/onap-client/onap_client/sdc/catalog/license_model_catalog.py b/onap-client/onap_client/sdc/catalog/license_model_catalog.py index a01b967..0a90ebf 100644 --- a/onap-client/onap_client/sdc/catalog/license_model_catalog.py +++ b/onap-client/onap_client/sdc/catalog/license_model_catalog.py @@ -34,16 +34,11 @@ # limitations under the License. # # ============LICENSE_END============================================ - import uuid from functools import partial -from onap_client import config from onap_client.sdc.client import SDCClient -PAYLOADS_DIR = config.PAYLOADS_DIR -application_id = config.APPLICATION_ID - class LicenseModelClient(SDCClient): @property @@ -61,7 +56,7 @@ class LicenseModelClient(SDCClient): endpoint=self.config.sdc.SDC_BE_ONBOARD_ENDPOINT, service_path=self.config.sdc.SDC_VENDOR_LICENSE_MODEL_PATH, ), - "payload": "{}/license_model.jinja".format(PAYLOADS_DIR), + "payload": "{}/license_model.jinja".format(self.config.payload_directory), "payload-parameters": ["vendor_name"], "success_code": 200, "headers": { @@ -69,7 +64,7 @@ class LicenseModelClient(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": { "license_model_id": ("itemId",), @@ -89,7 +84,7 @@ class LicenseModelClient(SDCClient): service_path=self.config.sdc.SDC_VENDOR_LICENSE_MODEL_PATH, ), "uri-parameters": ["license_model_id", "license_model_version_id"], - "payload": "{}/key_group.jinja".format(PAYLOADS_DIR), + "payload": "{}/key_group.jinja".format(self.config.payload_directory), "payload-parameters": [ "license_start_date", "license_end_date", @@ -101,7 +96,7 @@ class LicenseModelClient(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"key_group_id": ("value",)}, "auth": ( @@ -118,7 +113,7 @@ class LicenseModelClient(SDCClient): service_path=self.config.sdc.SDC_VENDOR_LICENSE_MODEL_PATH, ), "uri-parameters": ["license_model_id", "license_model_version_id"], - "payload": "{}/entitlement_pool.jinja".format(PAYLOADS_DIR), + "payload": "{}/entitlement_pool.jinja".format(self.config.payload_directory), "payload-parameters": [ "license_start_date", "license_end_date", @@ -130,7 +125,7 @@ class LicenseModelClient(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"entitlement_pool_id": ("value",)}, "auth": ( @@ -147,7 +142,7 @@ class LicenseModelClient(SDCClient): service_path=self.config.sdc.SDC_VENDOR_LICENSE_MODEL_PATH, ), "uri-parameters": ["license_model_id", "license_model_version_id"], - "payload": "{}/feature_group.jinja".format(PAYLOADS_DIR), + "payload": "{}/feature_group.jinja".format(self.config.payload_directory), "payload-parameters": [ "feature_group_name", "key_group_id", @@ -160,7 +155,7 @@ class LicenseModelClient(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"feature_group_id": ("value",)}, "auth": ( @@ -177,7 +172,7 @@ class LicenseModelClient(SDCClient): service_path=self.config.sdc.SDC_VENDOR_LICENSE_MODEL_PATH, ), "uri-parameters": ["license_model_id", "license_model_version_id"], - "payload": "{}/license_agreement.jinja".format(PAYLOADS_DIR), + "payload": "{}/license_agreement.jinja".format(self.config.payload_directory), "payload-parameters": ["feature_group_id", "license_agreement_name"], "success_code": 200, "headers": { @@ -185,7 +180,7 @@ class LicenseModelClient(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"license_agreement_id": ("value",)}, "auth": ( @@ -202,7 +197,7 @@ class LicenseModelClient(SDCClient): service_path=self.config.sdc.SDC_VENDOR_LICENSE_MODEL_PATH, ), "uri-parameters": ["license_model_id", "license_model_version_id"], - "payload": "{}/action.jinja".format(PAYLOADS_DIR), + "payload": "{}/action.jinja".format(self.config.payload_directory), "payload-parameters": ["action"], "success_code": 200, "headers": { @@ -210,7 +205,7 @@ class LicenseModelClient(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -232,7 +227,7 @@ class LicenseModelClient(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": { "vendor_name": ("vendorName",), @@ -259,7 +254,7 @@ class LicenseModelClient(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -281,7 +276,7 @@ class LicenseModelClient(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -302,7 +297,7 @@ class LicenseModelClient(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"results": ("results",)}, "auth": ( diff --git a/onap-client/onap_client/sdc/catalog/service_catalog.py b/onap-client/onap_client/sdc/catalog/service_catalog.py index aad645f..dad8456 100644 --- a/onap-client/onap_client/sdc/catalog/service_catalog.py +++ b/onap-client/onap_client/sdc/catalog/service_catalog.py @@ -34,16 +34,11 @@ # limitations under the License. # # ============LICENSE_END============================================ - import uuid from functools import partial -from onap_client import config from onap_client.sdc.client import SDCClient -PAYLOADS_DIR = config.PAYLOADS_DIR -application_id = config.APPLICATION_ID - class ServiceCatalog(SDCClient): @property @@ -61,7 +56,7 @@ class ServiceCatalog(SDCClient): endpoint=self.config.sdc.SDC_BE_ENDPOINT, service_path=self.config.sdc.SDC_CATALOG_SERVICES_PATH, ), - "payload": "{}/catalog_service.jinja".format(PAYLOADS_DIR), + "payload": "{}/catalog_service.jinja".format(self.config.payload_directory), "payload-parameters": [ "service_name", "instantiation_type", @@ -85,7 +80,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"catalog_service_id": ("uniqueId",)}, "auth": ( @@ -108,7 +103,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"catalog_service_id": ("uniqueId",)}, "auth": ( @@ -125,7 +120,7 @@ class ServiceCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_SERVICES_PATH, ), "uri-parameters": ["catalog_service_id"], - "payload": "{}/resource_instance.jinja".format(PAYLOADS_DIR), + "payload": "{}/resource_instance.jinja".format(self.config.payload_directory), "payload-parameters": [ "milli_timestamp", "catalog_resource_id", @@ -140,7 +135,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"catalog_resource_instance_id": ("uniqueId",)}, "auth": ( @@ -163,7 +158,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -179,7 +174,7 @@ class ServiceCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_SERVICES_PATH, ), "uri-parameters": ["catalog_service_id", "component_name"], - "payload": "{}/update_resource_instance.jinja".format(PAYLOADS_DIR), + "payload": "{}/update_resource_instance.jinja".format(self.config.payload_directory), "payload-parameters": [ "component_id", ], @@ -189,7 +184,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -205,7 +200,7 @@ class ServiceCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_SERVICES_PATH, ), "uri-parameters": ["catalog_service_id"], - "payload": "{}/user_remarks.jinja".format(PAYLOADS_DIR), + "payload": "{}/user_remarks.jinja".format(self.config.payload_directory), "payload-parameters": ["user_remarks"], "success_code": 200, "headers": { @@ -213,7 +208,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -229,7 +224,7 @@ class ServiceCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_SERVICES_PATH, ), "uri-parameters": ["catalog_service_id"], - "payload": "{}/user_remarks.jinja".format(PAYLOADS_DIR), + "payload": "{}/user_remarks.jinja".format(self.config.payload_directory), "payload-parameters": ["user_remarks"], "success_code": 200, "headers": { @@ -237,7 +232,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -253,7 +248,7 @@ class ServiceCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_SERVICES_PATH, ), "uri-parameters": ["catalog_service_id"], - "payload": "{}/user_remarks.jinja".format(PAYLOADS_DIR), + "payload": "{}/user_remarks.jinja".format(self.config.payload_directory), "payload-parameters": ["user_remarks"], "success_code": 200, "headers": { @@ -261,7 +256,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_tester_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -277,7 +272,7 @@ class ServiceCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_SERVICES_PATH, ), "uri-parameters": ["catalog_service_id"], - "payload": "{}/user_remarks.jinja".format(PAYLOADS_DIR), + "payload": "{}/user_remarks.jinja".format(self.config.payload_directory), "payload-parameters": ["user_remarks"], "success_code": 200, "headers": { @@ -285,7 +280,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_tester_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"catalog_service_id": ("uniqueId",)}, "auth": ( @@ -302,7 +297,7 @@ class ServiceCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_SERVICES_PATH, ), "uri-parameters": ["catalog_service_id"], - "payload": "{}/user_remarks.jinja".format(PAYLOADS_DIR), + "payload": "{}/user_remarks.jinja".format(self.config.payload_directory), "payload-parameters": ["user_remarks"], "success_code": 200, "headers": { @@ -310,7 +305,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_governor_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -333,7 +328,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_ops_user_id, # "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -349,7 +344,7 @@ class ServiceCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), "uri-parameters": ["catalog_service_id", "catalog_resource_instance_id"], - "payload": "{}/catalog_service_property.jinja".format(PAYLOADS_DIR), + "payload": "{}/catalog_service_property.jinja".format(self.config.payload_directory), "payload-parameters": [ "unique_id", "parent_unique_id", @@ -365,7 +360,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -381,7 +376,7 @@ class ServiceCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), "uri-parameters": ["catalog_service_id", "catalog_resource_instance_id"], - "payload": "{}/catalog_service_property.jinja".format(PAYLOADS_DIR), + "payload": "{}/catalog_service_property.jinja".format(self.config.payload_directory), "payload-parameters": [ "unique_id", "parent_unique_id", @@ -395,7 +390,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -411,7 +406,7 @@ class ServiceCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), "uri-parameters": ["catalog_service_id", "catalog_resource_instance_id", "module_id"], - "payload": "{}/generic_payload.jinja".format(PAYLOADS_DIR), + "payload": "{}/generic_payload.jinja".format(self.config.payload_directory), "payload-parameters": [ "payload_data", ], @@ -421,7 +416,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -443,7 +438,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -464,7 +459,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"services": ("services",)}, "auth": ( @@ -487,7 +482,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -509,7 +504,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -531,7 +526,7 @@ class ServiceCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, diff --git a/onap-client/onap_client/sdc/catalog/vnf_catalog.py b/onap-client/onap_client/sdc/catalog/vnf_catalog.py index 692052f..71b20ca 100644 --- a/onap-client/onap_client/sdc/catalog/vnf_catalog.py +++ b/onap-client/onap_client/sdc/catalog/vnf_catalog.py @@ -34,16 +34,11 @@ # limitations under the License. # # ============LICENSE_END============================================ - import uuid from functools import partial -from onap_client import config from onap_client.sdc.client import SDCClient -PAYLOADS_DIR = config.PAYLOADS_DIR -application_id = config.APPLICATION_ID - class VNFCatalog(SDCClient): @property @@ -61,7 +56,7 @@ class VNFCatalog(SDCClient): endpoint=self.config.sdc.SDC_BE_ENDPOINT, service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), - "payload": "{}/catalog_resource.jinja".format(PAYLOADS_DIR), + "payload": "{}/catalog_resource.jinja".format(self.config.payload_directory), "payload-parameters": [ "software_product_id", "vnf_name", @@ -77,7 +72,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"catalog_resource_id": ("uniqueId",)}, "auth": ( @@ -94,7 +89,7 @@ class VNFCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), "uri-parameters": ["catalog_resource_id"], - "payload": "{}/user_remarks.jinja".format(PAYLOADS_DIR), + "payload": "{}/user_remarks.jinja".format(self.config.payload_directory), "payload-parameters": ["user_remarks"], "success_code": 200, "headers": { @@ -102,7 +97,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"catalog_resource_id": ("uniqueId",)}, "auth": ( @@ -118,7 +113,7 @@ class VNFCatalog(SDCClient): endpoint=self.config.sdc.SDC_BE_ENDPOINT, service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), - "payload": "{}/catalog_vnf_input.jinja".format(PAYLOADS_DIR), + "payload": "{}/catalog_vnf_input.jinja".format(self.config.payload_directory), "payload-parameters": [ "input_default_value", "input_name", @@ -133,7 +128,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -150,14 +145,14 @@ class VNFCatalog(SDCClient): ), "uri-parameters": ["catalog_resource_id"], "success_code": 200, - "payload": "{}/generic_payload.jinja".format(PAYLOADS_DIR), + "payload": "{}/generic_payload.jinja".format(self.config.payload_directory), "payload-parameters": ["payload_data"], "headers": { "Accept": "application/json", "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -179,7 +174,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -194,7 +189,7 @@ class VNFCatalog(SDCClient): endpoint=self.config.sdc.SDC_BE_ENDPOINT, service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), - "payload": "{}/catalog_vnf_property.jinja".format(PAYLOADS_DIR), + "payload": "{}/catalog_vnf_property.jinja".format(self.config.payload_directory), "payload-parameters": [ "unique_id", "parent_unique_id", @@ -211,7 +206,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -226,7 +221,7 @@ class VNFCatalog(SDCClient): endpoint=self.config.sdc.SDC_BE_ENDPOINT, service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), - "payload": "{}/catalog_vnf_property.jinja".format(PAYLOADS_DIR), + "payload": "{}/catalog_vnf_property.jinja".format(self.config.payload_directory), "payload-parameters": [ "unique_id", "parent_unique_id", @@ -243,7 +238,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -265,7 +260,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"catalog_resource_id": ("uniqueId",)}, "auth": ( @@ -282,7 +277,7 @@ class VNFCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), "uri-parameters": ["catalog_resource_id", "catalog_policy_id"], - "payload": "{}/catalog_vnf_policy_property.jinja".format(PAYLOADS_DIR), + "payload": "{}/catalog_vnf_policy_property.jinja".format(self.config.payload_directory), "payload-parameters": [ "unique_id", "property_name", @@ -296,7 +291,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -318,7 +313,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"catalog_resource_id": ("uniqueId",)}, "auth": ( @@ -335,7 +330,7 @@ class VNFCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), "uri-parameters": ["catalog_resource_id", "catalog_group_id"], - "payload": "{}/catalog_vnf_group_property.jinja".format(PAYLOADS_DIR), + "payload": "{}/catalog_vnf_group_property.jinja".format(self.config.payload_directory), "payload-parameters": [ "unique_id", "property_name", @@ -351,7 +346,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -366,7 +361,7 @@ class VNFCatalog(SDCClient): endpoint=self.config.sdc.SDC_BE_ENDPOINT, service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), - "payload": "{}/catalog_vnf_group.jinja".format(PAYLOADS_DIR), + "payload": "{}/catalog_vnf_group.jinja".format(self.config.payload_directory), "payload-parameters": ["instance_id"], "uri-parameters": ["catalog_resource_id", "catalog_group_id"], "success_code": 200, @@ -375,7 +370,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -390,7 +385,7 @@ class VNFCatalog(SDCClient): endpoint=self.config.sdc.SDC_BE_ENDPOINT, service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), - "payload": "{}/catalog_vnf_policy.jinja".format(PAYLOADS_DIR), + "payload": "{}/catalog_vnf_policy.jinja".format(self.config.payload_directory), "payload-parameters": ["instance_ids"], "uri-parameters": ["catalog_resource_id", "catalog_policy_id"], "success_code": 200, @@ -399,7 +394,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -415,7 +410,7 @@ class VNFCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), "uri-parameters": ["catalog_resource_id"], - "payload": "{}/resource_instance_vnf.jinja".format(PAYLOADS_DIR), + "payload": "{}/resource_instance_vnf.jinja".format(self.config.payload_directory), "payload-parameters": [ "milli_timestamp", "new_catalog_resource_id", @@ -431,7 +426,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -447,7 +442,7 @@ class VNFCatalog(SDCClient): service_path=self.config.sdc.SDC_CATALOG_RESOURCES_PATH, ), "uri-parameters": ["catalog_resource_id"], - "payload": "{}/add_resource_relationship.jinja".format(PAYLOADS_DIR), + "payload": "{}/add_resource_relationship.jinja".format(self.config.payload_directory), "payload-parameters": [ "from_node_resource_id", "to_node_resource_id", @@ -464,7 +459,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -486,7 +481,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"catalog_resource_name": ("name",)}, "auth": ( @@ -509,7 +504,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -530,7 +525,7 @@ class VNFCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"resources": ("resources",)}, "auth": ( diff --git a/onap-client/onap_client/sdc/catalog/vsp_catalog.py b/onap-client/onap_client/sdc/catalog/vsp_catalog.py index c16fa16..f8ddb9b 100644 --- a/onap-client/onap_client/sdc/catalog/vsp_catalog.py +++ b/onap-client/onap_client/sdc/catalog/vsp_catalog.py @@ -34,16 +34,11 @@ # limitations under the License. # # ============LICENSE_END============================================ - import uuid from functools import partial -from onap_client import config from onap_client.sdc.client import SDCClient -PAYLOADS_DIR = config.PAYLOADS_DIR -application_id = config.APPLICATION_ID - class VSPCatalog(SDCClient): @property @@ -61,7 +56,7 @@ class VSPCatalog(SDCClient): endpoint=self.config.sdc.SDC_BE_ONBOARD_ENDPOINT, service_path=self.config.sdc.SDC_VENDOR_SOFTWARE_PRODUCT_PATH, ), - "payload": "{}/software_product.jinja".format(PAYLOADS_DIR), + "payload": "{}/software_product.jinja".format(self.config.payload_directory), "payload-parameters": [ "software_product_name", "feature_group_id", @@ -79,7 +74,7 @@ class VSPCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": { "software_product_id": ("itemId",), @@ -98,7 +93,7 @@ class VSPCatalog(SDCClient): endpoint=self.config.sdc.SDC_BE_ONBOARD_ENDPOINT, service_path=self.config.sdc.SDC_VENDOR_ITEMS_PATH, ), - "payload": "{}/software_product_update.jinja".format(PAYLOADS_DIR), + "payload": "{}/software_product_update.jinja".format(self.config.payload_directory), "payload-parameters": [ "description", ], @@ -109,7 +104,7 @@ class VSPCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -132,7 +127,7 @@ class VSPCatalog(SDCClient): "Content-Type": "multipart/form-data", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -154,7 +149,7 @@ class VSPCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -170,7 +165,7 @@ class VSPCatalog(SDCClient): service_path=self.config.sdc.SDC_VENDOR_SOFTWARE_PRODUCT_PATH, ), "uri-parameters": ["software_product_id", "software_product_version_id"], - "payload": "{}/action.jinja".format(PAYLOADS_DIR), + "payload": "{}/action.jinja".format(self.config.payload_directory), "payload-parameters": ["action"], "success_code": 200, "headers": { @@ -178,7 +173,7 @@ class VSPCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -194,7 +189,7 @@ class VSPCatalog(SDCClient): service_path=self.config.sdc.SDC_VENDOR_SOFTWARE_PRODUCT_PATH, ), "uri-parameters": ["software_product_id", "software_product_version_id"], - "payload": "{}/action.jinja".format(PAYLOADS_DIR), + "payload": "{}/action.jinja".format(self.config.payload_directory), "payload-parameters": ["action"], "success_code": 200, "headers": { @@ -202,7 +197,7 @@ class VSPCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -224,7 +219,7 @@ class VSPCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"name": ("name",)}, "auth": ( @@ -247,7 +242,7 @@ class VSPCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"name": ("name",)}, "auth": ( @@ -270,7 +265,7 @@ class VSPCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": { "software_product_version_id": ("id",), @@ -295,7 +290,7 @@ class VSPCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "return_data": {"results": ("results",)}, "auth": ( @@ -318,7 +313,7 @@ class VSPCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -334,7 +329,7 @@ class VSPCatalog(SDCClient): service_path=self.config.sdc.SDC_VENDOR_ITEMS_PATH, ), "uri-parameters": ["software_product_id"], - "payload": "{}/add_vsp_contributer.jinja".format(PAYLOADS_DIR), + "payload": "{}/add_vsp_contributer.jinja".format(self.config.payload_directory), "payload-parameters": ["user_id"], "success_code": 200, "headers": { @@ -342,7 +337,7 @@ class VSPCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, @@ -358,7 +353,7 @@ class VSPCatalog(SDCClient): service_path=self.config.sdc.SDC_VENDOR_ITEMS_PATH, ), "uri-parameters": ["software_product_id"], - "payload": "{}/add_vsp_contributer.jinja".format(PAYLOADS_DIR), + "payload": "{}/add_vsp_contributer.jinja".format(self.config.payload_directory), "payload-parameters": ["user_id"], "success_code": 200, "headers": { @@ -366,7 +361,7 @@ class VSPCatalog(SDCClient): "Content-Type": "application/json", "USER_ID": self.sdc_designer_user_id, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": ( self.global_sdc_username, diff --git a/onap-client/onap_client/sdc/client.py b/onap-client/onap_client/sdc/client.py index cfdd4ad..725cbeb 100644 --- a/onap-client/onap_client/sdc/client.py +++ b/onap-client/onap_client/sdc/client.py @@ -34,14 +34,10 @@ # limitations under the License. # # ============LICENSE_END============================================ - import uuid from functools import partial from onap_client.client.clients import Client -from onap_client import config - -application_id = config.APPLICATION_ID class SDCClient(Client): @@ -66,7 +62,7 @@ class SDCClient(Client): "Content-Type": "application/json", "USER_ID": self.config.sdc.SDC_DESIGNER_USER_ID, "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, # "auth": ( # self.sdc_designer_user_id, diff --git a/onap-client/onap_client/sdc/license_model.py b/onap-client/onap_client/sdc/license_model.py index 1fbcea2..ed5ba80 100644 --- a/onap-client/onap_client/sdc/license_model.py +++ b/onap-client/onap_client/sdc/license_model.py @@ -87,7 +87,7 @@ class LicenseModel(Resource): def _create(self, license_input): """Creates a license model object in SDC""" - return create_license_model(license_input) + return create_license_model(license_input, oc=self.oc) def _submit(self): """Submits the license model in SDC""" @@ -103,14 +103,15 @@ class LicenseModel(Resource): # TODO # Break this up into class funcs? -def create_license_model(license_input): +def create_license_model(license_input, oc=None): """Creates a license model object in SDC :license_input: dictionary with values to input for lm creation :return: dictionary of updated values for created lm """ - oc = Client() + if not oc: + oc = Client() kwargs = license_input license_model = oc.sdc.license_model.add_license_model(**kwargs) @@ -141,14 +142,15 @@ def create_license_model(license_input): return kwargs -def get_license_model_id(license_model_name): +def get_license_model_id(license_model_name, oc=None): """GETs license model UUID from SDC :license_model_name: name of license model in SDC :return: uuid of lm or None """ - oc = Client() + if not oc: + oc = Client() response = oc.sdc.license_model.get_license_models() results = response.response_data.get("results") @@ -158,14 +160,15 @@ def get_license_model_id(license_model_name): return None -def get_license_model_version_id(license_model_id): +def get_license_model_version_id(license_model_id, oc=None): """GETs license model version UUID from SDC :license_model_id: uuid of license model in SDC :return: uuid of lm version id or None """ - oc = Client() + if not oc: + oc = Client() license_model_version_id = None creation_time = -1 @@ -181,7 +184,7 @@ def get_license_model_version_id(license_model_id): return license_model_version_id -def get_license_model_attribute(license_model_id, license_model_version_id, attribute): +def get_license_model_attribute(license_model_id, license_model_version_id, attribute, oc=None): """GETs license model attribute from SDC :license_model_id: uuid of license model in SDC @@ -190,7 +193,8 @@ def get_license_model_attribute(license_model_id, license_model_version_id, attr :return: uuid of attribute of license-model """ - oc = Client() + if not oc: + oc = Client() response = oc.sdc.license_model.get_license_model_version_attribute( license_model_id=license_model_id, diff --git a/onap-client/onap_client/sdc/service.py b/onap-client/onap_client/sdc/service.py index 6aace73..c405e42 100644 --- a/onap-client/onap_client/sdc/service.py +++ b/onap-client/onap_client/sdc/service.py @@ -121,11 +121,11 @@ class Service(Resource): """Creates a service object in SDC""" service = None - existing = get_service_id(service_input.get("service_name")) + existing = get_service_id(service_input.get("service_name"), oc=self.oc) if existing is None: - service = create_service(service_input) + service = create_service(service_input, oc=self.oc) elif service_input.get("allow_update"): - service = update_service(existing, service_input) + service = update_service(existing, service_input, oc=self.oc) else: raise exceptions.ResourceAlreadyExistsException( "Service resource {} already exists".format( @@ -144,7 +144,7 @@ class Service(Resource): resource_id = resource.get("resource_id") resource_properties = resource.get("properties") if not resource_id: - resource_id = get_vnf_id(catalog_resource_name) + resource_id = get_vnf_id(catalog_resource_name, oc=self.oc) if not resource_id: raise exceptions.ResourceIDNotFoundException( "resource ID was not passed, and resource lookup by name was not found {}".format( @@ -205,7 +205,7 @@ class Service(Resource): self.oc.sdc.service.distribute_sdc_service(**self.attributes, **headers) if self.wait_for_distribution: - poll_distribution(self.service_name) + poll_distribution(self.service_name, oc=self.oc) self._refresh() @@ -326,8 +326,9 @@ class Service(Resource): return self.tosca -def update_service(existing_service_id, service_input): - oc = Client() +def update_service(existing_service_id, service_input, oc=None): + if not oc: + oc = Client() kwargs = service_input @@ -348,14 +349,15 @@ def update_service(existing_service_id, service_input): return kwargs -def create_service(service_input): +def create_service(service_input, oc=None): """Creates a service object in SDC :service_input: dictionary with values to input for service creation :return: dictionary of updated values for created service """ - oc = Client() + if not oc: + oc = Client() category_name_lower = service_input.get("category_name").lower() category_name_icon = normalize_category_icon(service_input.get("category_name")) @@ -373,19 +375,21 @@ def create_service(service_input): @utility -def get_service(service_name): +def get_service(service_name, oc=None): """Queries SDC for the TOSCA model for a service""" - oc = Client() + if not oc: + oc = Client() return oc.sdc.service.get_sdc_service( - catalog_service_id=get_service_id(service_name) + catalog_service_id=get_service_id(service_name, oc=oc) ).response_data @utility -def get_service_id(service_name): +def get_service_id(service_name, oc=None): """Queries SDC for the uniqueId of a service model""" - oc = Client() + if not oc: + oc = Client() response = oc.sdc.service.get_services() results = response.response_data.get("services", []) @@ -399,14 +403,18 @@ def get_service_id(service_name): return catalog_service.get("uniqueId") -def get_service_uuid(service_name): - return get_service(service_name).get("uuid") +def get_service_uuid(service_name, oc=None): + if not oc: + oc = Client() + + return get_service(service_name, oc=oc).get("uuid") -def get_service_distribution(service_name): - oc = Client() +def get_service_distribution(service_name, oc=None): + if not oc: + oc = Client() - distribution_id = get_distribution_id(service_name) + distribution_id = get_distribution_id(service_name, oc=oc) if distribution_id: return oc.sdc.service.get_service_distribution_details( @@ -416,11 +424,12 @@ def get_service_distribution(service_name): return None -def get_distribution_id(service_name): - oc = Client() +def get_distribution_id(service_name, oc=None): + if not oc: + oc = Client() distribution = oc.sdc.service.get_service_distribution( - distribution_service_id=get_service_uuid(service_name) + distribution_service_id=get_service_uuid(service_name, oc=oc) ).response_data if distribution: details = distribution.get("distributionStatusOfServiceList", []) @@ -431,14 +440,15 @@ def get_distribution_id(service_name): @utility -def poll_distribution(service_name): +def poll_distribution(service_name, oc=None): """Polls a distributed service until distribution is complete""" - oc = Client() + if not oc: + oc = Client() poll_interval = oc.config.sdc.POLL_INTERVAL or 30 x = 0 while x < 30: - distribution = get_service_distribution(service_name) + distribution = get_service_distribution(service_name, oc=oc) if not distribution: raise exceptions.DistributionNotFound( "Could not determine distribution status for {}".format(service_name) @@ -470,10 +480,11 @@ def poll_distribution(service_name): @utility -def download_csar(service_name, output_file): - oc = Client() +def download_csar(service_name, output_file, oc=None): + if not oc: + oc = Client() - service = get_service(service_name) + service = get_service(service_name, oc=oc) artifact_id = service.get("toscaArtifacts", {}).get("assettoscacsar", {}).get("uniqueId") csar_data = oc.sdc.service.get_sdc_csar( diff --git a/onap-client/onap_client/sdc/vnf.py b/onap-client/onap_client/sdc/vnf.py index 39c66b8..4c42dbe 100644 --- a/onap-client/onap_client/sdc/vnf.py +++ b/onap-client/onap_client/sdc/vnf.py @@ -126,11 +126,11 @@ class VNF(Resource): """Creates a vnf object in SDC""" vnf = None - existing = get_vnf_id(vnf_input.get("vnf_name")) + existing = get_vnf_id(vnf_input.get("vnf_name"), oc=self.oc) if not existing: - vnf = create_vnf(vnf_input) + vnf = create_vnf(vnf_input, oc=self.oc) elif vnf_input.get("allow_update"): - vnf = update_vnf(existing, vnf_input) + vnf = update_vnf(existing, vnf_input, oc=self.oc) else: raise exceptions.ResourceAlreadyExistsException( "VNF resource {} already exists".format(vnf_input.get("vnf_name")) @@ -206,14 +206,14 @@ class VNF(Resource): resource_relationship = resource.get("relationship", {}) if not resource_id: - resource_id = get_vnf_id(catalog_resource_name) + resource_id = get_vnf_id(catalog_resource_name, oc=self.oc) if not resource_id: raise exceptions.ResourceIDNotFoundException( "resource ID was not passed, and resource lookup by name was not found {}".format( resource_name ) ) - new_resource = add_resource(self.catalog_resource_id, resource_id, resource_name, origin_type=resource_origin) + new_resource = add_resource(self.catalog_resource_id, resource_id, resource_name, origin_type=resource_origin, oc=self.oc) self._refresh() new_resource_id = new_resource["id"] if resource_relationship: @@ -460,9 +460,7 @@ class VNF(Resource): :policy_name: name of the policy, matching onap-client.conf """ - oc = Client() - - policy = oc.config.sdc.POLICIES.get(policy_name) + policy = self.oc.config.sdc.POLICIES.get(policy_name) if not policy: raise exceptions.UnknownPolicyException( "Policy {} was not found in configuration file".format(policy_name) @@ -497,8 +495,9 @@ class VNF(Resource): return self.tosca -def update_vnf(catalog_resource_id, vnf_input): - oc = Client() +def update_vnf(catalog_resource_id, vnf_input, oc=None): + if not oc: + oc = Client() existing_vnf = oc.sdc.vnf.get_catalog_resource( catalog_resource_id=catalog_resource_id @@ -511,7 +510,7 @@ def update_vnf(catalog_resource_id, vnf_input): new_vnf_metadata = oc.sdc.vnf.get_catalog_resource_metadata(catalog_resource_id=vnf.get("uniqueId")).response_data.get("metadata", {}) - csar_version = vsp.get_vsp_version_id(vnf.get("csarUUID"), search_key="name") + csar_version = vsp.get_vsp_version_id(vnf.get("csarUUID"), search_key="name", oc=oc) vnf["csarVersion"] = csar_version vnf["componentMetadata"] = new_vnf_metadata @@ -524,18 +523,19 @@ def update_vnf(catalog_resource_id, vnf_input): return vnf_input -def create_vnf(vnf_input): +def create_vnf(vnf_input, oc=None): """Creates a vnf object in SDC :vnf_input: dictionary with values to input for vnf creation :return: dictionary of updated values for created vnf """ - oc = Client() + if not oc: + oc = Client() - software_product_id = vsp.get_vsp_id(vnf_input.get("software_product_name")) - software_product_version_id = vsp.get_vsp_version_id(software_product_id) - vsp_model = vsp.get_vsp_model(software_product_id, software_product_version_id) + software_product_id = vsp.get_vsp_id(vnf_input.get("software_product_name"), oc=oc) + software_product_version_id = vsp.get_vsp_version_id(software_product_id, oc=oc) + vsp_model = vsp.get_vsp_model(software_product_id, software_product_version_id, oc=oc) vsp_vendor = vsp_model.get("vendorName") vsp_category = vsp_model.get("category") @@ -547,7 +547,7 @@ def create_vnf(vnf_input): vnf_input["vendor_name"] = vsp_vendor vnf_input["vnf_description"] = vnf_input.get("description") - category = get_resource_category(vsp_category) + category = get_resource_category(vsp_category, oc=oc) vsp_sub_categories = [] for subcategory in category.get("subcategories", []): if subcategory.get("uniqueId").lower() == vsp_sub_category.lower(): @@ -555,7 +555,7 @@ def create_vnf(vnf_input): break category["subcategories"] = vsp_sub_categories - vnf_input["contact_id"] = vsp.get_vsp_owner(software_product_id) + vnf_input["contact_id"] = vsp.get_vsp_owner(software_product_id, oc=oc) vnf = oc.sdc.vnf.add_catalog_resource(**vnf_input, categories=[category]) @@ -611,7 +611,7 @@ def network_role_property_for_instance(network_role_tag, vnf_model, instance_id) return properties -def add_resource(parent_resource_id, catalog_resource_id, catalog_resource_name, origin_type="VF"): +def add_resource(parent_resource_id, catalog_resource_id, catalog_resource_name, origin_type="VF", oc=None): """Attaches a resource to a VNF in SDC :catalog_resource_id: ID of a resource in the SDC catalog @@ -619,7 +619,8 @@ def add_resource(parent_resource_id, catalog_resource_id, catalog_resource_name, :origin_type: specifies the origin of the attached resource """ - oc = Client() + if not oc: + oc = Client() milli_timestamp = int(time.time() * 1000) @@ -642,17 +643,20 @@ def add_resource(parent_resource_id, catalog_resource_id, catalog_resource_name, @utility -def get_vnf(vnf_name): +def get_vnf(vnf_name, oc=None): """Queries SDC for the TOSCA model for a VNF""" - oc = Client() + if not oc: + oc = Client() return oc.sdc.vnf.get_catalog_resource( - catalog_resource_id=get_vnf_id(vnf_name) + catalog_resource_id=get_vnf_id(vnf_name, oc=oc) ).response_data -def get_resource_category(category_name): - oc = Client() +def get_resource_category(category_name, oc=None): + if not oc: + oc = Client() + resource_categories = oc.sdc.get_resource_categories().response_data for category in resource_categories: if category.get("uniqueId").lower() == category_name.lower(): @@ -660,8 +664,9 @@ def get_resource_category(category_name): return None -def get_vnf_id(vnf_name): - oc = Client() +def get_vnf_id(vnf_name, oc=None): + if not oc: + oc = Client() response = oc.sdc.vnf.get_resources() results = response.response_data.get("resources", []) diff --git a/onap-client/onap_client/sdc/vsp.py b/onap-client/onap_client/sdc/vsp.py index 365c628..3a8dcde 100644 --- a/onap-client/onap_client/sdc/vsp.py +++ b/onap-client/onap_client/sdc/vsp.py @@ -81,11 +81,11 @@ class VSP(Resource): """Creates a vsp object in SDC""" vsp = None - existing = get_vsp(vsp_input.get("software_product_name")) + existing = get_vsp(vsp_input.get("software_product_name"), oc=self.oc) if not existing: - vsp = create_vsp(vsp_input) + vsp = create_vsp(vsp_input, oc=self.oc) elif vsp_input.get("allow_update"): - vsp = update_vsp(existing, vsp_input) + vsp = update_vsp(existing, vsp_input, oc=self.oc) else: raise ResourceAlreadyExistsException( "VSP resource {} already exists".format( @@ -128,13 +128,14 @@ class VSP(Resource): return self.tosca -def update_vsp(existing_vsp, vsp_input): - oc = Client() +def update_vsp(existing_vsp, vsp_input, oc=None): + if not oc: + oc = Client() existing_vsp_id = existing_vsp.get("id") existing_vsp_version_id = existing_vsp.get("version") - if get_vsp_version_id(existing_vsp_id, search_key="status") == "Certified": + if get_vsp_version_id(existing_vsp_id, search_key="status", oc=oc) == "Certified": oc.sdc.vsp.update_software_product( software_product_id=existing_vsp_id, software_product_version_id=existing_vsp_version_id, @@ -142,7 +143,7 @@ def update_vsp(existing_vsp, vsp_input): ) vsp_input["software_product_id"] = existing_vsp_id - vsp_input["software_product_version_id"] = get_vsp_version_id(existing_vsp_id) + vsp_input["software_product_version_id"] = get_vsp_version_id(existing_vsp_id, oc=oc) oc.sdc.vsp.upload_heat_package(**vsp_input) oc.sdc.vsp.validate_software_product(**vsp_input) @@ -153,27 +154,38 @@ def update_vsp(existing_vsp, vsp_input): return vsp_input -def create_vsp(vsp_input): +def create_vsp(vsp_input, oc=None): """Creates a VSP object in SDC :vsp_input: dictionary with values to input for vsp creation :return: dictionary of updated values for created vsp """ - oc = Client() + if not oc: + oc = Client() - license_model_id = sdc.license_model.get_license_model_id(vsp_input.get("license_model_name")) + license_model_id = sdc.license_model.get_license_model_id( + vsp_input.get("license_model_name"), + oc=oc + ) license_model_version_id = sdc.license_model.get_license_model_version_id( - license_model_id + license_model_id, + oc=oc ) feature_group = sdc.license_model.get_license_model_attribute( - license_model_id, license_model_version_id, "feature-groups" + license_model_id, + license_model_version_id, + "feature-groups", + oc=oc ) license_agreement = sdc.license_model.get_license_model_attribute( - license_model_id, license_model_version_id, "license-agreements" + license_model_id, + license_model_version_id, + "license-agreements", + oc=oc ) vsp_input["license_model_id"] = license_model_id @@ -195,14 +207,15 @@ def create_vsp(vsp_input): return vsp_input -def get_vsp_id(vsp_name): +def get_vsp_id(vsp_name, oc=None): """GETs vsp model ID from SDC :vsp_name: name of vsp model in SDC :return: id of vsp or None """ - oc = Client() + if not oc: + oc = Client() response = oc.sdc.vsp.get_software_products() results = response.response_data.get("results", {}) @@ -212,14 +225,15 @@ def get_vsp_id(vsp_name): return None -def get_vsp_version_id(vsp_id, search_key="id"): +def get_vsp_version_id(vsp_id, search_key="id", oc=None): """GETs vsp model version UUID from SDC :vsp_id: uuid of vsp model in SDC :return: uuid of vsp version id or None """ - oc = Client() + if not oc: + oc = Client() vsp_version_id = None creation_time = -1 @@ -233,16 +247,19 @@ def get_vsp_version_id(vsp_id, search_key="id"): return vsp_version_id -def get_vsp_model(vsp_id, vsp_version_id): - oc = Client() +def get_vsp_model(vsp_id, vsp_version_id, oc=None): + if not oc: + oc = Client() return oc.sdc.vsp.get_software_product( software_product_id=vsp_id, software_product_version_id=vsp_version_id, ).response_data -def get_vsp_owner(vsp_id): - oc = Client() +def get_vsp_owner(vsp_id, oc=None): + if not oc: + oc = Client() + vsps = oc.sdc.vsp.get_software_products().response_data.get("results", []) for vsp in vsps: if vsp.get("id") == vsp_id: @@ -251,13 +268,16 @@ def get_vsp_owner(vsp_id): @utility -def get_vsp(vsp_name): +def get_vsp(vsp_name, oc=None): """Queries SDC for the tosca model for a VSP""" - vsp_id = get_vsp_id(vsp_name) + if not oc: + oc = Client() + + vsp_id = get_vsp_id(vsp_name, oc=oc) if vsp_id is None: return None - vsp_version_id = get_vsp_version_id(vsp_id) - return get_vsp_model(vsp_id, vsp_version_id) + vsp_version_id = get_vsp_version_id(vsp_id, oc=oc) + return get_vsp_model(vsp_id, vsp_version_id, oc=oc) def user_exists(contributer, vsp_permissions, permission="Contributor"): diff --git a/onap-client/onap_client/sdnc/catalog/config_catalog.py b/onap-client/onap_client/sdnc/catalog/config_catalog.py index 18854e8..b3c5b1f 100644 --- a/onap-client/onap_client/sdnc/catalog/config_catalog.py +++ b/onap-client/onap_client/sdnc/catalog/config_catalog.py @@ -34,21 +34,16 @@ # limitations under the License. # # ============LICENSE_END============================================ - import uuid from functools import partial -from onap_client import config from onap_client.sdnc.client import SDNCClient -PAYLOADS_DIR = config.PAYLOADS_DIR -application_id = config.APPLICATION_ID - class ConfigClient(SDNCClient): @property def namespace(self): - return "config" + return "configuration" @property def catalog_resources(self): @@ -66,7 +61,7 @@ class ConfigClient(SDNCClient): "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.sdnc.SDNC_USERNAME, self.config.sdnc.SDNC_PASSWORD,), }, @@ -84,7 +79,7 @@ class ConfigClient(SDNCClient): "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.sdnc.SDNC_USERNAME, self.config.sdnc.SDNC_PASSWORD,), }, @@ -102,7 +97,7 @@ class ConfigClient(SDNCClient): "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.sdnc.SDNC_USERNAME, self.config.sdnc.SDNC_PASSWORD,), }, diff --git a/onap-client/onap_client/sdnc/catalog/operations_catalog.py b/onap-client/onap_client/sdnc/catalog/operations_catalog.py index 2d9662b..79e6f29 100644 --- a/onap-client/onap_client/sdnc/catalog/operations_catalog.py +++ b/onap-client/onap_client/sdnc/catalog/operations_catalog.py @@ -34,16 +34,11 @@ # limitations under the License. # # ============LICENSE_END============================================ - import uuid from functools import partial -from onap_client import config from onap_client.sdnc.client import SDNCClient -PAYLOADS_DIR = config.PAYLOADS_DIR -application_id = config.APPLICATION_ID - class OperationsClient(SDNCClient): @property @@ -67,7 +62,7 @@ class OperationsClient(SDNCClient): "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.sdnc.SDNC_USERNAME, self.config.sdnc.SDNC_PASSWORD,), }, @@ -85,7 +80,7 @@ class OperationsClient(SDNCClient): "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.sdnc.SDNC_USERNAME, self.config.sdnc.SDNC_PASSWORD,), }, diff --git a/onap-client/onap_client/sdnc/client.py b/onap-client/onap_client/sdnc/client.py index 9f5a495..1ebd04a 100644 --- a/onap-client/onap_client/sdnc/client.py +++ b/onap-client/onap_client/sdnc/client.py @@ -34,11 +34,7 @@ # limitations under the License. # # ============LICENSE_END============================================ - from onap_client.client.clients import Client -from onap_client import config - -application_id = config.APPLICATION_ID class SDNCClient(Client): diff --git a/onap-client/onap_client/sdnc/preload.py b/onap-client/onap_client/sdnc/preload.py index 5e1ee91..6fa9c4f 100644 --- a/onap-client/onap_client/sdnc/preload.py +++ b/onap-client/onap_client/sdnc/preload.py @@ -56,8 +56,8 @@ class Preload(Resource): } def _create(self, instance_input): - service_instance = so.vnf_instance.get_service_instance( - instance_input.get("service_instance_name") + service_instance = so.service_instance.get_service_instance( + instance_input.get("service_instance_name"), oc=self.oc ) if not service_instance: raise ServiceInstanceNotFound( @@ -66,7 +66,7 @@ class Preload(Resource): ) ) - vnf_instance = so.vnf_instance.get_vnf_instance( + vnf_instance = so.service_instance.get_vnf_instance( service_instance, instance_input.get("vnf_instance_name") ) if not vnf_instance: @@ -90,9 +90,9 @@ class Preload(Resource): vnf_model_name = vnf_model_information["model-name"] vnf_component = so.vnf_instance.get_vnf_model_component( - service_model_name, vnf_model_name + service_model_name, vnf_model_name, oc=self.oc ) - module_model = so.vnf_instance.get_module_model( + module_model = so.module_instance.get_module_model( vnf_component, instance_input.get("heat_template_name") ) @@ -105,13 +105,14 @@ class Preload(Resource): module_model.get("groupName"), ) - create_preload(preload_path, instance_input.get("api_type")) + create_preload(preload_path, instance_input.get("api_type"), oc=self.oc) return instance_input -def create_preload(preload_path, api_type): - oc = Client() +def create_preload(preload_path, api_type, oc=None): + if not oc: + oc = Client() if api_type == "GR_API": oc.sdnc.operations.gr_api_preload(preload_path=preload_path) diff --git a/onap-client/onap_client/so/catalog/service_instantiation.py b/onap-client/onap_client/so/catalog/service_instantiation.py index d561317..3874aef 100644 --- a/onap-client/onap_client/so/catalog/service_instantiation.py +++ b/onap-client/onap_client/so/catalog/service_instantiation.py @@ -34,16 +34,11 @@ # limitations under the License. # # ============LICENSE_END============================================ - import uuid from functools import partial -from onap_client import config from onap_client.so.client import SOClient -PAYLOADS_DIR = config.PAYLOADS_DIR -application_id = config.APPLICATION_ID - class ServiceInstantiationClient(SOClient): @property @@ -61,7 +56,7 @@ class ServiceInstantiationClient(SOClient): endpoint=self.config.so.SO_ENDPOINT, service_path=self.config.so.SO_SERVICE_INSTANCE_PATH, ), - "payload": "{}/so_service_instance.jinja".format(PAYLOADS_DIR), + "payload": "{}/so_service_instance.jinja".format(self.config.payload_directory), "payload-parameters": [ "service_instance_name", "requestor_id", @@ -84,7 +79,7 @@ class ServiceInstantiationClient(SOClient): "Accept": "application/json", "Content-Type": "application/json", # "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.so.SO_USERNAME, self.config.so.SO_PASSWORD), }, @@ -97,7 +92,7 @@ class ServiceInstantiationClient(SOClient): service_path=self.config.so.SO_SERVICE_INSTANCE_PATH, ), "uri-parameters": ["service_instance_id"], - "payload": "{}/so_delete_service.jinja".format(PAYLOADS_DIR), + "payload": "{}/so_delete_service.jinja".format(self.config.payload_directory), "payload-parameters": [ "service_invariant_id", "service_name", @@ -110,7 +105,7 @@ class ServiceInstantiationClient(SOClient): "Accept": "application/json", "Content-Type": "application/json", # "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.so.SO_USERNAME, self.config.so.SO_PASSWORD), }, @@ -123,7 +118,7 @@ class ServiceInstantiationClient(SOClient): service_path=self.config.so.SO_SERVICE_INSTANCE_PATH, ), "uri-parameters": ["service_instance_id"], - "payload": "{}/so_vnf_instance.jinja".format(PAYLOADS_DIR), + "payload": "{}/so_vnf_instance.jinja".format(self.config.payload_directory), "payload-parameters": [ "vnf_instance_name", "requestor_id", @@ -150,7 +145,7 @@ class ServiceInstantiationClient(SOClient): "Accept": "application/json", "Content-Type": "application/json", # "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.so.SO_USERNAME, self.config.so.SO_PASSWORD), }, @@ -163,7 +158,7 @@ class ServiceInstantiationClient(SOClient): service_path=self.config.so.SO_SERVICE_INSTANCE_PATH, ), "uri-parameters": ["service_instance_id", "vnf_instance_id"], - "payload": "{}/so_delete_vnf.jinja".format(PAYLOADS_DIR), + "payload": "{}/so_delete_vnf.jinja".format(self.config.payload_directory), "payload-parameters": [ "vnf_invariant_id", "vnf_name", @@ -178,8 +173,50 @@ class ServiceInstantiationClient(SOClient): "headers": { "Accept": "application/json", "Content-Type": "application/json", - # "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, + }, + "auth": (self.config.so.SO_USERNAME, self.config.so.SO_PASSWORD), + }, + "CREATE_VOLUME_MODULE_INSTANCE": { + "verb": "POST", + "description": "Creates a VNF Volume Module Instance.", + "uri": partial( + "{endpoint}{service_path}/{service_instance_id}/vnfs/{vnf_instance_id}/volumeGroups".format, + endpoint=self.config.so.SO_ENDPOINT, + service_path=self.config.so.SO_SERVICE_INSTANCE_PATH, + ), + "uri-parameters": ["service_instance_id", "vnf_instance_id"], + "payload": "{}/so_create_volume_module.jinja".format(self.config.payload_directory), + "payload-parameters": [ + "volume_module_instance_name", + "model_invariant_id", + "model_version_id", + "model_name", + "model_version", + "model_customization_id", + "model_name", + "api_type", + "tenant_id", + "cloud_owner", + "cloud_region", + "service_instance_id", + "service_model_name", + "service_model_invariant_id", + "service_model_version", + "service_model_version_id", + "vnf_instance_id", + "vnf_model_name", + "vnf_model_invariant_id", + "vnf_model_version", + "vnf_model_version_id", + "vnf_model_customization_id", + ], + "header-parameters": ["X-TransactionId"], + "success_code": 202, + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "X-FromAppId": self.config.application_id, }, "auth": (self.config.so.SO_USERNAME, self.config.so.SO_PASSWORD), }, @@ -192,7 +229,7 @@ class ServiceInstantiationClient(SOClient): service_path=self.config.so.SO_SERVICE_INSTANCE_PATH, ), "uri-parameters": ["service_instance_id", "vnf_instance_id"], - "payload": "{}/so_create_module.jinja".format(PAYLOADS_DIR), + "payload": "{}/so_create_module.jinja".format(self.config.payload_directory), "payload-parameters": [ "module_instance_name", "model_invariant_id", @@ -222,8 +259,7 @@ class ServiceInstantiationClient(SOClient): "headers": { "Accept": "application/json", "Content-Type": "application/json", - # "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.so.SO_USERNAME, self.config.so.SO_PASSWORD), }, @@ -236,7 +272,7 @@ class ServiceInstantiationClient(SOClient): service_path=self.config.so.SO_SERVICE_INSTANCE_PATH, ), "uri-parameters": ["service_instance_id", "vnf_instance_id", "vf_module_id"], - "payload": "{}/so_delete_module.jinja".format(PAYLOADS_DIR), + "payload": "{}/so_delete_module.jinja".format(self.config.payload_directory), "payload-parameters": [ "module_invariant_id", "module_name", @@ -251,8 +287,35 @@ class ServiceInstantiationClient(SOClient): "headers": { "Accept": "application/json", "Content-Type": "application/json", - # "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, + }, + "auth": (self.config.so.SO_USERNAME, self.config.so.SO_PASSWORD), + }, + "DELETE_VOLUME_MODULE_INSTANCE": { + "verb": "DELETE", + "description": "Deletes a VNF Volume Module Instance.", + "uri": partial( + "{endpoint}{service_path}/{service_instance_id}/vnfs/{vnf_instance_id}/volumeGroups/{volume_module_id}".format, + endpoint=self.config.so.SO_ENDPOINT, + service_path=self.config.so.SO_SERVICE_INSTANCE_PATH, + ), + "uri-parameters": ["service_instance_id", "vnf_instance_id", "volume_module_id"], + "payload": "{}/so_delete_volume_module.jinja".format(self.config.payload_directory), + "payload-parameters": [ + "module_invariant_id", + "module_name", + "module_version", + "cloud_region", + "cloud_owner", + "tenant_id", + "api_type", + ], + "header-parameters": ["X-TransactionId"], + "success_code": 202, + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "X-FromAppId": self.config.application_id, }, "auth": (self.config.so.SO_USERNAME, self.config.so.SO_PASSWORD), }, @@ -270,7 +333,7 @@ class ServiceInstantiationClient(SOClient): "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.so.SO_USERNAME, self.config.so.SO_PASSWORD), }, @@ -287,7 +350,7 @@ class ServiceInstantiationClient(SOClient): "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.so.SO_USERNAME, self.config.so.SO_PASSWORD), }, @@ -304,7 +367,24 @@ class ServiceInstantiationClient(SOClient): "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, + }, + "auth": (self.config.so.SO_USERNAME, self.config.so.SO_PASSWORD), + }, + "GET_MODULE_CUSTOMIZATION": { + "verb": "GET", + "description": "Searches the SO catalog for module customization object.", + "uri": partial( + "{endpoint}vfModuleCustomization/search/findFirstByModelCustomizationUUIDOrderByCreatedDesc?MODEL_CUSTOMIZATION_UUID={module_customization_id}".format, + endpoint=self.config.so.SO_ENDPOINT, + ), + "uri-parameters": ["module_customization_id"], + "success_code": 200, + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "X-TransactionId": str(uuid.uuid4()), + "X-FromAppId": self.config.application_id, }, "auth": (self.config.so.SO_USERNAME, self.config.so.SO_PASSWORD), }, diff --git a/onap-client/onap_client/so/client.py b/onap-client/onap_client/so/client.py index 7e79fe1..3fa48ec 100644 --- a/onap-client/onap_client/so/client.py +++ b/onap-client/onap_client/so/client.py @@ -34,12 +34,8 @@ # limitations under the License. # # ============LICENSE_END============================================ - from functools import partial from onap_client.client.clients import Client -from onap_client import config - -application_id = config.APPLICATION_ID class SOClient(Client): diff --git a/onap-client/onap_client/so/module_instance.py b/onap-client/onap_client/so/module_instance.py index 67da272..59aba64 100644 --- a/onap-client/onap_client/so/module_instance.py +++ b/onap-client/onap_client/so/module_instance.py @@ -34,11 +34,13 @@ # limitations under the License. # # ============LICENSE_END============================================ - import uuid from onap_client.resource import Resource from onap_client.client.clients import get_client as Client -from onap_client.exceptions import ServiceInstanceNotFound, VNFInstanceNotFound, ModuleInstanceNotFound +from onap_client.exceptions import ( + ModuleModelNameNotFound, + NoArtifactFoundInModel, +) from onap_client import so from onap_client import sdnc from onap_client.util import utility @@ -57,25 +59,21 @@ class ModuleInstance(Resource): "cloud_owner": {"type": str, "required": True}, "cloud_region": {"type": str, "required": True}, "api_type": {"type": str, "required": False, "default": "GR_API"}, + "volume_group_name": {"type": str, "required": False}, } def _create(self, instance_input): tenant_id = so.service_instance.get_tenant_id( instance_input.get("cloud_region"), instance_input.get("cloud_owner"), - instance_input.get("tenant_name") + instance_input.get("tenant_name"), + oc=self.oc ) instance_input["tenant_id"] = tenant_id - service_instance = so.vnf_instance.get_service_instance( - instance_input.get("service_instance_name") + service_instance = so.service_instance.get_service_instance( + instance_input.get("service_instance_name"), oc=self.oc ) - if not service_instance: - raise ServiceInstanceNotFound( - "No service instance found for {}".format( - instance_input.get("service_instance_name") - ) - ) service_instance_id = service_instance.get("service-instance-id") model_information = ( service_instance.get("service-data") @@ -87,15 +85,10 @@ class ModuleInstance(Resource): service_model_version = model_information["model-version"] service_model_name = model_information["model-name"] - vnf_instance = so.vnf_instance.get_vnf_instance( + vnf_instance = so.service_instance.get_vnf_instance( service_instance, instance_input.get("vnf_instance_name") ) - if not vnf_instance: - raise VNFInstanceNotFound( - "No vnf instance found for {}".format( - instance_input.get("vnf_instance_name") - ) - ) + vnf_model_information = vnf_instance.get("vnf-data").get("vnf-information") vnf_instance_id = vnf_model_information.get("vnf-id") vnf_model_name = vnf_model_information.get("onap-model-information").get( @@ -115,10 +108,10 @@ class ModuleInstance(Resource): ) vnf_model = so.vnf_instance.get_vnf_model_component( - service_model_name, vnf_model_name + service_model_name, vnf_model_name, oc=self.oc ) - module_model = so.vnf_instance.get_module_model( + module_model = get_module_model( vnf_model, instance_input.get("heat_template_name") ) model_invariant_id = module_model.get("invariantUUID") @@ -127,6 +120,8 @@ class ModuleInstance(Resource): model_name = module_model.get("groupName") model_version = module_model.get("version") + volume_group = module_uses_volume_group(module_model) and instance_input.get("volume_group_name") + instance_input["model_invariant_id"] = model_invariant_id instance_input["model_version_id"] = model_version_id instance_input["model_name"] = model_name @@ -144,11 +139,38 @@ class ModuleInstance(Resource): instance_input["vnf_model_version"] = vnf_model_version instance_input["vnf_model_customization_id"] = vnf_model_customization_id - return create_module_instance(instance_input) + return create_module_instance(instance_input, volume_group=volume_group, oc=self.oc) + + def _delete(self, instance_input): + if instance_input.get("volume_group_name"): + request = delete_volume_module_instance( + instance_input.get("service_instance_name"), + instance_input.get("vnf_instance_name"), + instance_input.get("volume_group_name"), + instance_input.get("api_type"), + oc=self.oc, + ) + request_id = request.get("requestReferences", {}).get( + "requestId" + ) + so.service_instance.poll_request(request_id, oc=self.oc) + + request = delete_module_instance( + instance_input.get("service_instance_name"), + instance_input.get("vnf_instance_name"), + instance_input.get("module_instance_name"), + instance_input.get("api_type"), + oc=self.oc, + ) + request_id = request.get("requestReferences", {}).get( + "requestId" + ) + so.service_instance.poll_request(request_id, oc=self.oc) -def create_module_instance(instance_input): - oc = Client() +def create_module_instance(instance_input, volume_group=False, oc=None): + if not oc: + oc = Client() preload = sdnc.preload.Preload( preload_path=instance_input.get("preload_path"), @@ -156,11 +178,24 @@ def create_module_instance(instance_input): service_instance_name=instance_input.get("service_instance_name"), module_instance_name=instance_input.get("module_instance_name"), heat_template_name=instance_input.get("heat_template_name"), - api_type=instance_input.get("api_type") + api_type=instance_input.get("api_type"), + oc=oc ) preload.create() headers = {"X-TransactionId": str(uuid.uuid4())} + + if volume_group: + volume_instance = oc.so.service_instantiation.create_volume_module_instance( + volume_module_instance_name=instance_input.get("volume_group_name"), + **instance_input, + **headers + ) + request_id = volume_instance.response_data.get("requestReferences", {}).get( + "requestId" + ) + so.service_instance.poll_request(request_id, oc=oc) + module_instance = oc.so.service_instantiation.create_module_instance( **instance_input, **headers ) @@ -169,41 +204,143 @@ def create_module_instance(instance_input): "requestId" ) - instance_input["request_info"] = so.service_instance.poll_request(request_id) + instance_input["request_info"] = so.service_instance.poll_request(request_id, oc=oc) return instance_input @utility -def delete_module_instance(service_instance_name, vnf_instance_name, module_instance_name, api_type="GR_API"): +def delete_module_instance(service_instance_name, vnf_instance_name, module_instance_name, api_type="GR_API", oc=None): + """Delete a Module Instance from SO""" + if not oc: + oc = Client() + + si = so.service_instance.get_service_instance(service_instance_name, oc=oc) + vnfi = so.service_instance.get_vnf_instance(si, vnf_instance_name) + modulei = so.service_instance.get_module_instance(vnfi, module_instance_name) + + si_id = si.get("service-instance-id") + vnfi_id = vnfi.get("vnf-id") + module_id = modulei.get("vf-module-id") + module_invariant_id = modulei.get("vf-module-data").get("vf-module-topology").get("onap-model-information").get("model-invariant-uuid") + module_version = modulei.get("vf-module-data").get("vf-module-topology").get("onap-model-information").get("model-version") + module_name = modulei.get("vf-module-data").get("vf-module-topology").get("onap-model-information").get("model-name") + tenant_id = modulei.get("vf-module-data").get("vf-module-request-input").get("tenant") + cloud_owner = modulei.get("vf-module-data").get("vf-module-request-input").get("cloud-owner") + cloud_region = modulei.get("vf-module-data").get("vf-module-request-input").get("aic-cloud-region") + + return oc.so.service_instantiation.delete_module_instance( + module_invariant_id=module_invariant_id, + module_name=module_name, + module_version=module_version, + cloud_region=cloud_region, + cloud_owner=cloud_owner, + tenant_id=tenant_id, + vnf_instance_id=vnfi_id, + service_instance_id=si_id, + vf_module_id=module_id, + api_type=api_type + ).response_data + + +@utility +def delete_volume_module_instance(service_instance_name, vnf_instance_name, volume_module_name, api_type="GR_API", oc=None): """Delete a Module Instance from SO""" - oc = Client() + if not oc: + oc = Client() + + si = so.service_instance.get_service_instance(service_instance_name, oc=oc) + vnfi = so.service_instance.get_vnf_instance(si, vnf_instance_name) + + vnf_model_information = vnfi.get("vnf-data").get("vnf-information") + service_model_information = ( + si.get("service-data") + .get("service-information") + .get("onap-model-information") + ) + service_model_name = service_model_information["model-name"] + vnf_model_name = vnf_model_information.get("onap-model-information").get( + "model-name" + ) - si = so.service_instance.get_service_instance(service_instance_name) si_id = si.get("service-instance-id") - for vnfi in si.get("service-data", {}).get("vnfs", {}).get("vnf", []): - vnfi_id = vnfi.get("vnf-id") - if vnfi.get("vnf-data", {}).get("vnf-request-input", {}).get("vnf-name") == vnf_instance_name: - for modulei in vnfi.get("vnf-data").get("vf-modules", {}).get("vf-module", []): - if modulei.get("vf-module-data", {}).get("vf-module-request-input", {}).get("vf-module-name") == module_instance_name: - module_id = modulei.get("vf-module-id") - module_invariant_id = modulei.get("vf-module-data").get("vf-module-topology").get("onap-model-information").get("model-invariant-uuid") - module_version = modulei.get("vf-module-data").get("vf-module-topology").get("onap-model-information").get("model-version") - module_name = modulei.get("vf-module-data").get("vf-module-topology").get("onap-model-information").get("model-name") - tenant_id = modulei.get("vf-module-data").get("vf-module-request-input").get("tenant") - cloud_owner = modulei.get("vf-module-data").get("vf-module-request-input").get("cloud-owner") - cloud_region = modulei.get("vf-module-data").get("vf-module-request-input").get("aic-cloud-region") - return oc.so.service_instantiation.delete_module_instance( - module_invariant_id=module_invariant_id, - module_name=module_name, - module_version=module_version, - cloud_region=cloud_region, - cloud_owner=cloud_owner, - tenant_id=tenant_id, - vnf_instance_id=vnfi_id, - service_instance_id=si_id, - vf_module_id=module_id, - api_type=api_type - ).response_data - - raise ModuleInstanceNotFound("Module Instance was not found: {} {} {}".format(service_instance_name, vnf_instance_name, module_instance_name)) + vnfi_id = vnfi.get("vnf-id") + + tenant_id = vnfi.get("vnf-data").get("vnf-request-input").get("tenant") + cloud_owner = vnfi.get("vnf-data").get("vnf-request-input").get("cloud-owner") + cloud_region = vnfi.get("vnf-data").get("vnf-request-input").get("aic-cloud-region") + + volume_group_instance = get_volume_group_instance(volume_module_name, cloud_owner, cloud_region, oc=oc) + volume_customization_id = volume_group_instance.get("model-customization-id") + vnf_component = so.vnf_instance.get_vnf_model_component( + service_model_name, vnf_model_name, oc=oc + ) + volume_group_component = get_volume_group_from_vnf_model(vnf_component, volume_customization_id) + + return oc.so.service_instantiation.delete_volume_module_instance( + volume_module_id=volume_group_instance.get("volume-group-id"), + module_invariant_id=volume_group_component.get("invariantUUID"), + module_name=volume_group_component.get("groupName"), + module_version=volume_group_component.get("version"), + cloud_region=cloud_region, + cloud_owner=cloud_owner, + tenant_id=tenant_id, + vnf_instance_id=vnfi_id, + service_instance_id=si_id, + api_type=api_type + ).response_data + + +def module_uses_volume_group(module_model): + for prop in module_model.get("properties"): + if prop.get("name", "") == "volume_group" and prop.get("value") == "true": + return True + return False + + +def get_volume_group_instance(volume_group_name, cloud_owner, cloud_region, oc=None): + if not oc: + oc = Client() + + volume_group_list = oc.aai.cloud_infrastructure.get_volume_groups( + cloud_owner=cloud_owner, + cloud_region=cloud_region + ).response_data + + for volume_group in volume_group_list.get("volume-group", []): + if volume_group.get("volume-group-name") == volume_group_name: + return volume_group + + return {} + + +def get_volume_group_from_vnf_model(vnf_component, volume_group_customization_id): + for group_instance in vnf_component.get("groupInstances", []): + if group_instance.get("customizationUUID") == volume_group_customization_id: + return group_instance + return {} + + +def get_module_model(vnf_model, heat_template_name): + artifact_uuid = None + deployment_artifacts = vnf_model.get("deploymentArtifacts", {}) + for artifact_name, artifact_data in deployment_artifacts.items(): + if artifact_data.get("artifactName") == heat_template_name: + artifact_uuid = artifact_data.get("artifactUUID") + + if not artifact_uuid: + raise NoArtifactFoundInModel( + "Heat Template {} was not found in service model".format(heat_template_name) + ) + + group_instances = vnf_model.get("groupInstances", []) + for instance in group_instances: + if artifact_uuid in instance.get("artifactsUuid", []): + # return instance.get("groupName") + return instance + + raise ModuleModelNameNotFound( + "Module Model Name for {} was not found in service model".format( + heat_template_name + ) + ) diff --git a/onap-client/onap_client/so/service_instance.py b/onap-client/onap_client/so/service_instance.py index 3675a4e..5441d84 100644 --- a/onap-client/onap_client/so/service_instance.py +++ b/onap-client/onap_client/so/service_instance.py @@ -46,6 +46,8 @@ from onap_client.exceptions import ( SORequestTimeout, TenantNotFound, ServiceInstanceNotFound, + VNFInstanceNotFound, + ModuleInstanceNotFound, ) from onap_client import sdc from onap_client.util import utility @@ -77,14 +79,16 @@ class ServiceInstance(Resource): tenant_id = get_tenant_id( instance_input.get("cloud_region"), instance_input.get("cloud_owner"), - instance_input.get("tenant_name") + instance_input.get("tenant_name"), + oc=self.oc ) instance_input["tenant_id"] = tenant_id instance_input["customer_id"] = instance_input.get("customer_name") service_model = self.oc.sdc.service.get_sdc_service( catalog_service_id=sdc.service.get_service_id( - instance_input.get("model_name") + instance_input.get("model_name"), + oc=self.oc ) ).response_data @@ -97,25 +101,23 @@ class ServiceInstance(Resource): instance_input["owning_entity_id"] = entity.get("id") break - return create_service_instance(instance_input) + return create_service_instance(instance_input, oc=self.oc) - -@utility -def get_service_instance(instance_name): - """Queries SDNC for a list of all service instances and returns - The service instance that matches <instance name>""" - oc = Client() - - service_instances = oc.sdnc.config.get_service_instances().response_data - for si in service_instances.get("services", {}).get("service", []): - if si.get("service-data", {}).get("service-request-input", {}).get("service-instance-name") == instance_name: - return si - - raise ServiceInstanceNotFound("Service Instance {} was not found".format(instance_name)) + def _delete(self, instance_input): + request = delete_service_instance( + instance_input.get("service_instance_name"), + instance_input.get("api_type"), + oc=self.oc + ) + request_id = request.get("requestReferences", {}).get( + "requestId" + ) + poll_request(request_id, oc=self.oc) -def get_tenant_id(cloud_region, cloud_owner, tenant_name): - oc = Client() +def get_tenant_id(cloud_region, cloud_owner, tenant_name, oc=None): + if not oc: + oc = Client() tenants = oc.aai.cloud_infrastructure.get_cloud_region_tenants( cloud_owner=cloud_owner, @@ -129,8 +131,9 @@ def get_tenant_id(cloud_region, cloud_owner, tenant_name): raise TenantNotFound("Tenant {} was not found in AAI".format(tenant_name)) -def create_service_instance(instance_input): - oc = Client() +def create_service_instance(instance_input, oc=None): + if not oc: + oc = Client() headers = {"X-TransactionId": str(uuid.uuid4())} service_instance = oc.so.service_instantiation.create_service_instance( @@ -141,15 +144,16 @@ def create_service_instance(instance_input): "requestId" ) - instance_input["request_info"] = poll_request(request_id) + instance_input["request_info"] = poll_request(request_id, oc=oc) return instance_input @utility -def poll_request(request_id): +def poll_request(request_id, oc=None): """Poll an SO request until completion""" - oc = Client() + if not oc: + oc = Client() poll_interval = oc.config.so.POLL_INTERVAL or 30 request = None @@ -181,11 +185,12 @@ def poll_request(request_id): @utility -def delete_service_instance(service_instance_name, api_type="GR_API"): +def delete_service_instance(service_instance_name, api_type="GR_API", oc=None): """Delete a Service Instance from SO""" - oc = Client() + if not oc: + oc = Client() - si = get_service_instance(service_instance_name) + si = get_service_instance(service_instance_name, oc=oc) si_id = si.get("service-instance-id") invariant_id = si.get("service-data").get("service-information").get("onap-model-information").get("model-invariant-uuid") version = si.get("service-data").get("service-information").get("onap-model-information").get("model-version") @@ -197,3 +202,35 @@ def delete_service_instance(service_instance_name, api_type="GR_API"): service_instance_id=si_id, api_type=api_type, ).response_data + + +@utility +def get_service_instance(instance_name, oc=None): + """Queries SDNC for a list of all service instances and returns + The service instance that matches <instance name>""" + if not oc: + oc = Client() + + service_instances = oc.sdnc.configuration.get_service_instances().response_data + for si in service_instances.get("services", {}).get("service", []): + if si.get("service-data", {}).get("service-request-input", {}).get("service-instance-name") == instance_name: + return si + + raise ServiceInstanceNotFound("Service Instance {} was not found".format(instance_name)) + + +def get_vnf_instance(service_instance_dict, vnf_instance_name): + for vnfi in service_instance_dict.get("service-data", {}).get("vnfs", {}).get("vnf", []): + if vnfi.get("vnf-data", {}).get("vnf-request-input", {}).get("vnf-name") == vnf_instance_name: + return vnfi + + raise VNFInstanceNotFound("VNF Instance was not found: {}".format(vnf_instance_name)) + + +def get_module_instance(vnf_instance_dict, module_instance_name): + for modulei in vnf_instance_dict.get("vnf-data").get("vf-modules", {}).get("vf-module", []): + if modulei.get("vf-module-data", {}).get("vf-module-request-input", {}).get("vf-module-name") == module_instance_name: + return modulei + + raise ModuleInstanceNotFound("Module Instance was not found: {}".format(module_instance_name)) + diff --git a/onap-client/onap_client/so/tests/test_module_instance.py b/onap-client/onap_client/so/tests/test_module_instance.py index e102702..0e8c655 100644 --- a/onap-client/onap_client/so/tests/test_module_instance.py +++ b/onap-client/onap_client/so/tests/test_module_instance.py @@ -130,7 +130,8 @@ def test_module_instance(): "groupUUID": MODULE_MODEL_VERSION_ID, "customizationUUID": MODULE_MODEL_CUSTOMIZATION_ID, "groupName": MODULE_MODEL_NAME, - "version": MODULE_MODEL_VERSION + "version": MODULE_MODEL_VERSION, + "properties": [] } ] } @@ -148,7 +149,7 @@ def test_module_instance(): oc.sdnc.operations.catalog_items["GR_API_PRELOAD"], ) mockup_catalog_item( - oc.sdnc.config.catalog_items["GET_SERVICE_INSTANCES"], + oc.sdnc.configuration.catalog_items["GET_SERVICE_INSTANCES"], override_return_data={ "services": { "service": [ @@ -179,6 +180,12 @@ def test_module_instance(): "model-customization-uuid": VNF_CUSTOMIZATION_UUID, "model-version": "1.0" } + }, + "vnf-request-input": { + "vnf-name": VNF_INSTANCE_NAME, + "tenant": TENANT_ID, + "cloud-owner": CLOUD_OWNER, + "aic-cloud-region": CLOUD_REGION } } } diff --git a/onap-client/onap_client/so/tests/test_vnf_instance.py b/onap-client/onap_client/so/tests/test_vnf_instance.py index cecdb39..88334b0 100644 --- a/onap-client/onap_client/so/tests/test_vnf_instance.py +++ b/onap-client/onap_client/so/tests/test_vnf_instance.py @@ -114,7 +114,7 @@ def test_vnf_instance(): override_uri_params={"catalog_resource_id": VNF_ACTUAL_UUID}, ) mockup_catalog_item( - oc.sdnc.config.catalog_items["GET_SERVICE_INSTANCES"], + oc.sdnc.configuration.catalog_items["GET_SERVICE_INSTANCES"], override_return_data={ "services": { "service": [ diff --git a/onap-client/onap_client/so/vnf_instance.py b/onap-client/onap_client/so/vnf_instance.py index 0dbd87f..32fcda7 100644 --- a/onap-client/onap_client/so/vnf_instance.py +++ b/onap-client/onap_client/so/vnf_instance.py @@ -40,13 +40,7 @@ import uuid from onap_client.lib import generate_dummy_string from onap_client.resource import Resource from onap_client.client.clients import get_client as Client -from onap_client.exceptions import ( - ServiceInstanceNotFound, - VNFComponentNotFound, - ModuleModelNameNotFound, - NoArtifactFoundInModel, - VNFInstanceNotFound, -) +from onap_client.exceptions import VNFComponentNotFound from onap_client import sdc from onap_client import so from onap_client.util import utility @@ -75,19 +69,15 @@ class VNFInstance(Resource): tenant_id = so.service_instance.get_tenant_id( instance_input.get("cloud_region"), instance_input.get("cloud_owner"), - instance_input.get("tenant_name") + instance_input.get("tenant_name"), + oc=self.oc ) instance_input["tenant_id"] = tenant_id - service_instance = get_service_instance( - instance_input.get("service_instance_name") + service_instance = so.service_instance.get_service_instance( + instance_input.get("service_instance_name"), + oc=self.oc ) - if not service_instance: - raise ServiceInstanceNotFound( - "No service instance found for {}".format( - instance_input.get("service_instance_name") - ) - ) service_instance_id = service_instance.get("service-instance-id") model_information = ( service_instance.get("service-data") @@ -100,7 +90,7 @@ class VNFInstance(Resource): service_model_name = model_information["model-name"] vnf_component = get_vnf_model_component( - service_model_name, instance_input.get("model_name") + service_model_name, instance_input.get("model_name"), oc=self.oc ) if not vnf_component: raise VNFComponentNotFound( @@ -125,13 +115,27 @@ class VNFInstance(Resource): instance_input["service_model_version_id"] = service_model_id instance_input["service_instance_id"] = service_instance_id - return create_vnf_instance(instance_input) + return create_vnf_instance(instance_input, oc=self.oc) + + def _delete(self, instance_input): + request = delete_vnf_instance( + instance_input.get("service_instance_name"), + instance_input.get("vnf_instance_name"), + instance_input.get("api_type"), + oc=self.oc + ) + request_id = request.get("requestReferences", {}).get( + "requestId" + ) + so.service_instance.poll_request(request_id, oc=self.oc) + +def get_vnf_model_component(service_model_name, vnf_model_name, oc=None): + if not oc: + oc = Client() -def get_vnf_model_component(service_model_name, vnf_model_name): - oc = Client() service_model = oc.sdc.service.get_sdc_service( - catalog_service_id=sdc.service.get_service_id(service_model_name) + catalog_service_id=sdc.service.get_service_id(service_model_name, oc=oc) ).response_data for component in service_model.get("componentInstances", []): @@ -140,59 +144,9 @@ def get_vnf_model_component(service_model_name, vnf_model_name): return None -def get_service_instance(service_instance_name): - oc = Client() - service_instances = oc.sdnc.config.get_service_instances().response_data - for si in service_instances.get("services", {}).get("service", []): - si_name = ( - si.get("service-data", {}) - .get("service-request-input", {}) - .get("service-instance-name") - ) - if si_name == service_instance_name: - return si - return None - - -def get_module_model(vnf_model, heat_template_name): - artifact_uuid = None - deployment_artifacts = vnf_model.get("deploymentArtifacts", {}) - for artifact_name, artifact_data in deployment_artifacts.items(): - if artifact_data.get("artifactName") == heat_template_name: - artifact_uuid = artifact_data.get("artifactUUID") - - if not artifact_uuid: - raise NoArtifactFoundInModel( - "Heat Template {} was not found in service model".format(heat_template_name) - ) - - group_instances = vnf_model.get("groupInstances", []) - for instance in group_instances: - if artifact_uuid in instance.get("artifactsUuid", []): - # return instance.get("groupName") - return instance - - raise ModuleModelNameNotFound( - "Module Model Name for {} was not found in service model".format( - heat_template_name - ) - ) - - -def get_vnf_instance(service_instance, vnf_instance_name): - for vnf_instance in ( - service_instance.get("service-data", {}).get("vnfs", {}).get("vnf", []) - ): - vi_name = ( - vnf_instance.get("vnf-data", {}).get("vnf-information", {}).get("vnf-name") - ) - if vi_name == vnf_instance_name: - return vnf_instance - return None - - -def create_vnf_instance(instance_input): - oc = Client() +def create_vnf_instance(instance_input, oc=None): + if not oc: + oc = Client() headers = {"X-TransactionId": str(uuid.uuid4())} vnf_instance = oc.so.service_instantiation.create_vnf_instance( @@ -203,35 +157,36 @@ def create_vnf_instance(instance_input): "requestId" ) - instance_input["request_info"] = so.service_instance.poll_request(request_id) + instance_input["request_info"] = so.service_instance.poll_request(request_id, oc=oc) return instance_input @utility -def delete_vnf_instance(service_instance_name, vnf_instance_name, api_type="GR_API"): +def delete_vnf_instance(service_instance_name, vnf_instance_name, api_type="GR_API", oc=None): """Delete a VNF Instance from SO""" - oc = Client() - si = so.service_instance.get_service_instance(service_instance_name) + if not oc: + oc = Client() + + si = so.service_instance.get_service_instance(service_instance_name, oc=oc) + vnfi = so.service_instance.get_vnf_instance(si, vnf_instance_name) + si_id = si.get("service-instance-id") - for vnfi in si.get("service-data", {}).get("vnfs", {}).get("vnf", []): - vnfi_id = vnfi.get("vnf-id") - if vnfi.get("vnf-data", {}).get("vnf-request-input", {}).get("vnf-name") == vnf_instance_name: - invariant_id = vnfi.get("vnf-data").get("vnf-information").get("onap-model-information").get("model-invariant-uuid") - vnf_version = vnfi.get("vnf-data").get("vnf-information").get("onap-model-information").get("model-version") - tenant_id = vnfi.get("vnf-data").get("vnf-request-input").get("tenant") - cloud_owner = vnfi.get("vnf-data").get("vnf-request-input").get("cloud-owner") - cloud_region = vnfi.get("vnf-data").get("vnf-request-input").get("aic-cloud-region") - return oc.so.service_instantiation.delete_vnf_instance( - vnf_invariant_id=invariant_id, - vnf_version=vnf_version, - vnf_name=vnf_instance_name, - cloud_region=cloud_region, - cloud_owner=cloud_owner, - tenant_id=tenant_id, - vnf_instance_id=vnfi_id, - service_instance_id=si_id, - api_type=api_type, - ).response_data - - raise VNFInstanceNotFound("VNF Instance was not found: {} {}".format(service_instance_name, vnf_instance_name)) + vnfi_id = vnfi.get("vnf-id") + invariant_id = vnfi.get("vnf-data").get("vnf-information").get("onap-model-information").get("model-invariant-uuid") + vnf_version = vnfi.get("vnf-data").get("vnf-information").get("onap-model-information").get("model-version") + tenant_id = vnfi.get("vnf-data").get("vnf-request-input").get("tenant") + cloud_owner = vnfi.get("vnf-data").get("vnf-request-input").get("cloud-owner") + cloud_region = vnfi.get("vnf-data").get("vnf-request-input").get("aic-cloud-region") + + return oc.so.service_instantiation.delete_vnf_instance( + vnf_invariant_id=invariant_id, + vnf_version=vnf_version, + vnf_name=vnf_instance_name, + cloud_region=cloud_region, + cloud_owner=cloud_owner, + tenant_id=tenant_id, + vnf_instance_id=vnfi_id, + service_instance_id=si_id, + api_type=api_type, + ).response_data diff --git a/onap-client/onap_client/vid/catalog/maintenance_catalog.py b/onap-client/onap_client/vid/catalog/maintenance_catalog.py index 1c7bad0..32f12ea 100644 --- a/onap-client/onap_client/vid/catalog/maintenance_catalog.py +++ b/onap-client/onap_client/vid/catalog/maintenance_catalog.py @@ -34,16 +34,11 @@ # limitations under the License. # # ============LICENSE_END============================================ - import uuid from functools import partial -from onap_client import config from onap_client.vid.client import VIDClient -PAYLOADS_DIR = config.PAYLOADS_DIR -application_id = config.APPLICATION_ID - class MaintenanceClient(VIDClient): @property @@ -62,13 +57,13 @@ class MaintenanceClient(VIDClient): service_path=self.config.vid.VID_MAINTENANCE_PATH, ), "payload-parameters": ["name"], - "payload": "{}/vid_maintenance.jinja".format(PAYLOADS_DIR), + "payload": "{}/vid_maintenance.jinja".format(self.config.payload_directory), "success_code": 200, "headers": { "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.vid.VID_USERNAME, self.config.vid.VID_PASSWORD,), }, @@ -81,13 +76,13 @@ class MaintenanceClient(VIDClient): service_path=self.config.vid.VID_MAINTENANCE_PATH, ), "payload-parameters": ["name"], - "payload": "{}/vid_maintenance.jinja".format(PAYLOADS_DIR), + "payload": "{}/vid_maintenance.jinja".format(self.config.payload_directory), "success_code": 200, "headers": { "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.vid.VID_USERNAME, self.config.vid.VID_PASSWORD,), }, @@ -100,13 +95,13 @@ class MaintenanceClient(VIDClient): service_path=self.config.vid.VID_MAINTENANCE_PATH, ), "payload-parameters": ["name"], - "payload": "{}/vid_maintenance.jinja".format(PAYLOADS_DIR), + "payload": "{}/vid_maintenance.jinja".format(self.config.payload_directory), "success_code": 200, "headers": { "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.vid.VID_USERNAME, self.config.vid.VID_PASSWORD,), }, @@ -119,13 +114,13 @@ class MaintenanceClient(VIDClient): service_path=self.config.vid.VID_MAINTENANCE_PATH, ), "payload-parameters": ["name"], - "payload": "{}/vid_maintenance.jinja".format(PAYLOADS_DIR), + "payload": "{}/vid_maintenance.jinja".format(self.config.payload_directory), "success_code": 200, "headers": { "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.vid.VID_USERNAME, self.config.vid.VID_PASSWORD,), }, @@ -142,7 +137,7 @@ class MaintenanceClient(VIDClient): "Accept": "application/json", "Content-Type": "application/json", "X-TransactionId": str(uuid.uuid4()), - "X-FromAppId": application_id, + "X-FromAppId": self.config.application_id, }, "auth": (self.config.vid.VID_USERNAME, self.config.vid.VID_PASSWORD,), }, diff --git a/onap-client/onap_client/vid/client.py b/onap-client/onap_client/vid/client.py index d3d4468..109f5b3 100644 --- a/onap-client/onap_client/vid/client.py +++ b/onap-client/onap_client/vid/client.py @@ -34,12 +34,8 @@ # limitations under the License. # # ============LICENSE_END============================================ - from functools import partial from onap_client.client.clients import Client -from onap_client import config - -application_id = config.APPLICATION_ID class VIDClient(Client): |