b3aef11f4c243fb6f4a41a4626d37cc7b434f5e4
[ccsdk/cds.git] / components / scripts / python / ccsdk_netconf / netconfclient.py
1 from netconf_constant import *
2 from org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor import NetconfExecutorExtensionsKt
3
4
5 class NetconfClient:
6
7     def __init__(self, log, component_function, requirement_name):
8         self.log = log
9         self.component_function = component_function
10         netconf_device = NetconfExecutorExtensionsKt.netconfDevice(component_function, requirement_name)
11         self.netconf_rpc_client = netconf_device.netconfRpcService
12         self.netconf_session = netconf_device.netconfSession
13
14     def disconnect(self):
15         self.netconf_session.disconnect()
16         return
17
18     def connect(self):
19         self.netconf_session.connect()
20         return
21
22     def lock(self, config_target=CONFIG_TARGET_CANDIDATE):
23         device_response = self.netconf_rpc_client.lock(config_target)
24         return device_response
25
26     def get_config(self, filter="", config_target=CONFIG_TARGET_RUNNING):
27         device_response = self.netconf_rpc_client.getConfig(filter, config_target)
28         return device_response
29
30     def edit_config(self, message_content, config_target=CONFIG_TARGET_CANDIDATE,
31                     edit_default_peration=CONFIG_DEFAULT_OPERATION_REPLACE):
32         device_response = self.netconf_rpc_client.editConfig(message_content,
33                                                              config_target,
34                                                              edit_default_peration)
35         return device_response
36
37     def commit(self, confirmed=False, confirm_timeout=60, persist="",
38                persist_id=""):
39         device_response = self.netconf_rpc_client.commit(confirmed, confirm_timeout,
40                                                          persist, persist_id)
41         return device_response
42
43     def invoke_rpc(self, rpc):
44         device_response = self.netconf_rpc_client.invokeRpc(rpc)
45         return device_response
46
47     def cancel_commit(self, persist_id=""):
48         device_response = self.netconf_rpc_client.cancelCommit(persist_id)
49         return device_response
50
51     def unlock(self, config_target=CONFIG_TARGET_CANDIDATE):
52         device_response = self.netconf_rpc_client.unLock(config_target)
53         return device_response
54
55     def validate(self, config_target=CONFIG_TARGET_CANDIDATE):
56         device_response = self.netconf_rpc_client.validate(config_target)
57         return device_response
58
59     def discard_change(self):
60         device_response = self.netconf_rpc_client.discardConfig()
61         return device_response
62
63     def set_execution_attribute_response_data(self, response_data):
64         self.setAttribute(ATTRIBUTE_RESPONSE_DATA, response_data)