1 # ============LICENSE_START=======================================================
2 # Copyright (C) 2019 Nordix Foundation.
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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 # ============LICENSE_END=========================================================
17 from org.onap.ccsdk.cds.blueprintsprocessor.functions.restconf.executor import \
18 RestconfComponentFunction
19 from java.lang import Exception as JavaException
21 from restconf_client import RestconfClient
24 class RestconfConfigDeploy(RestconfComponentFunction):
26 log = globals()["log"]
27 configlet_template_name = "config-assign"
28 configlet_resource_path = "/yang-ext:mount/mynetconf:netconflist"
29 restconf_server_identifier = "sdncodl"
31 def process(self, execution_request):
33 self.log.info("Started execution of process method")
35 restconf_client = RestconfClient(self.log, self)
36 pnf_id, resolution_key = self.retrieve_parameters(execution_request)
37 web_client_service = self.restClientService(self.restconf_server_identifier)
41 mount_payload = self.resolveAndGenerateMessage("config-deploy-mapping", "config-deploy-template")
42 restconf_client.mount_device(web_client_service, pnf_id, mount_payload)
44 # log the current configuration subtree
45 current_configuration = restconf_client.retrieve_device_configuration_subtree(
46 web_client_service, pnf_id, self.configlet_resource_path)
47 self.log.info("Current configuration subtree: {}", current_configuration)
50 configlet = self.resolveFromDatabase(resolution_key, self.configlet_template_name)
51 restconf_client.configure_device_json_patch(
52 web_client_service, pnf_id, self.configlet_resource_path, configlet)
53 except Exception, err:
54 self.log.error("an error occurred while configuring device {}", err)
57 restconf_client.unmount_device(web_client_service, pnf_id)
59 except JavaException, err:
60 self.log.error("Java Exception in the script", err)
62 except Exception, err:
63 self.log.error("Python Exception in the script:" + str(err), err)
65 self.log.info("Ended execution of process method")
67 def retrieve_parameters(self, execution_request):
68 resolution_key = self.getDynamicProperties("resolution-key").asText()
69 self.log.info("resolution_key: {}", resolution_key)
70 pnf_id = execution_request.payload.get("config-deploy-request").get("config-deploy-properties").get("pnf-id")
71 pnf_id = str(pnf_id).strip('\"')
72 self.log.info("pnf-id: {}", pnf_id)
73 return pnf_id, resolution_key
75 def recover(self, runtime_exception, execution_request):
76 self.log.info("Recover function called!")
77 self.log.info("Execution request", execution_request)
78 self.log.error("Exception", runtime_exception)
79 print self.bluePrintRuntimeService.getBluePrintError().addError(runtime_exception.getMessage())