From: Marius Sandu-Popa Date: Fri, 29 Jan 2010 17:24:14 +0000 (+0200) Subject: modified xml files and commander X-Git-Tag: getopt_long~187 X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=commitdiff_plain;h=fe9cde857f9dc269cd2384e3721312b885dca8b7;p=cs-p2p-next.git modified xml files and commander --- diff --git a/bt_comm/client/Client.py b/bt_comm/client/Client.py index b171e92..bd7ceb9 100644 --- a/bt_comm/client/Client.py +++ b/bt_comm/client/Client.py @@ -4,22 +4,36 @@ import paramiko import os from Util import * from XMLParser import * +from TrafficControl import * paramiko.util.log_to_file('/tmp/paramiko.log') MSGLEN = 1024 -class Commander: - def __init__(self): +class Commander(Thread): + def __init__(self, nodes_xml, swarm_xml): + self.nodes = Nodes(nodes_xml); + self.swarm = Swarm(swarm_xml); + self.tc = TrafficControl("openvz"); self.sshc = paramiko.SSHClient() self.sshc.load_system_host_keys() self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - def start_daemon(hostname, username, password, comm): - self.sshc.connect(hostname=hostname, username=username, password=password) + 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() - + def send_comm(self, hostname, port, msg_type, config_data): + self.sock.connect((hostname, port)) + self.send(msg_type) + response = self.recv_msg() + if response == ACK_MSG: + self.send_msg(pickle.dumps(config_data)) + response = self.recv_msg() + self.sock.close() + + return response + def send(self, msg): totalsent = 0 while totalsent < len(msg): @@ -27,16 +41,41 @@ class Commander: if sent == 0: raise RuntimeError, "socket connection broken" totalsent = totalsent + sent + + def start_daemon(self, node): + comm = ""; + send_sshcomm(node.public_address, node.username, node.ssh_port, comm): - def send_command(self, msg_type, config_data): - self.send(msg_type) - response = self.recv_msg() - if response == ACK_MSG: - self.send_msg(pickle.dumps(config_data)) - response = self.recv_msg() + def apply_tc(self, node): + si = swarm.getSIByNode(node) + tc.config(node.public_address, node.public_port, node.public_iface, \ + node.private_address, node.private_port, node.private_iface) + tc.set_upload_limit(si.upload_limit) + tc.set_download_limit(si.downoad_limit) - return response - + upload_limit_commands = tc.get_upload_limit_commands() + download_limit_commands = tc.get_download_limit_commands() + flush_commands = tc.get_flush_commands() + + def send_start(self, node): + + #~ 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): + + def send_stop(self, node): + pass + + def send_status(self, node): + pass + + def run(self): + pass + + #~ def recv_msg(self): #~ msg = '' #~ chunk = self.sock.recv(MSGLEN) @@ -48,22 +87,23 @@ class Commander: class TestCommander: def __init__(self): - nodes = Nodes("nodes.xml"); - swarm = Swarm("swarm.xml"); + nodes = Nodes("../xml/nodes.xml"); + swarm = Swarm("../xml/swarm.xml"); + print nodes.getNode("2"); if __name__ == "__main__": - s = MySocket() - s.connect(HOST, PORT) - - # test config - 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"}] + tc = TestCommander() + + + #~ # test config + #~ 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 = s.send_command(CONFIG_MSG, config_data) - print response + #~ response = s.send_command(CONFIG_MSG, config_data) + #~ print response diff --git a/bt_comm/xml/XMLParser.py b/bt_comm/xml/XMLParser.py index 80d16b8..928c654 100644 --- a/bt_comm/xml/XMLParser.py +++ b/bt_comm/xml/XMLParser.py @@ -7,28 +7,33 @@ class SwarmInstance: self.btclient = list[1]; self.upload_limit = list[2]; self.download_limit = list[3]; - self.port = list[4]; - self.download_dir = list[5]; - self.upload_dir = list[6]; + self.download_dir = list[4]; + self.log_dir = list[5]; + self.output_dir = list[6]; def __str__(self): return '[%s: %s: %s: %s: %s: %s: %s: %s]' \ %(self.id, self.node_id, self.btclient, self.upload_limit, \ - self.download_limit, self.port, self.upload_dir, self.download_dir); + self.download_limit, self.download_dir, self.log_dir, self.output_dir); class Node: def __init__(self, id, list): self.id = id; self.public_address = list[0]; self.public_port = list[1]; - self.private_address = list[2]; - self.private_port = list[3]; - self.ssh_port= list[4]; - self.clients_base_dir = list[5]; + self.public_iface = list[2]; + self.private_address = list[3]; + self.private_port = list[4]; + self.private_iface = list[5]; + self.ssh_port = list[6]; + self.username = list[7]; + self.listen_port = list[8]; + self.clients_base_dir = list[9]; def __str__(self): - return '[%s: %s: %s: %s: %s: %s: %s]' \ - %(self.id, self.public_address, self.public_port, self.private_address, self.private_port, self.ssh_port, self.clients_base_dir); + return '[%s: %s: %s: %s: %s: %s %s: %s]' \ + %(self.id, self.public_address, self.public_port, self.private_address, \ + self.private_port, self.ssh_port, self.username, self.clients_base_dir); class Nodes: def __init__(self, nodes_xml): @@ -58,16 +63,21 @@ class Swarm: tree = etree.parse(swarm_xml) root = tree.getroot() self.swarm = {} - for elem in root: + self.torrent_file = root[0].text + for elem in root[1:]: id = elem.get("id") list = [elem2.text for elem2 in elem[:len(elem)-1]] self.swarm[id] = SwarmInstance(id, list); + print self.swarm[id] except IOError as e: print e return None - - - -nodes = Nodes("nodes.xml"); -swarm = Swarm("swarm.xml"); - + + def getSIByNode(self, node): + for si in self.swarm.values(): + if si.node_id == node.id: + return si + +sw = Swarm("swarm.xml"); +print sw.torrent_file +print sw.getSIByNode("1") diff --git a/bt_comm/xml/nodes.xml b/bt_comm/xml/nodes.xml index def3961..68b1303 100644 --- a/bt_comm/xml/nodes.xml +++ b/bt_comm/xml/nodes.xml @@ -3,9 +3,13 @@ 141.85.224.201 10150 + 172.30.10.0 10150 + 10122 + gogu + /home/p2p/p2p-clients/tribler/ @@ -21,9 +25,13 @@ 141.85.224.202 10250 + 172.30.20.0 10250 + 10222 + gicu + /home/p2p/p2p-clients/tribler/ diff --git a/bt_comm/xml/swarm.xml b/bt_comm/xml/swarm.xml index e0ba485..3a665b9 100644 --- a/bt_comm/xml/swarm.xml +++ b/bt_comm/xml/swarm.xml @@ -1,13 +1,14 @@ + cucu 1 triber 512 256 - 9999 /this/dir - /this/dir + + @@ -22,9 +23,9 @@ transmission - - + + @@ -37,9 +38,9 @@ libtorrent - - + +