summaryrefslogtreecommitdiffstats
path: root/SharedModules/Utils/managerutils.py
diff options
context:
space:
mode:
Diffstat (limited to 'SharedModules/Utils/managerutils.py')
-rw-r--r--SharedModules/Utils/managerutils.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/SharedModules/Utils/managerutils.py b/SharedModules/Utils/managerutils.py
new file mode 100644
index 0000000..ca38b3f
--- /dev/null
+++ b/SharedModules/Utils/managerutils.py
@@ -0,0 +1,55 @@
+"""managerutils module.
+
+Supported Wrappers:-
+---------------
+*) ssh_connect
+*) ssh_connect_allhosts
+"""
+
+import re
+import ssh
+from atfglobals import GlobalObj
+
+def ssh_connect(hostkey):
+ """
+ """
+ env = GlobalObj.getTestenvObj()
+ cm = GlobalObj.getConnectionsManagerObj()
+ host_connection = cm.getConnection(hostkey)
+ if not host_connection:
+ host_obj = env.getHost(hostkey)
+ if not host_obj:
+ print "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:
+ print "Connection to %s already exist" % hostkey
+
+ return 0
+
+def ssh_connect_allhosts():
+ """
+ """
+ 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']
+