Merge "Designer > Breadcrumb"
[ccsdk/cds.git] / components / model-catalog / blueprint-model / service-blueprint / vLB / Scripts / python / ConfigDeploy.py
1 #  Copyright (c) 2019 Bell Canada.\r
2 #\r
3 #  Licensed under the Apache License, Version 2.0 (the "License");\r
4 #  you may not use this file except in compliance with the License.\r
5 #  You may obtain a copy of the License at\r
6 #\r
7 #      http://www.apache.org/licenses/LICENSE-2.0\r
8 #\r
9 #  Unless required by applicable law or agreed to in writing, software\r
10 #  distributed under the License is distributed on an "AS IS" BASIS,\r
11 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12 #  See the License for the specific language governing permissions and\r
13 #  limitations under the License.\r
14 \r
15 import netconf_constant\r
16 from common import ResolutionHelper\r
17 from time import sleep \r
18 from netconfclient import NetconfClient\r
19 from org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor import \\r
20   NetconfComponentFunction\r
21 \r
22 \r
23 class ConfigDeploy(NetconfComponentFunction):\r
24 \r
25   def process(self, execution_request):      \r
26       log = globals()[netconf_constant.SERVICE_LOG]       \r
27       print(globals())\r
28 #      print("Waiting 4 minutes until NETCONF server is UP on vLB ...")\r
29 #     sleep (240)\r
30       nc = NetconfClient(log, self, "netconf-connection")\r
31       rr = ResolutionHelper(self)\r
32 \r
33       # Get meshed template from DB\r
34       resolution_key = self.getDynamicProperties("resolution-key").asText()\r
35       payloadHostname = rr.retrieve_resolved_template_from_database(resolution_key, "baseconfig")\r
36       payloadInterface = rr.retrieve_resolved_template_from_database(resolution_key, "incremental-config")\r
37 \r
38       nc.connect()\r
39       nc.lock()\r
40       #if not response.isSuccess():\r
41       #  og.error(response.errorMessage)\r
42       nc.discard_change()\r
43       nc.edit_config(message_content=payloadInterface, edit_default_peration="merge") \r
44       nc.edit_config(message_content=payloadHostname, edit_default_peration="merge")  \r
45       #nc.validate()\r
46       nc.commit()\r
47       nc.get_config()                           #nc.commit(confirmed = True, confirm_timeout=15)\r
48       nc.unlock()\r
49       nc.disconnect()\r
50 \r
51   def recover(self, runtime_exception, execution_request):\r
52         log.error("Exception in the script {}", runtime_exception)\r
53         print self.addError(runtime_exception.cause.message)\r
54         return None