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):
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
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)
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)
#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()