From d48a5bd068f24ab406f14147ff132e0b5519f008 Mon Sep 17 00:00:00 2001 From: Piotr Stanior Date: Fri, 11 Feb 2022 10:57:51 +0100 Subject: Add support for resource's component property as resource input Change-Id: Ib0719f20a52aaa0356be407931a75fbeea4302dd Signed-off-by: Piotr Stanior Issue-ID: INT-2076 --- docs/source/schemas/version_1_1.rst | 4 ++ .../resources/sdc_properties_mixins.py | 53 +++++++++++++++------ onap_data_provider/schemas/infra_1_1.schema | 2 + samples/service.yaml | 54 ++++++++++++++++++---- 4 files changed, 90 insertions(+), 23 deletions(-) diff --git a/docs/source/schemas/version_1_1.rst b/docs/source/schemas/version_1_1.rst index 5d3a37f..ce74c91 100644 --- a/docs/source/schemas/version_1_1.rst +++ b/docs/source/schemas/version_1_1.rst @@ -200,6 +200,10 @@ Service inputs - boolean - NO - Determines if nested input is going to be created + * - resource-property + - boolean + - NO + - Determines whether use resource's property as an input * - resource - boolean - NO diff --git a/onap_data_provider/resources/sdc_properties_mixins.py b/onap_data_provider/resources/sdc_properties_mixins.py index 28d06c3..1b93365 100644 --- a/onap_data_provider/resources/sdc_properties_mixins.py +++ b/onap_data_provider/resources/sdc_properties_mixins.py @@ -20,8 +20,9 @@ from typing import Any, Dict, List, Union from onapsdk.exceptions import SDKException, ValidationError, ParameterError # type: ignore from onapsdk.sdc.component import Component # type: ignore -from onapsdk.sdc.properties import NestedInput, Property # type: ignore +from onapsdk.sdc.properties import NestedInput, Property, ComponentProperty # type: ignore from onapsdk.sdc.sdc_resource import SdcResource # type: ignore +from onapsdk.sdc.vf import Vf # type: ignore class SdcPropertiesMixins(ABC): @@ -116,24 +117,50 @@ class SdcPropertiesMixins(ABC): comp: Component = propresource.get_component_by_name(data["resource"]) propresource.declare_input(NestedInput(comp.sdc_resource, comp.sdc_resource.get_input(data["name"]))) + def declare_resource_property_input( + self, sdc_resource: Union[SdcResource, Component], input_data: Dict[str, Any] + ) -> None: + """Declare input from resource's property. + + Args: + sdc_resource (SdcResource): Resource for which input is going to be declared + input_data (Dict[str, Any]): Data used for input creation. + """ + if not isinstance(sdc_resource, Vf): + logging.error("Resource property as input is currently supported only for Vf resources.") + return + resource_component: Component = sdc_resource.get_component_by_name( + input_data["resource"] + ) + component_property: ComponentProperty = resource_component.get_property( + input_data["name"] + ) + sdc_resource.declare_input(component_property) + def set_inputs( - self, propresource: Union[SdcResource, Component], data: List[Dict[str, Any]] + self, sdc_resource: Union[SdcResource, Component], inputs_data: List[Dict[str, Any]], ) -> None: - """Set inputs of an SdcResource. + """Set inputs of an SdcResource. Args: - sdcresource (SdcResource): the SdcResource the inputs should belong to - data (Dict[str, Any]): Data needed to create resource. + sdc_resource (SdcResource): the SdcResource the inputs should belong to + inputs_data (Dict[str, Any]): Input data to be set into resource. """ - for property_data in data: # type: Dict[str, Any] - if property_data.get("nested-input"): - self.declare_nested_input(propresource, property_data) + for input_data in inputs_data: # type: Dict[str, Any] + if input_data.get("nested-input"): + self.declare_nested_input(sdc_resource, input_data) + elif input_data.get("resource-property"): + self.declare_resource_property_input(sdc_resource, input_data) + # In case resource already has input with given name then set its value only elif any( - (prop.name == property_data["name"] for prop in propresource.inputs) + ( + resource_input.name == input_data["name"] + for resource_input in sdc_resource.inputs + ) ): - propresource.set_input_default_value( - propresource.get_input(property_data["name"]), - property_data.get("value"), + sdc_resource.set_input_default_value( + sdc_resource.get_input(input_data["name"]), + input_data.get("value"), ) else: - self.declare_input(propresource, property_data) + self.declare_input(sdc_resource, input_data) diff --git a/onap_data_provider/schemas/infra_1_1.schema b/onap_data_provider/schemas/infra_1_1.schema index 87c6ecc..8320b74 100644 --- a/onap_data_provider/schemas/infra_1_1.schema +++ b/onap_data_provider/schemas/infra_1_1.schema @@ -292,6 +292,8 @@ properties: type: string nested-input: type: boolean + resource-property: + type: boolean resource: type: string value: diff --git a/samples/service.yaml b/samples/service.yaml index 36c92d7..8472f1b 100644 --- a/samples/service.yaml +++ b/samples/service.yaml @@ -24,11 +24,21 @@ resources: - name: sample-vnf # Make sure it exists! type: VF properties: - controller_actor: "CDS" - skip_post_instantiation_configuration: False - sdnc_artifact_name: "vnf" - sdnc_model_version: "1.0.0" - sdnc_model_name: "ubuntu20" + - name: controller_actor + type: string + value: "CDS" + - name: skip_post_instantiation_configuration + type: boolean + value: False + - name: sdnc_artifact_name + type: string + value: "vnf" + - name: sdnc_model_version + type: string + value: "1.0.0" + - name: sdnc_model_name + type: string + value: "ubuntu20" - service: name: sample-service-with-pnf resources: @@ -40,13 +50,37 @@ resources: - name: sample-pnf # Make sure it exists! type: PNF properties: - controller_actor: "CDS" - skip_post_instantiation_configuration: False - sdnc_artifact_name: "vnf" - sdnc_model_version: "1.0.0" - sdnc_model_name: "ubuntu20" + - name: controller_actor + type: string + value: "CDS" + - name: skip_post_instantiation_configuration + type: boolean + value: False + - name: sdnc_artifact_name + type: string + value: "vnf" + - name: sdnc_model_version + type: string + value: "1.0.0" + - name: sdnc_model_name + type: string + value: "ubuntu20" - service: name: sample-service-with-vl resources: - name: sample-vl # Make sure it exists! type: VL + + - service: + name: test-nested-inputs-service-1 + category: Network L4+ + description: LFN demo service + instantiation-type: Macro + resources: + - name: test-ar-pnf + type: PNF + inputs: + - resource-property: true + resource: test-ar-pnf + name: resource-property-name + value: test -- cgit 1.2.3-korg