Alexis de Talhouët | 3daf7d0 | 2019-02-12 23:05:01 -0500 | [diff] [blame] | 1 | from netconf_constant import CONFIG_TARGET_RUNNING, CONFIG_TARGET_CANDIDATE, \ |
| 2 | CONFIG_DEFAULT_OPERATION_REPLACE |
Cherukuri, Venkatanaresh (vn166g) | 8df5693 | 2019-02-05 09:47:55 -0500 | [diff] [blame] | 3 | |
Alexis de Talhouët | a69b9f5 | 2019-02-18 08:08:24 -0500 | [diff] [blame] | 4 | |
Cherukuri, Venkatanaresh (vn166g) | 8df5693 | 2019-02-05 09:47:55 -0500 | [diff] [blame] | 5 | class NetconfClient: |
| 6 | |
Alexis de Talhouët | 3daf7d0 | 2019-02-12 23:05:01 -0500 | [diff] [blame] | 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 |
Muthuramalingam, Brinda Santh | f7c6579 | 2019-02-12 15:26:19 -0500 | [diff] [blame] | 14 | |
Alexis de Talhouët | 3daf7d0 | 2019-02-12 23:05:01 -0500 | [diff] [blame] | 15 | def disconnect(self): |
| 16 | self.netconf_session.disconnect() |
| 17 | return |
Cherukuri, Venkatanaresh (vn166g) | 8df5693 | 2019-02-05 09:47:55 -0500 | [diff] [blame] | 18 | |
Alexis de Talhouët | 3daf7d0 | 2019-02-12 23:05:01 -0500 | [diff] [blame] | 19 | def connect(self): |
| 20 | self.netconf_session.connect() |
| 21 | return |
Cherukuri, Venkatanaresh (vn166g) | 8df5693 | 2019-02-05 09:47:55 -0500 | [diff] [blame] | 22 | |
Alexis de Talhouët | a69b9f5 | 2019-02-18 08:08:24 -0500 | [diff] [blame] | 23 | def lock(self, config_target=CONFIG_TARGET_CANDIDATE): |
| 24 | device_response = self.netconf_rpc_client.lock(config_target) |
Alexis de Talhouët | 3daf7d0 | 2019-02-12 23:05:01 -0500 | [diff] [blame] | 25 | return device_response |
Cherukuri, Venkatanaresh (vn166g) | 8df5693 | 2019-02-05 09:47:55 -0500 | [diff] [blame] | 26 | |
Alexis de Talhouët | a69b9f5 | 2019-02-18 08:08:24 -0500 | [diff] [blame] | 27 | def get_config(self, filter="", config_target=CONFIG_TARGET_RUNNING): |
| 28 | device_response = self.netconf_rpc_client.getConfig(filter, config_target) |
Alexis de Talhouët | 3daf7d0 | 2019-02-12 23:05:01 -0500 | [diff] [blame] | 29 | return device_response |
Cherukuri, Venkatanaresh (vn166g) | 8df5693 | 2019-02-05 09:47:55 -0500 | [diff] [blame] | 30 | |
Alexis de Talhouët | a69b9f5 | 2019-02-18 08:08:24 -0500 | [diff] [blame] | 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, |
Alexis de Talhouët | 3daf7d0 | 2019-02-12 23:05:01 -0500 | [diff] [blame] | 34 | config_target, |
Alexis de Talhouët | a69b9f5 | 2019-02-18 08:08:24 -0500 | [diff] [blame] | 35 | edit_default_peration) |
Alexis de Talhouët | 3daf7d0 | 2019-02-12 23:05:01 -0500 | [diff] [blame] | 36 | return device_response |
Cherukuri, Venkatanaresh (vn166g) | 8df5693 | 2019-02-05 09:47:55 -0500 | [diff] [blame] | 37 | |
Alexis de Talhouët | 18e1857 | 2019-02-19 10:02:00 -0500 | [diff] [blame] | 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 | |
Alexis de Talhouët | 1a19d33 | 2019-03-11 22:22:30 -0400 | [diff] [blame] | 44 | def invoke_rpc(self, rpc): |
| 45 | device_response = self.netconf_rpc_client.invokeRpc(rpc) |
| 46 | return device_response |
| 47 | |
Alexis de Talhouët | 18e1857 | 2019-02-19 10:02:00 -0500 | [diff] [blame] | 48 | def cancel_commit(self, persist_id=""): |
| 49 | device_response = self.netconf_rpc_client.cancelCommit(persist_id) |
Alexis de Talhouët | 3daf7d0 | 2019-02-12 23:05:01 -0500 | [diff] [blame] | 50 | return device_response |
Cherukuri, Venkatanaresh (vn166g) | 8df5693 | 2019-02-05 09:47:55 -0500 | [diff] [blame] | 51 | |
Alexis de Talhouët | a69b9f5 | 2019-02-18 08:08:24 -0500 | [diff] [blame] | 52 | def unlock(self, config_target=CONFIG_TARGET_CANDIDATE): |
| 53 | device_response = self.netconf_rpc_client.unLock(config_target) |
Alexis de Talhouët | 3daf7d0 | 2019-02-12 23:05:01 -0500 | [diff] [blame] | 54 | return device_response |
Cherukuri, Venkatanaresh (vn166g) | 8df5693 | 2019-02-05 09:47:55 -0500 | [diff] [blame] | 55 | |
Alexis de Talhouët | a69b9f5 | 2019-02-18 08:08:24 -0500 | [diff] [blame] | 56 | def validate(self, config_target=CONFIG_TARGET_CANDIDATE): |
| 57 | device_response = self.netconf_rpc_client.validate(config_target) |
Alexis de Talhouët | 3daf7d0 | 2019-02-12 23:05:01 -0500 | [diff] [blame] | 58 | return device_response |
Cherukuri, Venkatanaresh (vn166g) | 8df5693 | 2019-02-05 09:47:55 -0500 | [diff] [blame] | 59 | |
Alexis de Talhouët | a69b9f5 | 2019-02-18 08:08:24 -0500 | [diff] [blame] | 60 | def discard_change(self): |
| 61 | device_response = self.netconf_rpc_client.discardConfig() |
Alexis de Talhouët | 3daf7d0 | 2019-02-12 23:05:01 -0500 | [diff] [blame] | 62 | return device_response |