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 | a69b9f5 | 2019-02-18 08:08:24 -0500 | [diff] [blame^] | 38 | def commit(self): |
| 39 | device_response = self.netconf_rpc_client.commit() |
Alexis de Talhouët | 3daf7d0 | 2019-02-12 23:05:01 -0500 | [diff] [blame] | 40 | return device_response |
Cherukuri, Venkatanaresh (vn166g) | 8df5693 | 2019-02-05 09:47:55 -0500 | [diff] [blame] | 41 | |
Alexis de Talhouët | a69b9f5 | 2019-02-18 08:08:24 -0500 | [diff] [blame^] | 42 | def unlock(self, config_target=CONFIG_TARGET_CANDIDATE): |
| 43 | device_response = self.netconf_rpc_client.unLock(config_target) |
Alexis de Talhouët | 3daf7d0 | 2019-02-12 23:05:01 -0500 | [diff] [blame] | 44 | return device_response |
Cherukuri, Venkatanaresh (vn166g) | 8df5693 | 2019-02-05 09:47:55 -0500 | [diff] [blame] | 45 | |
Alexis de Talhouët | a69b9f5 | 2019-02-18 08:08:24 -0500 | [diff] [blame^] | 46 | def validate(self, config_target=CONFIG_TARGET_CANDIDATE): |
| 47 | device_response = self.netconf_rpc_client.validate(config_target) |
Alexis de Talhouët | 3daf7d0 | 2019-02-12 23:05:01 -0500 | [diff] [blame] | 48 | return device_response |
Cherukuri, Venkatanaresh (vn166g) | 8df5693 | 2019-02-05 09:47:55 -0500 | [diff] [blame] | 49 | |
Alexis de Talhouët | a69b9f5 | 2019-02-18 08:08:24 -0500 | [diff] [blame^] | 50 | def discard_change(self): |
| 51 | device_response = self.netconf_rpc_client.discardConfig() |
Alexis de Talhouët | 3daf7d0 | 2019-02-12 23:05:01 -0500 | [diff] [blame] | 52 | return device_response |