blob: 6f72e99252932abbe0b47a398c34c2816c691dbb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
"""managerutils module.
Supported Wrappers:-
---------------
*) ssh_connect
*) ssh_connect_allhosts
"""
import re
import ssh
from atfglobals import GlobalObj
def ssh_connect(hostkey):
"""
"""
logger = GlobalObj.getLoggerObj()
env = GlobalObj.getTestenvObj()
cm = GlobalObj.getConnectionsManagerObj()
if cm is None:
logger.error("Init ConnectionsManager")
return 1
host_connection = cm.getConnection(hostkey)
if not host_connection:
host_obj = env.getHost(hostkey)
if not host_obj:
logger.error("Invalid Host. %s is not defined in TestEnvironment"
% hostkey)
return 1
else:
host_connection = ssh.SshConnection()
if host_connection.connect(host_obj.hostname, host_obj.user,
host_obj.password):
return 1
else:
if re.match("server", hostkey, re.IGNORECASE):
cm.addServer(hostkey, host_connection)
else:
cm.addClient(hostkey, host_connection)
return 0
else:
logger.debug("Connection to %s already exist" % hostkey)
return 0
def ssh_connect_allhosts():
"""
"""
GlobalObj.initConnectionsManagerObj()
env = GlobalObj.getTestenvObj()
cm = GlobalObj.getConnectionsManagerObj()
hosts_keys = env.getHostsKeys()
for hostkey in hosts_keys:
return_status = ssh_connect(hostkey)
if return_status:
return return_status
return 0
__all__ = ['ssh_connect',
'ssh_connect_allhosts']
|