MCPcopy Create free account
hub / github.com/apache/cloudstack / SshClient

Class SshClient

tools/marvin/marvin/sshClient.py:38–209  ·  view source on GitHub ↗

@Desc : SSH Library for Marvin. Facilitates SSH,SCP services to marvin users @Input: host: Host to connect port: port on host to connect user: Username to be used for connecting passwd: Password for connection retries and delay applies for

Source from the content-addressed store, hash-verified

36
37
38class SshClient(object):
39
40 '''
41 @Desc : SSH Library for Marvin.
42 Facilitates SSH,SCP services to marvin users
43 @Input: host: Host to connect
44 port: port on host to connect
45 user: Username to be used for connecting
46 passwd: Password for connection
47 retries and delay applies for establishing connection
48 timeout : Applies while executing command
49 '''
50
51 def __init__(self, host, port, user, passwd, retries=60, delay=10,
52 log_lvl=logging.DEBUG, keyPairFiles=None, timeout=10.0):
53 self.host = None
54 self.port = 22
55 self.user = user
56 self.passwd = passwd
57 self.keyPairFiles = keyPairFiles
58 self.ssh = SSHClient()
59 self.ssh.set_missing_host_key_policy(AutoAddPolicy())
60 self.logger = logging.getLogger('sshClient')
61 self.retryCnt = 0
62 self.delay = 0
63 self.timeout = 3.0
64 self.ch = logging.StreamHandler()
65 self.ch.setLevel(log_lvl)
66 self.logger.addHandler(self.ch)
67
68 # Check invalid host value and raise exception
69 # Atleast host is required for connection
70 if host is not None and host != '':
71 self.host = host
72 if retries is not None and retries > 0:
73 self.retryCnt = retries
74 if delay is not None and delay > 0:
75 self.delay = delay
76 if timeout is not None and timeout > 0:
77 self.timeout = timeout
78 if port is not None and port >= 0:
79 self.port = port
80 if self.createConnection() == FAILED:
81 raise internalError("SSH Connection Failed")
82
83 def execute(self, command):
84 stdin, stdout, stderr = self.ssh.exec_command(command)
85 output = stdout.readlines()
86 errors = stderr.readlines()
87 results = []
88 if output is not None and len(output) == 0:
89 if errors is not None and len(errors) > 0:
90 for error in errors:
91 results.append(error.rstrip())
92
93 else:
94 for strOut in output:
95 results.append(strOut.rstrip())

Callers 15

test_DeployVmMethod · 0.90
_execute_ssh_commandFunction · 0.90
is_server_ssh_readyFunction · 0.90
is_snapshot_on_nfsFunction · 0.90
createChecksumFunction · 0.90
compareChecksumFunction · 0.90
test_01_elb_createMethod · 0.90

Calls

no outgoing calls