summaryrefslogtreecommitdiffstats
path: root/onap_data_provider/resources/sdc_properties_mixins.py
diff options
context:
space:
mode:
authorPiotr Stanior <piotr.stanior@t-mobile.pl>2022-02-11 10:57:51 +0100
committerPiotr Stanior <piotr.stanior@t-mobile.pl>2022-02-16 11:10:45 +0100
commitd48a5bd068f24ab406f14147ff132e0b5519f008 (patch)
treea5da298c59bb12819523e1ebc33ca7597b784e77 /onap_data_provider/resources/sdc_properties_mixins.py
parent79e2cf87c107ac0dcac46c5bf7f3a090661c8b70 (diff)
Add support for resource's component property as resource input
Change-Id: Ib0719f20a52aaa0356be407931a75fbeea4302dd Signed-off-by: Piotr Stanior <piotr.stanior@t-mobile.pl> Issue-ID: INT-2076
Diffstat (limited to 'onap_data_provider/resources/sdc_properties_mixins.py')
-rw-r--r--onap_data_provider/resources/sdc_properties_mixins.py53
1 files changed, 40 insertions, 13 deletions
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)