gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r22752 - in gnunet-planetlab/gplmt: . contrib
Date: Wed, 18 Jul 2012 16:13:30 +0200

Author: wachs
Date: 2012-07-18 16:13:30 +0200 (Wed, 18 Jul 2012)
New Revision: 22752

Removed:
   gnunet-planetlab/gplmt/contrib/tasks.conf
Modified:
   gnunet-planetlab/gplmt/Configuration.py
   gnunet-planetlab/gplmt/Notifications.py
   gnunet-planetlab/gplmt/Tasks.py
   gnunet-planetlab/gplmt/Worker.py
   gnunet-planetlab/gplmt/contrib/current.nodes
   gnunet-planetlab/gplmt/contrib/simpletasks.xml
   gnunet-planetlab/gplmt/contrib/test.conf
   gnunet-planetlab/gplmt/gplmt.py
Log:
- ssh command execution working

Modified: gnunet-planetlab/gplmt/Configuration.py
===================================================================
--- gnunet-planetlab/gplmt/Configuration.py     2012-07-18 14:11:47 UTC (rev 
22751)
+++ gnunet-planetlab/gplmt/Configuration.py     2012-07-18 14:13:30 UTC (rev 
22752)
@@ -29,9 +29,14 @@
         assert (None != logger)
         self.filename = filename
         self.logger = logger
+        self.notifications = ""
         self.slicename = ""
         self.taskfile = ""
         self.nodesfile = ""
+        self.ssh_add_unkown_hostkeys = False
+        self.ssh_keyfile = None
+        self.ssh_password = ""
+        self.ssh_use_known_hosts = False
     def load (self):        
         self.logger.log ("Loading configuration file '" + self.filename + "'")
 
@@ -50,10 +55,33 @@
             return False
         # optional values
         try: 
-            self.taskfile = config.get("planetlab", "tasks")
-            self.nodesfile = config.get("planetlab", "nodes")
+            # gplmt options
+            self.taskfile = config.get("gplmt", "tasks")
         except ConfigParser.NoOptionError as e:
             pass
         
+        try: 
+            self.nodesfile = config.get("gplmt", "nodes")
+        except ConfigParser.NoOptionError as e:
+            pass
+        
+        # ssh options
+        try: 
+            self.ssh_add_unkown_hostkeys = config.getboolean ("ssh", 
"add_unkown_hostkeys")
+        except ConfigParser.NoOptionError as e:
+            pass
+        try: 
+            self.ssh_use_known_hosts = config.getboolean ("ssh", 
"ssh_use_known_hosts")
+        except ConfigParser.NoOptionError as e:
+            pass
+        try: 
+            self.ssh_keyfile = config.get("ssh", "ssh_keyfile") 
+        except ConfigParser.NoOptionError as e:
+            pass
+        try: 
+            self.ssh_password = config.get("ssh", "ssh_password")
+        except ConfigParser.NoOptionError as e:
+            pass        
+        
         return True
         
\ No newline at end of file

Modified: gnunet-planetlab/gplmt/Notifications.py
===================================================================
--- gnunet-planetlab/gplmt/Notifications.py     2012-07-18 14:11:47 UTC (rev 
22751)
+++ gnunet-planetlab/gplmt/Notifications.py     2012-07-18 14:13:30 UTC (rev 
22752)
@@ -26,24 +26,41 @@
     def __init__(self, logger):
         assert (None != logger)
         self.logger = logger
+    def node_connected (self, node, success):
+        assert (0)
+    def node_disconnected (self, node, success):
+        assert (0) 
     def tasklist_started (self, node, tasks):
         assert (0)
-    def tasklist_completed (self, node, tasks):
+    def tasklist_completed (self, node, tasks, success):
         assert (0)
     def task_started (self, node, tasks):
         assert (0)
-    def task_completed (self, node, tasks):
+    def task_completed (self, node, tasks, success):
         assert (0)
         
 class SimpleNotification (Notification):
     def __init__(self, logger):
         assert (None != logger)
         self.logger = logger
