Add wrapper function for Cli and Netconf executor
[ccsdk/cds.git] / components / scripts / python / ccsdk_netconf / common.py
1 #  Copyright (c) 2019 Bell Canada.
2 #  Modifications Copyright (c) 2018 - 2019 IBM, Bell Canada.
3 #
4 #  Licensed under the Apache License, Version 2.0 (the "License");
5 #  you may not use this file except in compliance with the License.
6 #  You may obtain a copy of the License at
7 #
8 #      http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #  Unless required by applicable law or agreed to in writing, software
11 #  distributed under the License is distributed on an "AS IS" BASIS,
12 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 #  See the License for the specific language governing permissions and
14 #  limitations under the License.
15 from netconf_constant import *
16 from org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution import ResourceResolutionExtensionsKt
17
18
19 class ResolutionHelper:
20
21     def __init__(self, component_function):
22         self.component_function = component_function
23
24     def resolve_and_generate_message_from_template_prefix(self, artifact_prefix):
25         """Get the template resolved in the current workflow execution by the artifact prefix
26
27         :param artifact_prefix:
28         :return: template
29         """
30         return ResourceResolutionExtensionsKt.contentFromResolvedArtifact(self.component_function, artifact_prefix)
31
32     def retrieve_resolved_template_from_database(self, key, artifact_template):
33         """Get the template resolved and stored with resolution-key and matching with the artifact name
34
35         :param key:
36         :param artifact_template:
37         :return:
38         """
39         return ResourceResolutionExtensionsKt.storedContentFromResolvedArtifact(self.component_function, key,
40                                                                                 artifact_template)
41
42     def set_execution_attribute_response_data(self, response_data):
43         """For the current node execution, set the attribute value of response-data
44
45         :param response_data:
46         :return:
47         """
48         self.component_function.setAttribute(ATTRIBUTE_RESPONSE_DATA, response_data)
49
50     def get_node_template_attribute(self, node_template_name, attribute_key):
51         """get attribute value for a specific node template of the current workflow
52
53         :param node_template_name:
54         :param attribute_key:
55         :return: JsonNode
56         """
57         self.component_function.getNodeTemplateAttribute(node_template_name, attribute_key)
58
59     def get_input_value(self, key):
60         """Get input value of the current node template execution
61
62         :param key:
63         :return: JsonNode
64         """
65         self.component_function.bluePrintRuntimeService.getInputValue(key)
66