Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring code to adhere to persistence connection. #44398

Merged
merged 6 commits into from
Aug 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
198 changes: 0 additions & 198 deletions lib/ansible/module_utils/network/cnos/cnos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down