+    def node_connected (self, node, success):
+        if (success == True):
+            print node + " : connected successfully"
+        else:
+            print node + " : connection failed"
+    def node_disconnected (self, node, success):
+        if (success == True):
+            print node + " : disconnected"
+        else:
+            print node + " : disconnected with failure"    
     def tasklist_started (self, node, tasks):
         print node + " : Tasklist '" +  tasks.name + "' started"
-    def tasklist_completed (self, node, tasks):
-        print node + " : Tasklist '" +  tasks.name + "' completed"
+    def tasklist_completed (self, node, tasks, success):
+        if (success == True):
+            print node + " : Tasklist '" +  tasks.name + "' completed 
successfully"
+        else:
+            print node + " : Tasklist '" +  tasks.name + "' completed with 
failure"
     def task_started (self, node, task):
         print node + " : Task '" +  task.name + "' started"
-    def task_completed (self, node, task):
+    def task_completed (self, node, task, success):
         print node + " : Task '" +  task.name + "' completed"                  
 
\ No newline at end of file

Modified: gnunet-planetlab/gplmt/Tasks.py
===================================================================
--- gnunet-planetlab/gplmt/Tasks.py     2012-07-18 14:11:47 UTC (rev 22751)
+++ gnunet-planetlab/gplmt/Tasks.py     2012-07-18 14:13:30 UTC (rev 22752)
@@ -65,7 +65,7 @@
             except ValueError:
                 print "Invalid id '"+child.text+"' for task name " + t.name
             t.id = child.text
-        if (child.tag == "type"):
+        if ((child.tag == "type") and (child.text != None)):
             if (child.text == "run"):            
                 t.type = Operation.run
             elif (child.text == "get"):            
@@ -74,9 +74,9 @@
                 t.type = Operation.put
             else:
                 t.type = Operation.none
-        if (child.tag == "command"):
+        if ((child.tag == "command") and (child.text != None)):
             t.command = child.text
-        if (child.tag == "arguments"):
+        if ((child.tag == "arguments") and (child.text != None)):
             t.arguments = child.text
         if (child.tag == "timeout"):
             try:
@@ -88,7 +88,7 @@
                 t.expected_return_code = int(child.text)
             except ValueError:
                 print "Invalid expected return code '" +child.text+ "' for 
task id " + str (t.id) + " name " + t.name            
-        if (child.tag == "stop_on_fail"):
+        if ((child.tag == "stop_on_fail") and (child.text != None)):
             t.stop_on_fail = child.text
 
     if (False == t.check()):

Modified: gnunet-planetlab/gplmt/Worker.py
===================================================================
--- gnunet-planetlab/gplmt/Worker.py    2012-07-18 14:11:47 UTC (rev 22751)
+++ gnunet-planetlab/gplmt/Worker.py    2012-07-18 14:13:30 UTC (rev 22752)
@@ -22,71 +22,130 @@
 #
 # Worker
 
+import Tasks
 import threading
-import time
+import paramiko
+import socket
+import os
 
-exitFlag = 0
-glogger = None
+# Global variables
+g_logger = None
+g_notifications = None
+g_configuration = None
 
 class NodeWorkerThread (threading.Thread):
-    def __init__(self, threadID, node, tasks, notifications):
+    def __init__(self, threadID, node, tasks):
         threading.Thread.__init__(self)
         self.threadID = threadID
         self.node = node
         self.tasks = tasks
-        self.notifications = notifications
     def run(self):
-        glogger.log (self.node + " : Starting tasklist " + self.tasks.name)
+        success = False
+        g_logger.log (self.node + " : Starting tasklist " + self.tasks.name)
         task = self.tasks.get()
