Migrate ccsdk/apps to ccsdk/cds
[ccsdk/cds.git] / components / model-catalog / blueprint-model / test-blueprint / capability_python / Scripts / python / DefaultGetNetConfig.py
1 import  netconf_constant
2 from netconfclient import NetconfClient
3 from java.lang import Exception
4 from abstract_blueprint_function import AbstractPythonComponentFunction
5 from org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor import NetconfRpcService
6
7
8
9 class DefaultGetNetConfig(AbstractPythonComponentFunction):
10     def process(self, execution_request):
11         try:
12             log = globals()[netconf_constant.SERVICE_LOG]
13             print(globals())
14             #requestId = globals()[netconf_constant.PARAM_REQUEST_ID]
15             requestId = '1234'
16
17             bluePrintRuntimeService = globals()['bluePrintRuntimeService']
18
19             capabilityProperty = bluePrintRuntimeService.resolveNodeTemplateCapabilityProperties("sample-netconf-device","netconf")
20
21             log.info("capabilityProperty {}",capabilityProperty)
22             netconfService = NetconfRpcService()
23             nc = NetconfClient(log, netconfService)
24
25             nc.connect(netconfService.getNetconfDeviceInfo(capabilityProperty))
26             runningConfigTemplate = "runningconfig-template"
27
28             runningConfigMessageId = "get-config-" + requestId
29
30             deviceResponse = nc.getConfig(messageId=runningConfigMessageId,
31                                           filter=runningConfigTemplate)
32
33             log.info("Get Running Config Response {} ", deviceResponse.responseMessage)
34             if(deviceResponse !='null') :
35                 status = deviceResponse.status
36                 responseData = "{}"
37                 if (deviceResponse.status != netconf_constant.STATUS_SUCCESS and deviceResponse.errorMessage != 'null'):
38                     errorMessage = "Get Running Config Failure ::"+ deviceResponse.errorMessage
39
40         except Exception, err:
41             log.info("Exception in the script {}",err.getMessage())
42             status = netconf_constant.STATUS_FAILURE
43             errorMessage = "Get Running Config Failure ::"+err.getMessage()
44
45     def  recover(self, runtime_exception, execution_request):
46         print "Recovering calling.." + PROPERTY_BLUEPRINT_BASE_PATH
47         return None
48