From c02d3ed39e53d4ce56406a43089fc4a336c43f17 Mon Sep 17 00:00:00 2001 From: "stark, steven" Date: Wed, 11 Mar 2020 14:30:58 -0700 Subject: [VVP] Adding onap-client intial commit. This is supplementary tooling to interact with various ONAP applications. It will be used by the OVP VNF Testcase, it's not deployed with the ONAP platform. Issue-ID: VVP-381 Change-Id: I2ff3952ba8f4b9448acb5a24717ccc3b1f0a92fe Signed-off-by: stark, steven --- onap-client/onap_client/sdnc/__init__.py | 40 +++++ onap-client/onap_client/sdnc/catalog/__init__.py | 36 ++++ .../onap_client/sdnc/catalog/config_catalog.py | 114 ++++++++++++ .../onap_client/sdnc/catalog/operations_catalog.py | 97 +++++++++++ onap-client/onap_client/sdnc/client.py | 53 ++++++ onap-client/onap_client/sdnc/preload.py | 191 +++++++++++++++++++++ onap-client/onap_client/sdnc/tests/__init__.py | 36 ++++ 7 files changed, 567 insertions(+) create mode 100644 onap-client/onap_client/sdnc/__init__.py create mode 100644 onap-client/onap_client/sdnc/catalog/__init__.py create mode 100644 onap-client/onap_client/sdnc/catalog/config_catalog.py create mode 100644 onap-client/onap_client/sdnc/catalog/operations_catalog.py create mode 100644 onap-client/onap_client/sdnc/client.py create mode 100644 onap-client/onap_client/sdnc/preload.py create mode 100644 onap-client/onap_client/sdnc/tests/__init__.py (limited to 'onap-client/onap_client/sdnc') diff --git a/onap-client/onap_client/sdnc/__init__.py b/onap-client/onap_client/sdnc/__init__.py new file mode 100644 index 0000000..eb3184f --- /dev/null +++ b/onap-client/onap_client/sdnc/__init__.py @@ -0,0 +1,40 @@ +# -*- 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============================================ + +from onap_client.config import APP_CONFIG + +SDNC_PROPERTIES = APP_CONFIG.sdnc diff --git a/onap-client/onap_client/sdnc/catalog/__init__.py b/onap-client/onap_client/sdnc/catalog/__init__.py new file mode 100644 index 0000000..5519a84 --- /dev/null +++ b/onap-client/onap_client/sdnc/catalog/__init__.py @@ -0,0 +1,36 @@ +# -*- 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============================================ diff --git a/onap-client/onap_client/sdnc/catalog/config_catalog.py b/onap-client/onap_client/sdnc/catalog/config_catalog.py new file mode 100644 index 0000000..da3c1cf --- /dev/null +++ b/onap-client/onap_client/sdnc/catalog/config_catalog.py @@ -0,0 +1,114 @@ +# -*- 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============================================ + +import uuid +from functools import partial + +from onap_client import sdnc +from onap_client import config +from onap_client.sdnc.client import SDNCClient + +PAYLOADS_DIR = config.PAYLOADS_DIR +sdnc_properties = sdnc.SDNC_PROPERTIES +application_id = config.APPLICATION_ID + + +class ConfigClient(SDNCClient): + @property + def catalog_resources(self): + return CATALOG_RESOURCES + + @property + def namespace(self): + return "config" + + +CATALOG_RESOURCES = { + "GET_SERVICE_INSTANCES": { + "verb": "GET", + "description": "Get a list of all service instances", + "uri": partial( + "{endpoint}{service_path}/GENERIC-RESOURCE-API:services".format, + endpoint=sdnc_properties.SDNC_ENDPOINT, + service_path=sdnc_properties.SDNC_CONFIG_PATH, + ), + "success_code": 200, + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "X-TransactionId": str(uuid.uuid4()), + "X-FromAppId": application_id, + }, + "auth": (sdnc_properties.SDNC_USERNAME, sdnc_properties.SDNC_PASSWORD,), + }, + "GET_SERVICE_INSTANCE": { + "verb": "GET", + "description": "Get details for a service instance", + "uri": partial( + "{endpoint}{service_path}/GENERIC-RESOURCE-API:services/service/{service_instance_id}".format, + endpoint=sdnc_properties.SDNC_ENDPOINT, + service_path=sdnc_properties.SDNC_CONFIG_PATH, + ), + "uri-parameters": ["service_instance_id"], + "success_code": 200, + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "X-TransactionId": str(uuid.uuid4()), + "X-FromAppId": application_id, + }, + "auth": (sdnc_properties.SDNC_USERNAME, sdnc_properties.SDNC_PASSWORD,), + }, + "GET_VNF_INSTANCE": { + "verb": "GET", + "description": "Get details for a vnf instance", + "uri": partial( + "{endpoint}{service_path}/GENERIC-RESOURCE-API:services/service/{service_instance_id}/service-data/vnfs/vnf/{vnf_instance_id}".format, + endpoint=sdnc_properties.SDNC_ENDPOINT, + service_path=sdnc_properties.SDNC_CONFIG_PATH, + ), + "uri-parameters": ["service_instance_id", "vnf_instance_id"], + "success_code": 200, + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "X-TransactionId": str(uuid.uuid4()), + "X-FromAppId": application_id, + }, + "auth": (sdnc_properties.SDNC_USERNAME, sdnc_properties.SDNC_PASSWORD,), + }, +} diff --git a/onap-client/onap_client/sdnc/catalog/operations_catalog.py b/onap-client/onap_client/sdnc/catalog/operations_catalog.py new file mode 100644 index 0000000..12db3a3 --- /dev/null +++ b/onap-client/onap_client/sdnc/catalog/operations_catalog.py @@ -0,0 +1,97 @@ +# -*- 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============================================ + +import uuid +from functools import partial + +from onap_client import sdnc +from onap_client import config +from onap_client.sdnc.client import SDNCClient + +PAYLOADS_DIR = config.PAYLOADS_DIR +sdnc_properties = sdnc.SDNC_PROPERTIES +application_id = config.APPLICATION_ID + + +class OperationsClient(SDNCClient): + @property + def catalog_resources(self): + return CATALOG_RESOURCES + + @property + def namespace(self): + return "operations" + + +CATALOG_RESOURCES = { + "GR_API_PRELOAD": { + "verb": "POST", + "description": "Upload a GR API preload to SDNC", + "uri": partial( + "{endpoint}{service_path}/GENERIC-RESOURCE-API:preload-vf-module-topology-operation".format, + endpoint=sdnc_properties.SDNC_ENDPOINT, + service_path=sdnc_properties.SDNC_OPERATIONS_PATH, + ), + "payload-path": ["preload_path"], + "success_code": 200, + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "X-TransactionId": str(uuid.uuid4()), + "X-FromAppId": application_id, + }, + "auth": (sdnc_properties.SDNC_USERNAME, sdnc_properties.SDNC_PASSWORD,), + }, + "VNF_API_PRELOAD": { + "verb": "POST", + "description": "Upload a VNF API preload to SDNC", + "uri": partial( + "{endpoint}{service_path}/VNF-API:preload-vnf-topology-operation".format, + endpoint=sdnc_properties.SDNC_ENDPOINT, + service_path=sdnc_properties.SDNC_OPERATIONS_PATH, + ), + "payload-path": ["preload_path"], + "success_code": 200, + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "X-TransactionId": str(uuid.uuid4()), + "X-FromAppId": application_id, + }, + "auth": (sdnc_properties.SDNC_USERNAME, sdnc_properties.SDNC_PASSWORD,), + }, +} diff --git a/onap-client/onap_client/sdnc/client.py b/onap-client/onap_client/sdnc/client.py new file mode 100644 index 0000000..c0a3d1b --- /dev/null +++ b/onap-client/onap_client/sdnc/client.py @@ -0,0 +1,53 @@ +# -*- 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============================================ + +from onap_client import sdnc +from onap_client.client.clients import Client +from onap_client import config + +sdnc_properties = sdnc.SDNC_PROPERTIES +application_id = config.APPLICATION_ID + + +class SDNCClient(Client): + @property + def namespace(self): + return "sdnc" + + @property + def catalog_resources(self): + return {} diff --git a/onap-client/onap_client/sdnc/preload.py b/onap-client/onap_client/sdnc/preload.py new file mode 100644 index 0000000..65c5e0c --- /dev/null +++ b/onap-client/onap_client/sdnc/preload.py @@ -0,0 +1,191 @@ +# -*- 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============================================ + +import json +import tempfile + +from onap_client.resource import Resource +from onap_client.client.clients import Client as SDNCClient +from onap_client.exceptions import ServiceInstanceNotFound, VNFInstanceNotFound +from onap_client import so +from onap_client.config import LOG as logger + +oc = SDNCClient() +sdnc_client = oc.sdnc + + +class Preload(Resource): + resource_name = "PRELOAD" + spec = { + "api_type": {"type": str, "required": True}, + "preload_path": {"type": str, "required": True}, + "service_instance_name": {"type": str, "required": True}, + "vnf_instance_name": {"type": str, "required": True}, + "module_instance_name": {"type": str, "required": True}, + "heat_template_name": {"type": str, "required": True}, + } + + def __init__( + self, + preload_path, + vnf_instance_name, + service_instance_name, + module_instance_name, + heat_template_name, + api_type, + ): + instance_input = {} + + instance_input["preload_path"] = preload_path + instance_input["vnf_instance_name"] = vnf_instance_name + instance_input["service_instance_name"] = service_instance_name + instance_input["module_instance_name"] = module_instance_name + instance_input["heat_template_name"] = heat_template_name + instance_input["api_type"] = api_type + + super().__init__(instance_input) + + def _create(self, instance_input): + service_instance = so.vnf_instance.get_service_instance( + instance_input.get("service_instance_name") + ) + if not service_instance: + raise ServiceInstanceNotFound( + "No service instance found for {}".format( + instance_input.get("service_instance_name") + ) + ) + + vnf_instance = so.vnf_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") + ) + ) + + service_model_information = ( + service_instance.get("service-data") + .get("service-information") + .get("onap-model-information") + ) + service_model_name = service_model_information["model-name"] + vnf_model_information = ( + vnf_instance.get("vnf-data") + .get("vnf-information") + .get("onap-model-information") + ) + vnf_model_name = vnf_model_information["model-name"] + + vnf_component = so.vnf_instance.get_vnf_model_component( + service_model_name, vnf_model_name + ) + module_model = so.vnf_instance.get_module_model( + vnf_component, instance_input.get("heat_template_name") + ) + + preload_path = update_preload_with_instance( + instance_input.get("preload_path"), + instance_input.get("api_type"), + "{}/{} 0".format(service_model_name, vnf_model_name), + instance_input.get("vnf_instance_name"), + instance_input.get("module_instance_name"), + module_model.get("groupName"), + ) + + logger.info("Created preload {}".format(preload_path)) + + create_preload(preload_path, instance_input.get("api_type")) + + return instance_input + + def _post_create(self): + pass + + def _submit(self): + pass + + +def create_preload(preload_path, api_type): + if api_type == "GR_API": + sdnc_client.operations.gr_api_preload(preload_path=preload_path) + elif api_type == "VNF_API": + sdnc_client.operations.vnf_api_preload(preload_path=preload_path) + + +def update_preload_with_instance( + preload_path, + api_type, + vnf_type, + vnf_instance_name, + module_instance_name, + module_model_name, +): + with open(preload_path, "r") as f: + preload_data = json.loads(f.read()) + + if api_type == "GR_API": + data = {"vnf-name": vnf_instance_name, "vnf-type": vnf_type} + preload_data["input"]["preload-vf-module-topology-information"][ + "vnf-topology-identifier-structure" + ] = data + data = { + "vf-module-type": module_model_name, + "vf-module-name": module_instance_name, + } + preload_data["input"]["preload-vf-module-topology-information"][ + "vf-module-topology" + ]["vf-module-topology-identifier"] = data + elif api_type == "VNF_API": + data = { + "vnf-name": module_instance_name, + "vnf-type": module_model_name, + "generic-vnf-type": vnf_type, + "generic-vnf-name": vnf_instance_name, + } + preload_data["input"]["vnf-topology-information"][ + "vnf-topology-identifier" + ] = data + + filename = "" + with tempfile.NamedTemporaryFile(mode='w+t', delete=False) as f: + filename = f.name + json.dump(preload_data, f, indent=4) + + return filename diff --git a/onap-client/onap_client/sdnc/tests/__init__.py b/onap-client/onap_client/sdnc/tests/__init__.py new file mode 100644 index 0000000..5519a84 --- /dev/null +++ b/onap-client/onap_client/sdnc/tests/__init__.py @@ -0,0 +1,36 @@ +# -*- 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============================================ -- cgit 1.2.3-korg