diff options
author | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2022-07-08 14:52:31 +0000 |
---|---|---|
committer | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2022-07-11 08:47:42 +0000 |
commit | dc0b8a7349225066f0e8e55c8decc0049696b21f (patch) | |
tree | cd790771ff4992d4c6a12ac2f5688a8f32e929fd /onap_data_provider/resources | |
parent | 4b3b475ae1adfebba77db54924b457ddde7cb0ca (diff) |
CDS blueprint and blueprint's resource template resources
Add 2 more resources:
- CDS blueprint
- CDS blueprint's resource template
Both added into 1.1 schema
Change the version into 0.7.0
Issue-ID: INT-2134
Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl>
Change-Id: I4dfb343f233922a2f8a524dc135f7eec051e69aa
Diffstat (limited to 'onap_data_provider/resources')
-rw-r--r-- | onap_data_provider/resources/blueprint_resource.py | 42 | ||||
-rw-r--r-- | onap_data_provider/resources/cds_resource_template.py | 64 | ||||
-rw-r--r-- | onap_data_provider/resources/resource_creator.py | 12 |
3 files changed, 117 insertions, 1 deletions
diff --git a/onap_data_provider/resources/blueprint_resource.py b/onap_data_provider/resources/blueprint_resource.py new file mode 100644 index 0000000..e57694a --- /dev/null +++ b/onap_data_provider/resources/blueprint_resource.py @@ -0,0 +1,42 @@ +"""Blueprint resource module.""" +""" + Copyright 2022 Deutsche Telekom AG + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file 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. +""" + +import logging +from typing import Any, Dict +from onapsdk.cds import Blueprint, BlueprintModel # type: ignore + +from onapsdk.exceptions import FileError, ResourceNotFound # type: ignore +from onap_data_provider.resources.resource import Resource + + +class BlueprintResource(Resource): + + def __init__(self, data: Dict[str, Any]) -> None: + super().__init__(data) + + self._blueprint: Blueprint = None + self._blueprint_model: BlueprintModel = None + + def create(self) -> None: + enriched_blueprint: Blueprint = self.blueprint.enrich() + enriched_blueprint.publish() + + @property + def blueprint(self) -> Blueprint: + if not self._blueprint: + self._blueprint = Blueprint.load_from_file(self.data["blueprint-file-path"]) + return self._blueprint diff --git a/onap_data_provider/resources/cds_resource_template.py b/onap_data_provider/resources/cds_resource_template.py new file mode 100644 index 0000000..5233707 --- /dev/null +++ b/onap_data_provider/resources/cds_resource_template.py @@ -0,0 +1,64 @@ +"""Customer resource module.""" +""" + Copyright 2022 Deutsche Telekom AG + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file 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. +""" + +import logging +from typing import Any, Dict +from onapsdk.cds import Blueprint, BlueprintModel # type: ignore + +from onapsdk.exceptions import ResourceNotFound # type: ignore +from onap_data_provider.resources.resource import Resource + + +class BlueprintResourceTemplateResource(Resource): + + def __init__(self, data: Dict[str, Any]) -> None: + super().__init__(data) + + self._blueprint: Blueprint = None + self._blueprint_model: BlueprintModel = None + + def create(self) -> None: + if self.blueprint: + if (data_to_store := self.data.get("data")) is None: + with open(self.data["data-file"], "r") as data_file: + data_to_store = data_file.read().encode("utf-8") + self.blueprint.store_resolved_template( + artifact_name=self.data["artifact-name"], + data=data_to_store, + resolution_key=self.data.get("resolution-key"), + resource_type=self.data.get("resource-type"), + resource_id=self.data.get("resource-id") + ) + + @property + def blueprint_model(self) -> BlueprintModel: + if not self._blueprint_model: + try: + self._blueprint_model = BlueprintModel.get_by_name_and_version( + blueprint_name=self.data["blueprint-name"], + blueprint_version=self.data["blueprint-version"] + ) + except ResourceNotFound: + logging.error(f"No blueprint with {self.data['blueprint-name']} name and {self.data['blueprint-version']} version") + return None + return self._blueprint_model + + @property + def blueprint(self) -> Blueprint: + if self.blueprint_model and not self._blueprint: + self._blueprint = self.blueprint_model.get_blueprint() + return self._blueprint diff --git a/onap_data_provider/resources/resource_creator.py b/onap_data_provider/resources/resource_creator.py index de9ee9b..c6ed4d8 100644 --- a/onap_data_provider/resources/resource_creator.py +++ b/onap_data_provider/resources/resource_creator.py @@ -22,9 +22,12 @@ import typing from abc import ABC from .aai_service_resource import AaiServiceResource +from .blueprint_resource import BlueprintResource +from .cds_resource_template import BlueprintResourceTemplateResource from .cloud_region_resource import CloudRegionResource from .complex_resource import ComplexResource from .customer_resource import CustomerResource +from .data_dictionary_resource import DataDictionarySetResource from .line_of_business_resource import LineOfBusinessResource from .msb_k8s_definition import MsbK8SDefinitionResource from .owning_entity_resource import OwningEntityResource @@ -38,7 +41,6 @@ from .service_instance_resource import ( from .vendor_resource import VendorResource from .vnf_resource import VnfResource from .vsp_resource import VspResource -from .data_dictionary_resource import DataDictionarySetResource from ..versions import VersionsEnum if typing.TYPE_CHECKING: @@ -134,6 +136,12 @@ class ResourceCreator(ABC): VersionsEnum.V1_0: DataDictionarySetResource, VersionsEnum.V1_1: DataDictionarySetResource, }, + "blueprint": { + VersionsEnum.V1_1: BlueprintResource, + }, + "blueprint-resource-template": { + VersionsEnum.V1_1: BlueprintResourceTemplateResource, + } } @classmethod @@ -164,6 +172,8 @@ class ResourceCreator(ABC): - owning-entity: OwningEntityResource - msb-k8s-definition: MsbK8SDefinitionResource - data-dictionaries: DataDictionarySetResource + - blueprints: BlueprintResource + - blueprint-resource-template: BlueprintResourceTemplateResource Args: resource_type (str): Resource type to create |