You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by se...@apache.org on 2013/06/20 18:56:30 UTC

git commit: updated refs/heads/master to fa58080

Updated Branches:
  refs/heads/master 30c6e2707 -> fa5808080


remoteSSHClient cleansed


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/fa580808
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/fa580808
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/fa580808

Branch: refs/heads/master
Commit: fa580808070c8ece13056b34d772858ee573d0e6
Parents: 30c6e27
Author: Daan Hoogland <dh...@schubergphilis.com>
Authored: Thu Jun 20 16:27:50 2013 +0200
Committer: Sebastien Goasguen <ru...@gmail.com>
Committed: Thu Jun 20 12:56:18 2013 -0400

----------------------------------------------------------------------
 tools/marvin/marvin/remoteSSHClient.py | 58 +++++++++++++++++------------
 1 file changed, 34 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fa580808/tools/marvin/marvin/remoteSSHClient.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/remoteSSHClient.py b/tools/marvin/marvin/remoteSSHClient.py
index 04450fd..597fc65 100644
--- a/tools/marvin/marvin/remoteSSHClient.py
+++ b/tools/marvin/marvin/remoteSSHClient.py
@@ -5,9 +5,9 @@
 # to you under the Apache License, Version 2.0 (the
 # "License"); you may not use this file except in compliance
 # with the License.  You may obtain a copy of the License at
-# 
+#
 #   http://www.apache.org/licenses/LICENSE-2.0
-# 
+#
 # Unless required by applicable law or agreed to in writing,
 # software distributed under the License is distributed on an
 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -15,15 +15,17 @@
 # specific language governing permissions and limitations
 # under the License.
 
-import paramiko 
+import paramiko
 import time
 import cloudstackException
 import contextlib
 import logging
 from contextlib import closing
 
+
 class remoteSSHClient(object):
-    def __init__(self, host, port, user, passwd, retries = 10, log_lvl=logging.INFO, keyPairFileLocation=None):
+    def __init__(self, host, port, user, passwd, retries=10,
+                 log_lvl=logging.INFO, keyPairFileLocation=None):
         self.host = host
         self.port = port
         self.user = user
@@ -39,29 +41,36 @@ class remoteSSHClient(object):
         retry_count = retries
         while True:
             try:
-                if keyPairFileLocation == None:
-                    self.ssh.connect(str(host),int(port), user, passwd)
-                    self.logger.debug("SSH connect: %s@%s with passwd %s"%(user, str(host), passwd))
+                if keyPairFileLocation is None:
+                    self.ssh.connect(str(host), int(port), user, passwd)
+                    self.logger.debug("SSH connect: %s@%s with passwd %s" %
+                                      (user, str(host), passwd))
                 else:
-                    self.ssh.connect(
-                                        hostname=str(host),
-                                        port=int(port),
-                                        username=str(user),
-                                        key_filename=str(keyPairFileLocation),
-                                        look_for_keys=False
-                                    )
-                    self.logger.debug("connecting to server %s with user %s key %s"%(str(host), user, keyPairFileLocation))
-                    self.logger.debug("SSH connect: %s@%s with passwd %s"%(user, str(host), passwd))
+                    self.ssh.connect(hostname=str(host),
+                                     port=int(port),
+                                     username=str(user),
+                                     key_filename=str(keyPairFileLocation),
+                                     look_for_keys=False
+                                     )
+                    self.logger.debug(
+                        "connecting to server %s with user %s key %s" %
+                        (str(host), user, keyPairFileLocation))
+                    self.logger.debug("SSH connect: %s@%s with passwd %s" %
+                                      (user, str(host), passwd))
             except paramiko.SSHException, sshex:
                 if retry_count == 0:
-                    raise cloudstackException.InvalidParameterException(repr(sshex))
+                    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))
+                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)
         output = stdout.readlines()
@@ -71,16 +80,17 @@ class remoteSSHClient(object):
             if errors is not None and len(errors) > 0:
                 for error in errors:
                     results.append(error.rstrip())
-            
+
         else:
             for strOut in output:
                 results.append(strOut.rstrip())
-        self.logger.debug("{Cmd: %s via Host: %s} {returns: %s}"%(command, str(self.host), results))
+        self.logger.debug("{Cmd: %s via Host: %s} {returns: %s}" %
+                          (command, str(self.host), results))
         return results
-    
+
     def scp(self, srcFile, destPath):
         transport = paramiko.Transport((self.host, int(self.port)))
-        transport.connect(username = self.user, password=self.passwd)
+        transport.connect(username=self.user, password=self.passwd)
         sftp = paramiko.SFTPClient.from_transport(transport)
         try:
             sftp.put(srcFile, destPath)
@@ -90,7 +100,7 @@ class remoteSSHClient(object):
     def close(self):
         self.ssh.close()
 
-            
+
 if __name__ == "__main__":
     with contextlib.closing(remoteSSHClient("10.223.75.10", 22, "root",
                                             "password")) as ssh: