gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r28180 - in gnunet-planetlab/gplmt: . gplmt


From: gnunet
Subject: [GNUnet-SVN] r28180 - in gnunet-planetlab/gplmt: . gplmt
Date: Fri, 19 Jul 2013 09:41:33 +0200

Author: wachs
Date: 2013-07-19 09:41:33 +0200 (Fri, 19 Jul 2013)
New Revision: 28180

Modified:
   gnunet-planetlab/gplmt/gplmt.py
   gnunet-planetlab/gplmt/gplmt/Worker.py
Log:
ssh exec working


Modified: gnunet-planetlab/gplmt/gplmt/Worker.py
===================================================================
--- gnunet-planetlab/gplmt/gplmt/Worker.py      2013-07-19 07:30:11 UTC (rev 
28179)
+++ gnunet-planetlab/gplmt/gplmt/Worker.py      2013-07-19 07:41:33 UTC (rev 
28180)
@@ -31,6 +31,7 @@
 import signal
 import inspect
 
+
 try:
     import gplmt.Configuration as Configuration
     import gplmt.Util as Util
@@ -232,14 +233,18 @@
 
 class RemoteSSHWorker (AbstractWorker):
     def connect (self):
+        self.ssh = None
+        if (interrupt):
+            return TaskExecutionResult(Tasks.Taskresult.user_interrupt, 
"interrupted by user", "")            
         try: 
-            ssh = paramiko.SSHClient()
+            self.ssh = paramiko.SSHClient()
+            
             if (g_configuration.ssh_use_known_hosts):
                 g_logger.log (self.node.hostname + " : Loading known hosts")
-                ssh.load_system_host_keys ()
+                self.ssh.load_system_host_keys ()
             # Automatically add new hostkeys
             if (g_configuration.ssh_add_unkown_hostkeys == True):
-                ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
+                self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
             # check for private key existance
             keyfile = None
             if (g_configuration.ssh_keyfile != None): 
@@ -250,52 +255,55 @@
                     g_logger.log (self.node.hostname + " : Not found " + 
g_configuration.ssh_keyfile)
             g_logger.log (self.node.hostname + " : Trying to connect to '" 
+Util.print_ssh_connection (self.node) + "'")
             if self.node.username is not None: #credentials are supplied in 
node file
-                if (self.node.password is not None):                    
-                    ssh.connect (self.node.hostname,
+                if (self.node.password is not None):
+                    print "Using node information " + self.node.username + " " 
+self.node.password                      
+                    self.ssh.connect (self.node.hostname,
                                 port=self.node.port or 22,
                                 username=self.node.username,
                                 password=self.node.password,
                                 timeout=10)
                 else:
-                    ssh.connect (self.node.hostname,
+                    print "Using node information " + self.node.username 
+                    self.ssh.connect (self.node.hostname,
                                  port=self.node.port or 22,
                                  username=self.node.username,
                                  timeout=10)                                   
     
             elif ("" != g_configuration.ssh_username):
-                g_logger.log (self.node.hostname + " : Using private keyfile 
'" +str(keyfile)+ "'")
-                ssh.connect (self.node.hostname,
+                print "Using node information " + g_configuration.ssh_username 
 + " " + g_configuration.ssh_password 
+                self.ssh.connect (self.node.hostname,
                          port=self.node.port or 22,
                          username=g_configuration.ssh_username, 
                          password=g_configuration.ssh_password,
                          timeout=10,
                          key_filename=keyfile)
             elif ("" != g_configuration.ssh_password):
-                g_logger.log (self.node.hostname + " : Trying to connect to " 
+ 
-                              self.node.hostname + 
-                              " using password '" + 
g_configuration.ssh_password+ 
-                              "' and private keyfile '" +str(keyfile)+ "'")
-                ssh.connect (self.node.hostname,
+                print "Using node information " + g_configuration.ssh_password
+                self.ssh.connect (self.node.hostname,
                              port=self.node.port or 22,
-                             password=g_configuration.ssh_password,
+                             password=g_configuration.self.ssh_password,
                              timeout=10,
                              key_filename=keyfile)
             else:
-                ssh.connect (self.node.hostname,
+                print "Using no information"
+                self.ssh.connect (self.node.hostname,
                              port=self.node.port or 22,
                              timeout=10,
                              key_filename=keyfile)
-            self.transport = ssh.get_transport()                         
+            self.transport = self.ssh.get_transport()                         
         except (IOError,
                 paramiko.SSHException,
                 paramiko.BadHostKeyException, 
                 paramiko.AuthenticationException,
                 socket.error) as e:  
             g_logger.log (self.node.hostname + " : Error while trying to 
connect: " + str(e))
-            return False
+            return TaskExecutionResult (Tasks.Taskresult.fail, str(e), "")
         g_logger.log (self.node.hostname + " : Connected!")
-        return True
+        return TaskExecutionResult (Tasks.Taskresult.success, "", "")
     def disconnect (self):       
-        raise NotImplementedError (inspect.stack()[0][3])     
+        if ((None == self.ssh) or (None == self.transport)):
+            return TaskExecutionResult (Tasks.Taskresult.fail, "", "")
+        self.ssh.close()
+        return TaskExecutionResult (Tasks.Taskresult.success, "", "")
     def exec_run_per_host (self, task):
         raise NotImplementedError (inspect.stack()[0][3]) 
     def exec_run (self, task):
@@ -314,12 +322,10 @@
             channel = self.transport.open_session()
             channel.settimeout(1.0)
             channel.get_pty ()
-            #print self.node + " CMD: " + task.command + " " + task.arguments
-            channel.exec_command(task.command + " " + task.arguments)
-            
+            channel.exec_command(task.command + " " + task.arguments)          
  
         except SSHException as e:
-            g_logger.log (self.node.hostname + " : Error while trying to 
connect: " + str(e))
-        
+            g_logger.log (self.node.hostname + " : Error while trying to 
execute: " + str(e))
+            return TaskExecutionResult(Tasks.Taskresult.fail, str(e), "") 
         if (task.timeout > 0):
             timeout = task.timeout
         else:
@@ -398,9 +404,7 @@
         else: 
             message = "'"+ task.name +  "' failed"
             g_logger.log (self.node.hostname + " : Task "+ message)
-        return TaskExecutionResult(result, message, output)
-
-        return TaskExecutionResult(Tasks.Taskresult.success, "exec_run 
successful", "")   
+        return TaskExecutionResult(result, message, output)  
     def exec_put (self):
         raise NotImplementedError (inspect.stack()[0][3]) 
     def exec_get (self):

Modified: gnunet-planetlab/gplmt/gplmt.py
===================================================================
--- gnunet-planetlab/gplmt/gplmt.py     2013-07-19 07:30:11 UTC (rev 28179)
+++ gnunet-planetlab/gplmt/gplmt.py     2013-07-19 07:41:33 UTC (rev 28180)
@@ -25,6 +25,7 @@
 # Checking dependencies
 # ElementTree XML Parser
 import sys
+import getopt, getpass
 
 try: 
     from elementtree import ElementTree
@@ -49,9 +50,8 @@
     import gplmt.Tasks as Tasklist
     import gplmt.Worker as Worker
     import gplmt.Notifications as Notifications
-    import getopt, getpass
 except ImportError as e: 
-    print "That's a bug! please check README: " +  __file__+ " " + str (e)
+    print "That's a bug! please check README: '" +  __file__+ "' " + str (e)
     imports = False
     
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]