small changes for Commander
authorMarius Sandu-Popa <sandupopamarius@gmail.com>
Sat, 10 Apr 2010 15:09:47 +0000 (18:09 +0300)
committerMarius Sandu-Popa <sandupopamarius@gmail.com>
Sat, 10 Apr 2010 15:10:12 +0000 (18:10 +0300)
autorun/commander/Commander.py
autorun/commander/SSHCommander.py
autorun/xml/nodes.xml

index e2b6d64..ccf595e 100644 (file)
@@ -19,7 +19,7 @@ class Commander(Thread):
                self.tc = TrafficControl("openvz");
                self.sshc = paramiko.SSHClient()
                self.sshc.set_missing_host_key_policy(paramiko.AutoAddPolicy())
-               self.sshc.load_system_host_keys()
+               #self.sshc.load_system_host_keys()
                self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                
        def sendSSHComm(self, hostname, username, port, comm):
@@ -45,11 +45,11 @@ class Commander(Thread):
        def sendComm(self, hostname, port, msg_type, config_data):
                try:
                        self.sock.connect((hostname, port))
-                       self.send(msg_type)
-                       response = self.recv_msg()
+                       self.sendMsg(msg_type)
+                       response = self.recvMsg()
                        if response == ACK_MSG:
                                self.sendMsg(pickle.dumps(config_data))
-                               response = self.recv_msg()
+                               response = self.recvMsg()
                        print "->>>>>>>>>>>>>>>>>>>>>>>>>", response
                except Exception as e:
                        print e
@@ -61,21 +61,21 @@ class Commander(Thread):
                while totalsent < len(msg):
                        sent = self.sock.send(msg[totalsent:])
                        if sent == 0:
-                               raise RuntimeError,     "socket connection broken"
+                               raise RuntimeError, "socket connection broken"
                        totalsent = totalsent + sent
        
        def recvMsg(self):
                msg = ''
                chunk = self.sock.recv(MSGLEN)
                if chunk == '':
-                       raise RuntimeError,     "socket connection broken"
+                       raise RuntimeError, "socket connection broken"
                msg = msg + chunk
                
                return msg
                        
        def startDaemon(self, node):
                print node.daemon_dir
-               comm = "PYTHONPATH=/home/p2p/cs-p2p-next/bt_comm:/home/p2p/cs-p2p-next/bt_comm/start-clients/ python /home/p2p/cs-p2p-next/bt_comm/server/Server.py start " + node.public_address + " " + node.listen_port
+               comm = "python " + node.daemon_dir + "Server.py start " + node.public_address + " " + node.listen_port
                print comm
                #self.printDummyCommand(node.public_address, node.public_port, node.ssh_port, comm)
                self.sendSSHComm(node.public_address, node.username, int(node.ssh_port), comm)
@@ -97,17 +97,16 @@ class Commander(Thread):
                base_path = node.getClientBaseDir(si.btclient)
                torrent_file = self.swarm.getTorrentFile()
                
-               config_data = {CLIENT : si.btclient, 
-                                       BASE_DIR : base_path, 
-                                       UP_LIMIT : si.download_limit,
-                                       DL_LIMIT : si.upload_limit,
-                                       PORT : node.public_port,
-                                       DL_DIR : si.download_dir, 
-                                       LOG_DIR : si.log_dir, 
-                                       OUT_FILE : si.output_file,
-                                       LOG_FILE : si.log_file,
-                                       TORRENT : torrent_file
-                                       }
+               config_data = { CLIENT : si.btclient, 
+                               BASE_DIR : base_path, 
+                               UP_LIMIT : si.download_limit,
+                               DL_LIMIT : si.upload_limit,
+                               PORT : node.public_port,
+                               DL_DIR : si.download_dir, 
+                               LOG_DIR : si.log_dir, 
+                               OUT_FILE : si.output_file,
+                               LOG_FILE : si.log_file,
+                               TORRENT : torrent_file }
                
                self.printDummyCommand(node.public_address, node.listen_port, START_MSG, config_data)
                self.sendComm(node.public_address, int(node.listen_port), START_MSG, config_data)
index 25bfcac..5130f8b 100644 (file)
@@ -7,22 +7,32 @@ class SSHCommander:
                #self.sshclient = paramiko.Transport((hostname, port))
                self.sshclient = paramiko.SSHClient()
                self.sshclient.set_missing_host_key_policy(paramiko.AutoAddPolicy())
-               self.sshclient.load_system_host_keys()
-               #~ transport = paramiko.Transport((host, port))
-               #pkey_file = os.path.expanduser('~/.ssh/id_rsa')
-               #self.pkey = paramiko.RSAKey.from_private_key_file(pkey_file)
+               #self.sshclient.load_system_host_keys()
+               #transport = paramiko.Transport((hostname, port))
+               pkey_file = os.path.expanduser('~/.ssh/id_rsa')
+               self.pkey = paramiko.RSAKey.from_private_key_file(pkey_file)
                self.hostname = hostname
                self.username = username
                self.port = port
        
        def connect(self):
-               self.sshclient.connect(hostname=self.hostname, username=self.username, port=self.port)
-               #self.sshclient.connect(username=self.username, pkey=self.pkey)
+               try:
+                       self.sshclient.connect(hostname=self.hostname, username=self.username, pkey=self.pkey, port=self.port)
+                       #self.channel = self.sshclient.opensession();
+                       #self.sshclient.connect(username=self.username, pkey=self.pkey)
+               except Exception as e:
+                       print e
+                       self.sshclient.close()
 
        def emitCommand(self, comm):
-               stdin, stdout, stderr = self.sshclient.exec_command(comm)
-               print stdout.readlines()
-       
+               try:
+                       #self.channel = self.sshclient.open_session();
+                       stdin, stdout, stderr = self.sshclient.exec_command(comm)
+                       print stdout.readlines()
+               except Exception as e:
+                       print e
+                       self.sshclient.close()  
+
        def closeConnection(self):
                self.sshclient.close()
                
index 514bb2b..27df668 100644 (file)
@@ -10,7 +10,7 @@
        <ssh_port>20322</ssh_port>
        <username>p2p</username>
        <listen_port>10004</listen_port>
-       <daemon_dir>/home/p2p/cs-p2p-next/bt_comm/server</daemon_dir>
+       <daemon_dir>/home/p2p/cs-p2p-next/autorun/server/</daemon_dir>
        <clients>
            <client id="tribler">
                <base>/home/p2p/p2p-clients/tribler/</base>