Refactoring code to adhere to persistence connection. (#44398)

* Refactoring code to adhere to persistence connection.

* Update cnos_rollback.py

* Review comment of Qalthos incorporated

* Updating license for the refactored method

* Update cnos_rollback.py

* Removing the BSD License as suggested by Legal
This commit is contained in:
Anil Kumar Muraleedharan 2018-08-30 00:55:19 +05:30 committed by Nathaniel Case
commit 822dbe3016
2 changed files with 108 additions and 281 deletions

View file

@ -1327,204 +1327,6 @@ def interfaceLevel2Config(module, cmd, prompt, answer):
# EOM
def doStartUpConfigRollback(
protocol, timeout, confServerIp, confPath, confServerUser,
confServerPwd, obj):
# server = "10.241.105.214"
server = confServerIp
# username = "pbhosale"
username = confServerUser
# password = "Lab4man1"
password = confServerPwd
if((confPath is None) or (confPath is "")):
confPath = "cnos_config"
retVal = ""
# config backup command happens here
if(protocol == "ftp"):
command = "cp " + protocol + " " + protocol + "://" + username + \
"@" + server + "/" + confPath + " startup-config vrf management\n"
# debugOutput(command)
retVal = retVal + waitForDeviceResponse(command, "Password:", 3, obj)
# debugOutput(command)
retVal = retVal + waitForDeviceResponse(command, "[n]", timeout, obj)
command = "y\n"
retVal = retVal + waitForDeviceResponse(password, "#", timeout, obj)
elif(protocol == "tftp"):
command = "cp " + protocol + " " + protocol + "://" + \
server + "/" + confPath + " startup-config vrf management\n"
# debugOutput(command)
retVal = retVal + waitForDeviceResponse(command, "[n]", timeout, obj)
command = "y\n"
retVal = retVal + waitForDeviceResponse(command, "#", timeout, obj)
else:
return "Error-110"
return retVal
# EOM
# Utility Method to restore the start up config
# This method supports only SCP or SFTP
# Tuning of timeout parameter is pending
def doSecureStartUpConfigRollback(
protocol, timeout, confServerIp, confPath, confServerUser,
confServerPwd, obj):
# server = "10.241.105.214"
server = confServerIp
# username = "pbhosale"
username = confServerUser
# password = "Lab4man1"
password = confServerPwd
if((confPath is None) or (confPath is "")):
confPath = "cnos_config"
retVal = ""
# config backup command happens here
# cp sftp sftp://root@10.241.106.118/cnos_config/running_config.conf
# startup-config vrf management
command = "cp " + protocol + " " + protocol + "://" + username + \
"@" + server + "/" + confPath + " startup-config vrf management \n"
# debugOutput(command)
response = waitForDeviceResponse(command, "(yes/no)", 3, obj)
if(response.lower().find('error-101')):
command = password + "\n"
retVal = retVal + waitForDeviceResponse(command, "[n]", timeout, obj)
command = "y\n"
retVal = retVal + waitForDeviceResponse(command, "#", timeout, obj)
return retVal
retVal = retVal + response
if(protocol == "scp"):
command = "yes \n"
# debugOutput(command)
retVal = retVal + waitForDeviceResponse(command, "timeout:", 3, obj)
command = "0\n"
# debugOutput(command)
retVal = retVal + waitForDeviceResponse(command, "Password:", 3, obj)
elif(protocol == "sftp"):
command = "yes \n"
# debugOutput(command)
retVal = retVal + waitForDeviceResponse(command, "Password:", 3, obj)
else:
return "Error-110"
# Password entry happens here
# debugOutput(command)
command = password + "\n"
retVal = retVal + waitForDeviceResponse(command, "[n]", timeout, obj)
command = "y\n"
retVal = retVal + waitForDeviceResponse(command, "#", timeout, obj)
return retVal
# EOM
def doRunningConfigRollback(
protocol, timeout, confServerIp, confPath, confServerUser,
confServerPwd, obj):
# server = "10.241.105.214"
server = confServerIp
# username = "pbhosale"
username = confServerUser
# password = "Lab4man1"
password = confServerPwd
if((confPath is None) or (confPath is "")):
confPath = "cnos_config"
retVal = ""
# config backup command happens here
if(protocol == "ftp"):
command = "cp " + protocol + " " + protocol + "://" + username + \
"@" + server + "/" + confPath + " running-config vrf management\n"
# debugOutput(command)
retVal = retVal + waitForDeviceResponse(command, "Password:", 3, obj)
# debugOutput(command)
retVal = retVal + waitForDeviceResponse(password, "#", timeout, obj)
elif(protocol == "tftp"):
command = "cp " + protocol + " " + protocol + "://" + \
server + "/" + confPath + " running-config vrf management\n"
# debugOutput(command)
retVal = retVal + waitForDeviceResponse(command, "#", timeout, obj)
else:
return "Error-110"
return retVal
# EOM
# Utility Method to restore the running config
# This method supports only SCP or SFTP
# Tuning of timeout parameter is pending
def doSecureRunningConfigRollback(
protocol, timeout, confServerIp, confPath, confServerUser,
confServerPwd, obj):
# server = "10.241.105.214"
server = confServerIp
# username = "pbhosale"
username = confServerUser
# password = "Lab4man1"
password = confServerPwd
if((confPath is None) or (confPath is "")):
confPath = "cnos_config"
retVal = ""
# config backup command happens here
# cp sftp sftp://root@10.241.106.118/cnos_config/running_config.conf
# running-config vrf management
command = "cp " + protocol + " " + protocol + "://" + username + \
"@" + server + "/" + confPath + " running-config vrf management \n"
# debugOutput(command)
response = waitForDeviceResponse(command, "(yes/no)", 3, obj)
if(response.lower().find('error-101')):
command = password + "\n"
retVal = retVal + waitForDeviceResponse(command, "#", timeout, obj)
return retVal
retVal = retVal + response
if(protocol == "scp"):
command = "yes \n"
# debugOutput(command)
retVal = retVal + waitForDeviceResponse(command, "timeout:", 3, obj)
command = "0\n"
# debugOutput(command)
retVal = retVal + waitForDeviceResponse(command, "Password:", 3, obj)
elif(protocol == "sftp"):
command = "yes \n"
# debugOutput(command)
retVal = retVal + waitForDeviceResponse(command, "Password:", 3, obj)
else:
return "Error-110"
# Password entry happens here
# debugOutput(command)
command = password + "\n"
retVal = retVal + waitForDeviceResponse(command, "#", timeout, obj)
return retVal
# EOM
# Utility Method to download an image from FTP/TFTP server to device.
# This method supports only FTP or TFTP
# Tuning of timeout parameter is pending