Add additional retries to the SSH client by default

This commit is contained in:
Prasanna Santhanam 2012-05-15 16:54:08 +05:30
parent d82158d0ae
commit 0c26f359ce
3 changed files with 20 additions and 14 deletions

View File

@ -10,15 +10,12 @@
# limitations under the License.
#
# Automatically generated by addcopyright.py at 04/03/2012
try:
import unittest2 as unittest
except ImportError:
import unittest
from functools import partial
import unittest
import os
import sys
import logging
from functools import partial
def testCaseLogger(message, logger=None):
if logger is not None:

View File

@ -11,10 +11,7 @@
#
# Automatically generated by addcopyright.py at 04/03/2012
from cloudstackAPI import *
try:
import unittest2 as unittest
except ImportError:
import unittest
import unittest
import cloudstackTestClient
#class UserName(object):

View File

@ -11,19 +11,31 @@
#
# Automatically generated by addcopyright.py at 04/03/2012
import paramiko
import time
import cloudstackException
class remoteSSHClient(object):
def __init__(self, host, port, user, passwd):
def __init__(self, host, port, user, passwd, retries = 10):
self.host = host
self.port = port
self.user = user
self.passwd = passwd
self.ssh = paramiko.SSHClient()
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
self.ssh.connect(str(host),int(port), user, passwd)
except paramiko.SSHException, sshex:
raise cloudstackException.InvalidParameterException(repr(sshex))
retry_count = retries
while True:
try:
self.ssh.connect(str(host),int(port), user, passwd)
except paramiko.SSHException, sshex:
if retry_count == 0:
raise cloudstackException.InvalidParameterException(repr(sshex))
retry_count = retry_count - 1
time.sleep(5)
except paramiko.AuthenticationException, authEx:
raise cloudstackException.InvalidParameterException("Invalid credentials to login to %s on port %s"%(str(host), port))
else:
return
def execute(self, command):
stdin, stdout, stderr = self.ssh.exec_command(command)