4db7c731bda763a3754e29eebbac26c7ba27c228
[ccsdk/cds.git] /
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.apps.blueprintsprocessor.functions.netconf.executor import NetconfRpcService
6 from org.onap.ccsdk.apps.controllerblueprints.core.utils import JacksonUtils
7 from org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.interfaces import DeviceInfo
8 from org.onap.ccsdk.apps.controllerblueprints.core.service import BluePrintRuntimeService
9
10
11 class DefaultGetNetConfig(AbstractPythonComponentFunction):
12     def process(self, execution_request):
13         try:
14             log = globals()[netconf_constant.SERVICE_LOG]
15             print(globals())
16             #requestId = globals()[netconf_constant.PARAM_REQUEST_ID]
17             requestId = '1234'
18
19             bluePrintRuntimeService = globals()['bluePrintRuntimeService']
20
21             capabilityProperty = bluePrintRuntimeService.resolveNodeTemplateCapabilityProperties("sample-netconf-device","netconf")
22
23             log.info("capabilityProperty {}",capabilityProperty)
24             netconfService = NetconfRpcService()
25             nc = NetconfClient(log, netconfService)
26
27             nc.connect(netconfService.getNetconfDeviceInfo(capabilityProperty))
28             runningConfigTemplate = "runningconfig-template"
29
30             runningConfigMessageId = "get-config-" + requestId
31
32             deviceResponse = nc.getConfig(messageId=runningConfigMessageId,
33                                           filter=runningConfigTemplate)
34
35             log.info("Get Running Config Response {} ", deviceResponse.responseMessage)
36             if(deviceResponse !='null') :
37                 status = deviceResponse.status
38                 responseData = "{}"
39                 if (deviceResponse.status != netconf_constant.STATUS_SUCCESS and deviceResponse.errorMessage != 'null'):
40                     errorMessage = "Get Running Config Failure ::"+ deviceResponse.errorMessage
41
42         except Exception, err:
43             log.info("Exception in the script {}",err.getMessage())
44             status = netconf_constant.STATUS_FAILURE
45             errorMessage = "Get Running Config Failure ::"+err.getMessage()
46
47     def  recover(self, runtime_exception, execution_request):
48         print "Recovering calling.." + PROPERTY_BLUEPRINT_BASE_PATH
49         return None
50