from Util import *
from XMLParser import *
from TrafficControl import *
+from threading import Thread
paramiko.util.log_to_file('/tmp/paramiko.log')
MSGLEN = 1024
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def send_sshcomm(self, hostname, username, port, comm):
- self.sshc.connect(hostname=hostname, username=username, port=port)
- stdin, stdout, stderr = self.sshc.exec_command(comm)
- self.sshc.close()
+ try:
+ self.sshc.connect(hostname=hostname, username=username, port=port)
+ stdin, stdout, stderr = self.sshc.exec_command(comm)
+ self.sshc.close()
+ except Exception as e:
+ print e
+
+ def send_multiple_sshcom(self, hostname, username, port, comms):
+ try:
+ self.sshc.connect(hostname=hostname, username=username, port=port)
+ for c in comms:
+ stdin, stdout, stderr = self.sshc.exec_command(comm)
+ self.sshc.close()
+ except Exception as e:
+ print e
def send_comm(self, hostname, port, msg_type, config_data):
self.sock.connect((hostname, port))
def start_daemon(self, node):
comm = "";
- send_sshcomm(node.public_address, node.username, node.ssh_port, comm):
+ send_sshcomm(node.public_address, node.username, node.ssh_port, comm)
def apply_tc(self, node):
si = swarm.getSIByNode(node)
tc.set_upload_limit(si.upload_limit)
tc.set_download_limit(si.downoad_limit)
- upload_limit_commands = tc.get_upload_limit_commands()
- download_limit_commands = tc.get_download_limit_commands()
- flush_commands = tc.get_flush_commands()
+ commands = tc.get_all_commands()
+ send_multiple_sshcomm(node.public_address, node.username, node.ssh_port, commands)
def send_start(self, node):
+ config_data = []
#~ config_data = [{CLIENT:"tribler", FILE:"Tribler/Tools/cmdline.py",
#~ RUN_TYPE:"script",
#~ INTERPRETER:"python", PREFIX:"PYTHONPATH=.",SUFFIX:"",
#~ UP_LIMIT_OPTION:"",DL_LIMIT_OPTION:"", PORT_OPTION:"-p",
#~ LOG_DIR_OPTION:"-l",DL_DIR_OPTION:"-d"}]
- response = send_comm(self, node.public_address, node.public_port, START_MSG, config_data):
+ response = send_comm(self, node.public_address, node.public_port, START_MSG, config_data)
def send_stop(self, node):
pass
pass
def run(self):
- pass
-
-
+ while(1):
+ k = raw_input('enter choice:')
+ if k == '': break
+
#~ def recv_msg(self):
#~ msg = ''
#~ chunk = self.sock.recv(MSGLEN)
def __init__(self):
nodes = Nodes("../xml/nodes.xml");
swarm = Swarm("../xml/swarm.xml");
- print nodes.getNode("2");
+ #print nodes.getNode("2");
if __name__ == "__main__":
return flush_commands
+ def get_all_commands(self):
+ all_commands = []
+ all_commands.extend(self.get_upload_limit_commands())
+ all_commands.extend(self.get_download_limit_commands())
+ all_commands.extend(self.get_flush_commands())
+
+ return all_commands
+
def print_commands(commands, header):
print "\n\t== %s ==\n" % (header)
upload_limit_commands = tc.get_upload_limit_commands()
download_limit_commands = tc.get_download_limit_commands()
flush_commands = tc.get_flush_commands()
+ all_commands = tc.get_all_commands()
print_commands(upload_limit_commands, "upload limit commands")
print_commands(download_limit_commands, "download limit commands")
print_commands(flush_commands, "flush commands")
+ print_commands(all_commands, "all commands")
if __name__ == "__main__":
sys.exit(main())