+        try: 
+            ssh = paramiko.SSHClient()
+            if (g_configuration.ssh_use_known_hosts):
+                g_logger.log (self.node + " : Loading known hosts")
+                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())
+            # check for private key existance
+            keyfile = None
+            if (g_configuration.ssh_keyfile != None): 
+                if (os.path.exists (g_configuration.ssh_keyfile)):
+                    g_logger.log (self.node + " : Found " + 
g_configuration.ssh_keyfile)
+                    keyfile = g_configuration.ssh_keyfile
+                else:
+                    g_logger.log (self.node + " : Not found " + 
g_configuration.ssh_keyfile)
+                
+            g_logger.log (self.node + " : Trying to connect to " + 
+                          g_configuration.slicename + "@" + self.node + 
+                          " using password '" + g_configuration.ssh_password+ 
+                          "' and private keyfile '" +str(keyfile)+ "'")
+            ssh.connect (self.node, 
+                         username=g_configuration.slicename, 
+                         password=g_configuration.ssh_password,
+                         key_filename=keyfile) 
+        except (IOError,
+                paramiko.SSHException,
+                paramiko.BadHostKeyException, 
+                paramiko.AuthenticationException,
+                socket.error) as e:  
+            print self.node + " : Error while trying to connect: " + str(e)
+            g_notifications.node_connected (self.node, False)
+            g_notifications.tasklist_completed (self.node, self.tasks, False)
+            return
+        
+        g_notifications.node_connected (self.node, True)
+        success = True
         while (None != task):
             if (task.__class__.__name__ == "Task"):
