From b858fea1be6f72a6f00972a56f0829225c22285f Mon Sep 17 00:00:00 2001 From: Marius Sandu-Popa Date: Sat, 10 Apr 2010 18:09:47 +0300 Subject: [PATCH] small changes for Commander --- autorun/commander/Commander.py | 35 +++++++++++++++---------------- autorun/commander/SSHCommander.py | 28 +++++++++++++++++-------- autorun/xml/nodes.xml | 2 +- 3 files changed, 37 insertions(+), 28 deletions(-) diff --git a/autorun/commander/Commander.py b/autorun/commander/Commander.py index e2b6d64..ccf595e 100644 --- a/autorun/commander/Commander.py +++ b/autorun/commander/Commander.py @@ -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) diff --git a/autorun/commander/SSHCommander.py b/autorun/commander/SSHCommander.py index 25bfcac..5130f8b 100644 --- a/autorun/commander/SSHCommander.py +++ b/autorun/commander/SSHCommander.py @@ -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() diff --git a/autorun/xml/nodes.xml b/autorun/xml/nodes.xml index 514bb2b..27df668 100644 --- a/autorun/xml/nodes.xml +++ b/autorun/xml/nodes.xml @@ -10,7 +10,7 @@ 20322 p2p 10004 - /home/p2p/cs-p2p-next/bt_comm/server + /home/p2p/cs-p2p-next/autorun/server/ /home/p2p/p2p-clients/tribler/ -- 2.20.1