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)
40 mount_payload = self.resolveAndGenerateMessage("config-deploy-mapping", "config-deploy-template")
41 restconf_client.mount_device(web_client_service, pnf_id, mount_payload)
43 configlet = self.resolveFromDatabase(resolution_key, self.configlet_template_name)
44 restconf_client.configure_device(web_client_service, pnf_id, self.configlet_resource_path, configlet)
45 except Exception, err:
46 self.log.error("an error occurred while configuring device {}", err)
49 restconf_client.unmount_device(web_client_service, pnf_id)
51 except JavaException, err:
52 self.log.error("Java Exception in the script", err)
54 except Exception, err:
55 self.log.error("Python Exception in the script:" + str(err), err)
57 self.log.info("Ended execution of process method")
59 def retrieve_parameters(self, execution_request):
60 resolution_key = self.getDynamicProperties("resolution-key").asText()
61 self.log.info("resolution_key: {}", resolution_key)
62 pnf_id = execution_request.payload.get("config-deploy-request").get("config-deploy-properties").get("pnf-id")
63 pnf_id = str(pnf_id).strip('\"')
64 self.log.info("pnf-id: {}", pnf_id)
65 return pnf_id, resolution_key
67 def recover(self, runtime_exception, execution_request):
68 self.log.info("Recover function called!")
69 self.log.info("Execution request", execution_request)
70 self.log.error("Exception", runtime_exception)
71 print self.bluePrintRuntimeService.getBluePrintError().addError(runtime_exception.getMessage())