-                glogger.log (self.node + " : Running task " + task.name)
-                self.notifications.task_started (self.node, task)
+                
+                if (task.type == Tasks.Operation.run):
+                    stdin, stdout, stderr = ssh.exec_command(task.command + " 
" + task.arguments, 1024)
+                    data = stdout.readline()
+                    print data
+                    #for line in data:
+                    #    print line
+                elif (task.type == Tasks.Operation.put):
+                    print "TO IMPLEMENT"
+                elif (task.type == Tasks.Operation.get):
+                    print "TO IMPLEMENT"
+                else:
+                    print "TO IMPLEMENT"
+                    
+                
+                g_logger.log (self.node + " : Running task " + task.name)
+                g_notifications.task_started (self.node, task)
             elif (task.__class__.__name__ == "Taskset"):
-                glogger.log (self.node + " : Running task set")
+                g_logger.log (self.node + " : Running task set")
             task = self.tasks.get()
-            time.sleep(1)
         
-        self.notifications.tasklist_completed (self.node, self.tasks)
-        glogger.log (self.node + " : All tasks done for " + self.node)
+        ssh.close()
+        g_notifications.node_disconnected (self.node, True)
+        g_notifications.tasklist_completed (self.node, self.tasks, success)
+        g_logger.log (self.node + " : All tasks done for " + self.node)
         
 
 
 class NodeWorker:
-    def __init__(self, logger, node, tasks, notifications):
-        assert (None != logger)
+    def __init__(self, node, tasks):
         assert (None != node)
         assert (None != tasks)
-        assert (None != notifications)
-        self.logger = logger
         self.node = node
         self.tasks = tasks
         self.thread = None
-        self.notifications = notifications
     def start (self):
-        self.logger.log ("Starting execution for node " + self.node)
-        self.notifications.tasklist_started (self.node, self.tasks)
-        self.thread = NodeWorkerThread (1, self.node, self.tasks, 
self.notifications)
+        g_logger.log ("Starting execution for node " + self.node)
+        g_notifications.tasklist_started (self.node, self.tasks)
+        self.thread = NodeWorkerThread (1, self.node, self.tasks)
         self.thread.start()
     
 class Worker:
-    def __init__(self, logger, nodes, tasks, notifications):
-        global glogger;
+    def __init__(self, logger, configuration, nodes, tasks, notifications):
+        global g_logger;
+        global g_configuration;
+        global g_notifications;
         assert (None != logger)
         assert (None != nodes)
         assert (None != tasks)
         assert (None != notifications)
+        assert (hasattr(notifications, 'node_connected'))
+        assert (hasattr(notifications, 'node_disconnected'))        
         assert (hasattr(notifications, 'tasklist_started'))
         assert (hasattr(notifications, 'tasklist_completed'))
         assert (hasattr(notifications, 'task_started'))
         assert (hasattr(notifications, 'task_completed'))
-        self.logger = logger
         self.nodes = nodes
         self.tasks = tasks
-        self.notifications = notifications
-        glogger = logger;
+        g_configuration = configuration
+        g_notifications = notifications
+        g_logger = logger;
     def start (self):
-        self.logger.log ("Starting execution")
+        g_logger.log ("Starting execution")
         for n in self.nodes.nodes:
-            nw = NodeWorker (self.logger, n, self.tasks.copy(), 
self.notifications)
+            nw = NodeWorker (n, self.tasks.copy())
             nw.start()

Modified: gnunet-planetlab/gplmt/contrib/current.nodes
===================================================================
--- gnunet-planetlab/gplmt/contrib/current.nodes        2012-07-18 14:11:47 UTC 
(rev 22751)
+++ gnunet-planetlab/gplmt/contrib/current.nodes        2012-07-18 14:13:30 UTC 
(rev 22752)
@@ -1,3 +1 @@
-abc.de
-def.at
-ghi.tv
\ No newline at end of file
+localhost
\ No newline at end of file

Modified: gnunet-planetlab/gplmt/contrib/simpletasks.xml
===================================================================
--- gnunet-planetlab/gplmt/contrib/simpletasks.xml      2012-07-18 14:11:47 UTC 
(rev 22751)
+++ gnunet-planetlab/gplmt/contrib/simpletasks.xml      2012-07-18 14:13:30 UTC 
(rev 22752)
@@ -2,9 +2,9 @@
 <tasklist name="Simple task list" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:noNamespaceSchemaLocation="../tasklist_schema.xsd">
   <task name="simple tasks">
         <id>0</id>
-        <name>run 1</name>
+        <name>get date</name>
         <type>run</type> 
-        <command>cat</command> 
+        <command>date</command> 
         <arguments></arguments> 
         <expected_return_code>0</expected_return_code>
         <expected_output></expected_output>

Deleted: gnunet-planetlab/gplmt/contrib/tasks.conf
===================================================================
--- gnunet-planetlab/gplmt/contrib/tasks.conf   2012-07-18 14:11:47 UTC (rev 
22751)
+++ gnunet-planetlab/gplmt/contrib/tasks.conf   2012-07-18 14:13:30 UTC (rev 
22752)
@@ -1,8 +0,0 @@
-[run cat]
-command = date
-args = 
-returncode = 0
-output = 
-stop_on_fail = 1 
-
-[run date]

Modified: gnunet-planetlab/gplmt/contrib/test.conf
===================================================================
--- gnunet-planetlab/gplmt/contrib/test.conf    2012-07-18 14:11:47 UTC (rev 
22751)
+++ gnunet-planetlab/gplmt/contrib/test.conf    2012-07-18 14:13:30 UTC (rev 
22752)
@@ -1,5 +1,27 @@
+[gplmt]
+nodes = contrib/current.nodes
+tasks = contrib/simpletasks.xml
+# Which notification mechanism to use: 
+# simple: print messages to stdout
+notification = simple
+#tasks = contrib/tasks.xml
+
+
 [planetlab]
-slice = tum_dht_testing
-nodes = contrib/current.nodes
-#tasks = contrib/simpletasks.xml
-tasks = contrib/tasks.xml
+slice = mwachs
+
+[ssh]
+# Order of ssh authentication:
+#
+# The ssh_keyfile_filename passed in (if any)
+# Any key we can find through an SSH agent
+# Any "id_rsa" or "id_dsa" key discoverable in ~/.ssh/
+# Plain password auth, if a ssh_password was given
+
+#ssh_keyfile = <keyfile>
+ssh_password = <password>
+
+# Use system's SSH "known hosts" file
+ssh_use_known_hosts = yes
+# Add node hostkeys automatically
+add_unkown_hostkeys = yes
\ No newline at end of file

Modified: gnunet-planetlab/gplmt/gplmt.py
===================================================================
--- gnunet-planetlab/gplmt/gplmt.py     2012-07-18 14:11:47 UTC (rev 22751)
+++ gnunet-planetlab/gplmt/gplmt.py     2012-07-18 14:13:30 UTC (rev 22752)
@@ -122,10 +122,13 @@
         sys.exit(2)        
 
 # Set up notifications
-    notifications = Notifications.SimpleNotification (main.logger)
+    if (configuration.notifications == "simple"):
+        notifications = Notifications.SimpleNotification (main.logger)
+    else:
+        notifications = Notifications.SimpleNotification (main.logger)
 
 # Start execution
-    worker = Worker.Worker (main.logger, nodes, tasks, notifications)
+    worker = Worker.Worker (main.logger, configuration, nodes, tasks, 
notifications)
     worker.start()
 # Clean up
 




reply via email to

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