Cherukuri, Venkatanaresh (vn166g) | 9a4387c | 2019-02-05 09:47:55 -0500 | [diff] [blame] | 1 | from netconf_constant import CONFIG_TARGET_RUNNING, CONFIG_DEFAULT_OPERATION_REPLACE |
| 2 | |
| 3 | |
| 4 | |
| 5 | class NetconfClient: |
| 6 | |
Muthuramalingam, Brinda Santh | 0928983 | 2019-02-12 15:26:19 -0500 | [diff] [blame^] | 7 | def __init__(self, log, componentFunction): |
Cherukuri, Venkatanaresh (vn166g) | 9a4387c | 2019-02-05 09:47:55 -0500 | [diff] [blame] | 8 | self.log = log |
Muthuramalingam, Brinda Santh | 0928983 | 2019-02-12 15:26:19 -0500 | [diff] [blame^] | 9 | self.componentFunction = componentFunction |
| 10 | self.nc = None |
| 11 | |
| 12 | def createRPCServiceFromRequirement(self, requirementName): |
| 13 | self.nc = self.componentFunction.netconfRpcClientService(requirementName) |
Cherukuri, Venkatanaresh (vn166g) | 9a4387c | 2019-02-05 09:47:55 -0500 | [diff] [blame] | 14 | |
| 15 | def disconnect(self): |
| 16 | self.nc.disconnect() |
| 17 | return |
| 18 | |
Muthuramalingam, Brinda Santh | 0928983 | 2019-02-12 15:26:19 -0500 | [diff] [blame^] | 19 | def connect(self, deviceInfo): |
Cherukuri, Venkatanaresh (vn166g) | 9a4387c | 2019-02-05 09:47:55 -0500 | [diff] [blame] | 20 | self.nc.connect(deviceInfo) |
| 21 | return |
| 22 | |
| 23 | def lock(self, messageId, configTarget, messageTimeout=30): |
| 24 | deviceResponse = self.nc.lock(messageId, configTarget, messageTimeout) |
| 25 | return deviceResponse |
| 26 | |
| 27 | def getConfig(self, messageId, filter, configTarget=CONFIG_TARGET_RUNNING, messageTimeout=30): |
| 28 | self.log.info("in the ncclient getConfig {}",messageId) |
| 29 | self.log.info("in the ncclient getConfig {}",filter) |
| 30 | deviceResponse = self.nc.getConfig(messageId, filter, configTarget, messageTimeout) |
| 31 | return deviceResponse |
| 32 | |
| 33 | def editConfig(self, messageId, messageContent, reConnect=False, wait=0, lock=False, |
| 34 | configTarget=CONFIG_TARGET_RUNNING, editDefaultOperation=CONFIG_DEFAULT_OPERATION_REPLACE, |
| 35 | deleteConfig= False, validate= False, commit=False, discardChanges =True, unlock=False, |
| 36 | preRestartWait=0, postRestartWait=0, messageTimeout=30): |
| 37 | deviceResponse = self.nc.editConfig(messageId, messageContent, reConnect, wait, lock, configTarget, |
| 38 | editDefaultOperation, deleteConfig, validate, commit, discardChanges, unlock, |
| 39 | preRestartWait, postRestartWait, messageTimeout) |
| 40 | return deviceResponse |
| 41 | |
| 42 | def commit(self, messageId, message, discardChanges =True, messageTimeout=30): |
| 43 | deviceResponse = self.nc.commit(messageId, message, discardChanges, messageTimeout) |
| 44 | return deviceResponse |
| 45 | |
| 46 | def unLock(self, messageId, configTarget, messageTimeout=30): |
| 47 | deviceResponse = self.nc.unLock(messageId, configTarget, messageTimeout) |
| 48 | return deviceResponse |
| 49 | |
| 50 | def discardChanges(self, messageId, messageTimeout=30): |
| 51 | deviceResponse = self.nc.discardChanges(messageId, messageTimeout) |
| 52 | return deviceResponse |
| 53 | |
| 54 | def close(self, messageId, force=False, messageTimeout=30): |
| 55 | deviceResponse = self.nc.close(messageId, force, messageTimeout) |
| 56 | return deviceResponse |
| 57 | |
| 58 | def rpc(self, request, messageId, messageTimeout=30): |
| 59 | deviceResponse = self.nc.rpc(request, messageId, messageTimeout) |
| 60 | return deviceResponse |