diff options
Diffstat (limited to 'onap-client/onap_client/so')
-rw-r--r-- | onap-client/onap_client/so/__init__.py | 40 | ||||
-rw-r--r-- | onap-client/onap_client/so/catalog/__init__.py | 36 | ||||
-rw-r--r-- | onap-client/onap_client/so/catalog/service_instantiation.py | 316 | ||||
-rw-r--r-- | onap-client/onap_client/so/client.py | 69 | ||||
-rw-r--r-- | onap-client/onap_client/so/module_instance.py | 236 | ||||
-rw-r--r-- | onap-client/onap_client/so/service_instance.py | 230 | ||||
-rw-r--r-- | onap-client/onap_client/so/tests/__init__.py | 36 | ||||
-rw-r--r-- | onap-client/onap_client/so/vnf_instance.py | 267 |
8 files changed, 1230 insertions, 0 deletions
diff --git a/onap-client/onap_client/so/__init__.py b/onap-client/onap_client/so/__init__.py new file mode 100644 index 0000000..44cf6d7 --- /dev/null +++ b/onap-client/onap_client/so/__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 + +SO_PROPERTIES = APP_CONFIG.so diff --git a/onap-client/onap_client/so/catalog/__init__.py b/onap-client/onap_client/so/catalog/__init__.py new file mode 100644 index 0000000..5519a84 --- /dev/null +++ b/onap-client/onap_client/so/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/so/catalog/service_instantiation.py b/onap-client/onap_client/so/catalog/service_instantiation.py new file mode 100644 index 0000000..665402f --- /dev/null +++ b/onap-client/onap_client/so/catalog/service_instantiation.py @@ -0,0 +1,316 @@ +# -*- 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 so +from onap_client import config +from onap_client.so.client import SOClient + +PAYLOADS_DIR = config.PAYLOADS_DIR +so_properties = so.SO_PROPERTIES +application_id = config.APPLICATION_ID + + +class ServiceInstantiationClient(SOClient): + @property + def catalog_resources(self): + return CATALOG_RESOURCES + + @property + def namespace(self): + return "service_instantiation" + + +CATALOG_RESOURCES = { + "CREATE_SERVICE_INSTANCE": { + "verb": "POST", + "description": "Creates a Service Instance from the service catalog", + "uri": partial( + "{endpoint}{service_path}".format, + endpoint=so_properties.SO_ENDPOINT, + service_path=so_properties.SO_SERVICE_INSTANCE_PATH, + ), + "payload": "{}/so_service_instance.jinja".format(PAYLOADS_DIR), + "payload-parameters": [ + "service_instance_name", + "requestor_id", + "model_invariant_id", + "model_version_id", + "model_name", + "model_version", + "tenant_id", + "cloud_owner", + "cloud_region", + "api_type", + "service_type", + "customer_id", + "project_name", + "owning_entity_id", + ], + "header-parameters": ["X-TransactionId"], + "success_code": 202, + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + # "X-TransactionId": str(uuid.uuid4()), + "X-FromAppId": application_id, + }, + "auth": (so_properties.SO_USERNAME, so_properties.SO_PASSWORD), + }, + "DELETE_SERVICE_INSTANCE": { + "verb": "DELETE", + "description": "Deletes a VNF Instance.", + "uri": partial( + "{endpoint}{service_path}/{service_instance_id}".format, + endpoint=so_properties.SO_ENDPOINT, + service_path=so_properties.SO_SERVICE_INSTANCE_PATH, + ), + "uri-parameters": ["service_instance_id"], + "payload": "{}/so_delete_service.jinja".format(PAYLOADS_DIR), + "payload-parameters": [ + "service_invariant_id", + "service_name", + "service_version", + "api_type", + ], + "header-parameters": ["X-TransactionId"], + "success_code": 202, + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + # "X-TransactionId": str(uuid.uuid4()), + "X-FromAppId": application_id, + }, + "auth": (so_properties.SO_USERNAME, so_properties.SO_PASSWORD), + }, + "CREATE_VNF_INSTANCE": { + "verb": "POST", + "description": "Creates a VNF Instance.", + "uri": partial( + "{endpoint}{service_path}/{service_instance_id}/vnfs".format, + endpoint=so_properties.SO_ENDPOINT, + service_path=so_properties.SO_SERVICE_INSTANCE_PATH, + ), + "uri-parameters": ["service_instance_id"], + "payload": "{}/so_vnf_instance.jinja".format(PAYLOADS_DIR), + "payload-parameters": [ + "vnf_instance_name", + "requestor_id", + "model_invariant_id", + "model_version_id", + "model_name", + "model_version", + "model_customization_id", + "tenant_id", + "cloud_owner", + "cloud_region", + "api_type", + "platform", + "line_of_business", + "service_model_name", + "service_model_invariant_id", + "service_model_version", + "service_model_version_id", + "service_instance_id", + ], + "header-parameters": ["X-TransactionId"], + "success_code": 202, + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + # "X-TransactionId": str(uuid.uuid4()), + "X-FromAppId": application_id, + }, + "auth": (so_properties.SO_USERNAME, so_properties.SO_PASSWORD), + }, + "DELETE_VNF_INSTANCE": { + "verb": "DELETE", + "description": "Deletes a VNF Instance.", + "uri": partial( + "{endpoint}{service_path}/{service_instance_id}/vnfs/{vnf_instance_id}".format, + endpoint=so_properties.SO_ENDPOINT, + service_path=so_properties.SO_SERVICE_INSTANCE_PATH, + ), + "uri-parameters": ["service_instance_id", "vnf_instance_id"], + "payload": "{}/so_delete_vnf.jinja".format(PAYLOADS_DIR), + "payload-parameters": [ + "vnf_invariant_id", + "vnf_name", + "vnf_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-TransactionId": str(uuid.uuid4()), + "X-FromAppId": application_id, + }, + "auth": (so_properties.SO_USERNAME, so_properties.SO_PASSWORD), + }, + "CREATE_MODULE_INSTANCE": { + "verb": "POST", + "description": "Creates a VNF Module Instance.", + "uri": partial( + "{endpoint}{service_path}/{service_instance_id}/vnfs/{vnf_instance_id}/vfModules".format, + endpoint=so_properties.SO_ENDPOINT, + service_path=so_properties.SO_SERVICE_INSTANCE_PATH, + ), + "uri-parameters": ["service_instance_id", "vnf_instance_id"], + "payload": "{}/so_create_module.jinja".format(PAYLOADS_DIR), + "payload-parameters": [ + "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-TransactionId": str(uuid.uuid4()), + "X-FromAppId": application_id, + }, + "auth": (so_properties.SO_USERNAME, so_properties.SO_PASSWORD), + }, + "DELETE_MODULE_INSTANCE": { + "verb": "DELETE", + "description": "Deletes a VNF Module Instance.", + "uri": partial( + "{endpoint}{service_path}/{service_instance_id}/vnfs/{vnf_instance_id}/vfModules/{vf_module_id}".format, + endpoint=so_properties.SO_ENDPOINT, + service_path=so_properties.SO_SERVICE_INSTANCE_PATH, + ), + "uri-parameters": ["service_instance_id", "vnf_instance_id", "vf_module_id"], + "payload": "{}/so_delete_module.jinja".format(PAYLOADS_DIR), + "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-TransactionId": str(uuid.uuid4()), + "X-FromAppId": application_id, + }, + "auth": (so_properties.SO_USERNAME, so_properties.SO_PASSWORD), + }, + "GET_REQUEST_STATUS": { + "verb": "GET", + "description": "Queries the status for a given request ID", + "uri": partial( + "{endpoint}{service_path}/{request_id}".format, + endpoint=so_properties.SO_ENDPOINT, + service_path=so_properties.SO_ORCHESTRATION_PATH, + ), + "uri-parameters": ["request_id"], + "success_code": 200, + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "X-TransactionId": str(uuid.uuid4()), + "X-FromAppId": application_id, + }, + "auth": (so_properties.SO_USERNAME, so_properties.SO_PASSWORD), + }, + "GET_SERVICE_MODEL": { + "verb": "GET", + "description": "Searches the SO catalog for a service model", + "uri": partial( + "{endpoint}/service/search/findOneByModelName?modelName={model_name}".format, + endpoint=so_properties.SO_ENDPOINT, + ), + "uri-parameters": ["model_name"], + "success_code": 200, + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "X-TransactionId": str(uuid.uuid4()), + "X-FromAppId": application_id, + }, + "auth": (so_properties.SO_USERNAME, so_properties.SO_PASSWORD), + }, + "GET_SERVICE_MODEL_DETAILS": { + "verb": "GET", + "description": "Searches the SO catalog for a service model", + "uri": partial( + "{endpoint}/service/search/findOneByModelName?modelName={model_name}".format, + endpoint=so_properties.SO_ENDPOINT, + ), + "uri-parameters": ["model_name"], + "success_code": 200, + "headers": { + "Accept": "application/json", + "Content-Type": "application/json", + "X-TransactionId": str(uuid.uuid4()), + "X-FromAppId": application_id, + }, + "auth": (so_properties.SO_USERNAME, so_properties.SO_PASSWORD), + }, +} diff --git a/onap-client/onap_client/so/client.py b/onap-client/onap_client/so/client.py new file mode 100644 index 0000000..c38cf0c --- /dev/null +++ b/onap-client/onap_client/so/client.py @@ -0,0 +1,69 @@ +# -*- 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 functools import partial +from onap_client import so +from onap_client.client.clients import Client +from onap_client import config + +so_properties = so.SO_PROPERTIES +application_id = config.APPLICATION_ID + + +class SOClient(Client): + @property + def namespace(self): + return "so" + + @property + def catalog_resources(self): + return CATALOG_RESOURCES + + +CATALOG_RESOURCES = { + "HEALTH_CHECK": { + "verb": "GET", + "description": "Queries so health check endpoint", + "uri": partial( + "{endpoint}{service_path}".format, + endpoint=so_properties.SO_ENDPOINT, + service_path=so_properties.SO_HEALTH_CHECK_PATH, + ), + "success_code": 200, + "auth": (so_properties.SO_USERNAME, so_properties.SO_PASSWORD), + }, +} diff --git a/onap-client/onap_client/so/module_instance.py b/onap-client/onap_client/so/module_instance.py new file mode 100644 index 0000000..19af17a --- /dev/null +++ b/onap-client/onap_client/so/module_instance.py @@ -0,0 +1,236 @@ +# -*- 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 onap_client.resource import Resource +from onap_client.client.clients import Client as SOClient +from onap_client.exceptions import ServiceInstanceNotFound, VNFInstanceNotFound, ModuleInstanceNotFound +from onap_client import so +from onap_client import sdnc +from onap_client.util import utility + +oc = SOClient() +so_client = oc.so + + +class VNFInstance(Resource): + resource_name = "MODULE_INSTANCE" + spec = { + "module_instance_name": {"type": str, "required": True}, + "vnf_instance_name": {"type": str, "required": True}, + "service_instance_name": {"type": str, "required": True}, + "requestor_id": {"type": str, "required": False, "default": "cs0008"}, + "heat_template_name": {"type": str, "required": True}, + "preload_path": {"type": str, "required": True}, + "tenant_name": {"type": str, "required": True}, + "cloud_owner": {"type": str, "required": True}, + "cloud_region": {"type": str, "required": True}, + "api_type": {"type": str, "required": False, "default": "GR_API"}, + } + + def __init__( + self, + module_instance_name, + vnf_instance_name, + service_instance_name, + requestor_id, + heat_template_name, + preload_path, + tenant_name, + cloud_owner, + cloud_region, + api_type, + ): + instance_input = {} + + tenant_id = so.service_instance.get_tenant_id(cloud_region, cloud_owner, tenant_name) + + instance_input["module_instance_name"] = module_instance_name + instance_input["vnf_instance_name"] = vnf_instance_name + instance_input["service_instance_name"] = service_instance_name + instance_input["requestor_id"] = requestor_id + instance_input["heat_template_name"] = heat_template_name + instance_input["preload_path"] = preload_path + instance_input["tenant_id"] = tenant_id + instance_input["cloud_owner"] = cloud_owner + instance_input["cloud_region"] = cloud_region + 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") + ) + ) + service_instance_id = service_instance.get("service-instance-id") + model_information = ( + service_instance.get("service-data") + .get("service-information") + .get("onap-model-information") + ) + service_model_invariant_id = model_information["model-invariant-uuid"] + service_model_version_id = model_information["model-uuid"] + service_model_version = model_information["model-version"] + service_model_name = model_information["model-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") + ) + ) + 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( + "model-name" + ) + vnf_model_invariant_id = vnf_model_information.get( + "onap-model-information" + ).get("model-invariant-uuid") + vnf_model_version_id = vnf_model_information.get("onap-model-information").get( + "model-uuid" + ) + vnf_model_customization_id = vnf_model_information.get( + "onap-model-information" + ).get("model-customization-uuid") + vnf_model_version = vnf_model_information.get("onap-model-information").get( + "model-version" + ) + + vnf_model = so.vnf_instance.get_vnf_model_component( + service_model_name, vnf_model_name + ) + + module_model = so.vnf_instance.get_module_model( + vnf_model, instance_input.get("heat_template_name") + ) + model_invariant_id = module_model.get("invariantUUID") + model_version_id = module_model.get("groupUUID") + model_customization_id = module_model.get("customizationUUID") + model_name = module_model.get("groupName") + model_version = module_model.get("version") + + instance_input["model_invariant_id"] = model_invariant_id + instance_input["model_version_id"] = model_version_id + instance_input["model_name"] = model_name + instance_input["model_version"] = model_version + instance_input["model_customization_id"] = model_customization_id + instance_input["service_instance_id"] = service_instance_id + instance_input["service_model_name"] = service_model_name + instance_input["service_model_invariant_id"] = service_model_invariant_id + instance_input["service_model_version"] = service_model_version + instance_input["service_model_version_id"] = service_model_version_id + instance_input["vnf_instance_id"] = vnf_instance_id + instance_input["vnf_model_name"] = vnf_model_name + instance_input["vnf_model_invariant_id"] = vnf_model_invariant_id + instance_input["vnf_model_version_id"] = vnf_model_version_id + instance_input["vnf_model_version"] = vnf_model_version + instance_input["vnf_model_customization_id"] = vnf_model_customization_id + + return create_module_instance(instance_input) + + def _post_create(self): + pass + + def _submit(self): + pass + + +def create_module_instance(instance_input): + sdnc.preload.Preload( + instance_input.get("preload_path"), + instance_input.get("vnf_instance_name"), + instance_input.get("service_instance_name"), + instance_input.get("module_instance_name"), + instance_input.get("heat_template_name"), + instance_input.get("api_type") + ) + + headers = {"X-TransactionId": str(uuid.uuid4())} + module_instance = so_client.service_instantiation.create_module_instance( + **instance_input, **headers + ) + + request_id = module_instance.response_data.get("requestReferences", {}).get( + "requestId" + ) + + instance_input["request_info"] = so.service_instance.poll_request(request_id) + + return instance_input + + +@utility +def delete_module_instance(service_instance_name, vnf_instance_name, module_instance_name, api_type="GR_API"): + """Delete a Module Instance from SO""" + 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 so_client.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)) diff --git a/onap-client/onap_client/so/service_instance.py b/onap-client/onap_client/so/service_instance.py new file mode 100644 index 0000000..a5a2e8f --- /dev/null +++ b/onap-client/onap_client/so/service_instance.py @@ -0,0 +1,230 @@ +# -*- 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 onap_client.lib import generate_dummy_string +from onap_client.resource import Resource +from onap_client.client.clients import Client as SOClient +from onap_client.so import SO_PROPERTIES +from onap_client.exceptions import ( + SORequestStatusUnavailable, + SORequestFailed, + SORequestTimeout, + TenantNotFound, + ServiceInstanceNotFound, +) +from onap_client import sdc +from onap_client.util import utility + +from time import sleep + +oc = SOClient() +so_client = oc.so +sdc_client = oc.sdc +aai_client = oc.aai +sdnc_client = oc.sdnc +vid_client = oc.vid + + +class ServiceInstance(Resource): + resource_name = "SERVICE_INSTANCE" + spec = { + "service_instance_name": { + "type": str, + "required": False, + "default": generate_dummy_string("SI_"), + }, + "requestor_id": {"type": str, "required": False, "default": "cs0008"}, + "model_name": {"type": str, "required": True}, + "model_version": {"type": str, "required": False, "default": "1.0"}, + "tenant_name": {"type": str, "required": True}, + "cloud_owner": {"type": str, "required": True}, + "cloud_region": {"type": str, "required": True}, + "api_type": {"type": str, "required": False, "default": "GR_API"}, + "service_type": {"type": str, "required": True}, + "customer_name": {"type": str, "required": True}, + "project_name": {"type": str, "required": True}, + "owning_entity_name": {"type": str, "required": True}, + } + + def __init__( + self, + service_instance_name, + requestor_id, + model_name, + model_version, + tenant_name, + cloud_owner, + cloud_region, + api_type, + service_type, + customer_name, + project_name, + owning_entity_name, + ): + instance_input = {} + + tenant_id = get_tenant_id(cloud_region, cloud_owner, tenant_name) + + instance_input["service_instance_name"] = service_instance_name + instance_input["requestor_id"] = requestor_id + instance_input["model_name"] = model_name + instance_input["model_version"] = model_version + instance_input["tenant_id"] = tenant_id + instance_input["cloud_owner"] = cloud_owner + instance_input["cloud_region"] = cloud_region + instance_input["api_type"] = api_type + instance_input["service_type"] = service_type + instance_input["customer_id"] = customer_name + instance_input["project_name"] = project_name + instance_input["owning_entity_name"] = owning_entity_name + + super().__init__(instance_input) + + def _create(self, instance_input): + service_model = sdc_client.service.get_sdc_service( + catalog_service_id=sdc.service.get_service_id( + instance_input.get("model_name") + ) + ).response_data + + instance_input["model_invariant_id"] = service_model["invariantUUID"] + instance_input["model_version_id"] = service_model["uniqueId"] + + category_parameters = vid_client.maintenance.get_category_parameters().response_data + for entity in category_parameters.get("categoryParameters", {}).get("owningEntity", []): + if entity.get("name") == instance_input.get("owning_entity_name"): + instance_input["owning_entity_id"] = entity.get("id") + break + + return create_service_instance(instance_input) + + def _post_create(self): + pass + + def _submit(self): + pass + + +@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>""" + service_instances = sdnc_client.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 get_tenant_id(cloud_region, cloud_owner, tenant_name): + tenants = aai_client.cloud_infrastructure.get_cloud_region_tenants( + cloud_owner=cloud_owner, + cloud_region=cloud_region + ).response_data + + for tenant in tenants.get("tenant"): + if tenant.get("tenant-name") == tenant_name: + return tenant.get("tenant-id") + + raise TenantNotFound("Tenant {} was not found in AAI".format(tenant_name)) + + +def create_service_instance(instance_input): + headers = {"X-TransactionId": str(uuid.uuid4())} + service_instance = so_client.service_instantiation.create_service_instance( + **instance_input, **headers + ) + + request_id = service_instance.response_data.get("requestReferences", {}).get( + "requestId" + ) + + instance_input["request_info"] = poll_request(request_id) + + return instance_input + + +@utility +def poll_request(request_id): + """Poll an SO request until completion""" + poll_interval = SO_PROPERTIES.POLL_INTERVAL or 30 + request = None + x = 0 + while x < 30: + request = so_client.service_instantiation.get_request_status( + request_id=request_id + ).response_data + status = request.get("request", {}).get("requestStatus", {}).get("requestState") + if not status: + raise SORequestStatusUnavailable( + "Could not determine request for {}".format(request_id) + ) + if status == "FAILED": + failure_message = ( + request.get("request", {}).get("requestStatus", {}).get("statusMessage") + ) + raise SORequestFailed( + "Request {} failed with message {}".format(request_id, failure_message) + ) + elif status == "COMPLETE": + return request + + x += 1 + + sleep(poll_interval) + + raise SORequestTimeout("Request {} timed out polling for status".format(request_id)) + + +@utility +def delete_service_instance(service_instance_name, api_type="GR_API"): + """Delete a Service Instance from SO""" + si = get_service_instance(service_instance_name) + 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") + + return so_client.service_instantiation.delete_service_instance( + service_invariant_id=invariant_id, + service_name=service_instance_name, + service_version=version, + service_instance_id=si_id, + api_type=api_type, + ).response_data diff --git a/onap-client/onap_client/so/tests/__init__.py b/onap-client/onap_client/so/tests/__init__.py new file mode 100644 index 0000000..5519a84 --- /dev/null +++ b/onap-client/onap_client/so/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============================================ diff --git a/onap-client/onap_client/so/vnf_instance.py b/onap-client/onap_client/so/vnf_instance.py new file mode 100644 index 0000000..4d289a0 --- /dev/null +++ b/onap-client/onap_client/so/vnf_instance.py @@ -0,0 +1,267 @@ +# -*- 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 onap_client.lib import generate_dummy_string +from onap_client.resource import Resource +from onap_client.client.clients import Client as SOClient +from onap_client.exceptions import ( + ServiceInstanceNotFound, + VNFComponentNotFound, + ModuleModelNameNotFound, + NoArtifactFoundInModel, + VNFInstanceNotFound, +) +from onap_client import sdc +from onap_client import so +from onap_client.util import utility + + +oc = SOClient() +so_client = oc.so +sdc_client = oc.sdc +sdnc_client = oc.sdnc + + +class VNFInstance(Resource): + resource_name = "VNF_INSTANCE" + spec = { + "vnf_instance_name": { + "type": str, + "required": False, + "default": generate_dummy_string("VNF_"), + }, + "service_instance_name": {"type": str, "required": True}, + "requestor_id": {"type": str, "required": False, "default": "cs0008"}, + "model_name": {"type": str, "required": True}, + "tenant_name": {"type": str, "required": True}, + "cloud_owner": {"type": str, "required": True}, + "cloud_region": {"type": str, "required": True}, + "api_type": {"type": str, "required": False, "default": "GR_API"}, + "platform": {"type": str, "required": True}, + "line_of_business": {"type": str, "required": True}, + } + + def __init__( + self, + vnf_instance_name, + service_instance_name, + requestor_id, + model_name, + tenant_name, + cloud_owner, + cloud_region, + api_type, + platform, + line_of_business, + ): + instance_input = {} + + tenant_id = so.service_instance.get_tenant_id(cloud_region, cloud_owner, tenant_name) + + instance_input["vnf_instance_name"] = vnf_instance_name + instance_input["service_instance_name"] = service_instance_name + instance_input["requestor_id"] = requestor_id + instance_input["model_name"] = model_name + instance_input["tenant_id"] = tenant_id + instance_input["cloud_owner"] = cloud_owner + instance_input["cloud_region"] = cloud_region + instance_input["api_type"] = api_type + instance_input["platform"] = platform + instance_input["line_of_business"] = line_of_business + + super().__init__(instance_input) + + def _create(self, instance_input): + service_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") + ) + ) + service_instance_id = service_instance.get("service-instance-id") + model_information = ( + service_instance.get("service-data") + .get("service-information") + .get("onap-model-information") + ) + service_invariant_id = model_information["model-invariant-uuid"] + service_model_id = model_information["model-uuid"] + service_model_version = model_information["model-version"] + service_model_name = model_information["model-name"] + + vnf_component = get_vnf_model_component( + service_model_name, instance_input.get("model_name") + ) + if not vnf_component: + raise VNFComponentNotFound( + "No component found for {}".format(instance_input.get("model_name")) + ) + vnf_model_customization_id = vnf_component["customizationUUID"] + vnf_model_version_id = vnf_component["actualComponentUid"] + vnf_model_version = vnf_component["componentVersion"] + + vnf_model = sdc_client.vnf.get_catalog_resource( + catalog_resource_id=vnf_model_version_id, + ).response_data + vnf_model_invariant_id = vnf_model["invariantUUID"] + + instance_input["model_invariant_id"] = vnf_model_invariant_id + instance_input["model_version_id"] = vnf_model_version_id + instance_input["model_customization_id"] = vnf_model_customization_id + instance_input["model_version"] = vnf_model_version + instance_input["service_model_name"] = service_model_name + instance_input["service_model_invariant_id"] = service_invariant_id + instance_input["service_model_version"] = service_model_version + instance_input["service_model_version_id"] = service_model_id + instance_input["service_instance_id"] = service_instance_id + + return create_vnf_instance(instance_input) + + def _post_create(self): + pass + + def _submit(self): + pass + + +def get_vnf_model_component(service_model_name, vnf_model_name): + service_model = sdc_client.service.get_sdc_service( + catalog_service_id=sdc.service.get_service_id(service_model_name) + ).response_data + + for component in service_model.get("componentInstances", []): + if component["componentName"] == vnf_model_name: + return component + return None + + +def get_service_instance(service_instance_name): + service_instances = sdnc_client.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): + headers = {"X-TransactionId": str(uuid.uuid4())} + vnf_instance = so_client.service_instantiation.create_vnf_instance( + **instance_input, **headers + ) + + request_id = vnf_instance.response_data.get("requestReferences", {}).get( + "requestId" + ) + + instance_input["request_info"] = so.service_instance.poll_request(request_id) + + return instance_input + + +@utility +def delete_vnf_instance(service_instance_name, vnf_instance_name, api_type="GR_API"): + """Delete a VNF Instance from SO""" + 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: + 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 so_client.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)) |