Add support to invoke device specific RPC
[ccsdk/cds.git] / components / scripts / python / ccsdk_netconf / netconfclient.py
1 from netconf_constant import CONFIG_TARGET_RUNNING, CONFIG_TARGET_CANDIDATE, \
2   CONFIG_DEFAULT_OPERATION_REPLACE
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 = self.component_function.initializeNetconfConnection(
11         requirement_name)
12     self.netconf_rpc_client = netconf_device.netconfRpcService
13     self.netconf_session = netconf_device.netconfSession
14
15   def disconnect(self):
16     self.netconf_session.disconnect()
17     return
18
19   def connect(self):
20     self.netconf_session.connect()
21     return
22
23   def lock(self, config_target=CONFIG_TARGET_CANDIDATE):
24     device_response = self.netconf_rpc_client.lock(config_target)
25     return device_response
26
27   def get_config(self, filter="", config_target=CONFIG_TARGET_RUNNING):
28     device_response = self.netconf_rpc_client.getConfig(filter, config_target)
29     return device_response
30
31   def edit_config(self, message_content, config_target=CONFIG_TARGET_CANDIDATE,
32       edit_default_peration=CONFIG_DEFAULT_OPERATION_REPLACE):
33     device_response = self.netconf_rpc_client.editConfig(message_content,
34                                                          config_target,
35                                                          edit_default_peration)
36     return device_response
37
38   def commit(self, confirmed=False, confirm_timeout=60, persist="",
39       persist_id=""):
40     device_response = self.netconf_rpc_client.commit(confirmed, confirm_timeout,
41                                                      persist, persist_id)
42     return device_response
43
44   def invoke_rpc(self, rpc):
45     device_response = self.netconf_rpc_client.invokeRpc(rpc)
46     return device_response
47
48   def cancel_commit(self, persist_id=""):
49     device_response = self.netconf_rpc_client.cancelCommit(persist_id)
50     return device_response
51
52   def unlock(self, config_target=CONFIG_TARGET_CANDIDATE):
53     device_response = self.netconf_rpc_client.unLock(config_target)
54     return device_response
55
56   def validate(self, config_target=CONFIG_TARGET_CANDIDATE):
57     device_response = self.netconf_rpc_client.validate(config_target)
58     return device_response
59
60   def discard_change(self):
61     device_response = self.netconf_rpc_client.discardConfig()
62     return device_response