From: Marius Sandu-Popa Date: Fri, 29 Jan 2010 14:29:24 +0000 (+0200) Subject: updated xml files X-Git-Tag: getopt_long~196 X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=commitdiff_plain;h=5dc9556d7367244699bd8a8590f9a0ae43e8d5f2;p=cs-p2p-next.git updated xml files --- diff --git a/bt_comm/xml/SSHCommander.py b/bt_comm/xml/SSHCommander.py index 71cfc41..716a065 100644 --- a/bt_comm/xml/SSHCommander.py +++ b/bt_comm/xml/SSHCommander.py @@ -2,14 +2,31 @@ import paramiko import os paramiko.util.log_to_file('/tmp/paramiko.log') -client = paramiko.SSHClient() -client.load_system_host_keys() -client.connect(hostname='141.85.37.237', username='marius', password='marius') -#client.connect(hostname='p2p-next-07.grid.pub.ro', username='p2p') -stdin, stdout, stderr = client.exec_command('touch gugu dudu') -stdin, stdout, stderr = client.exec_command('ls -l') -print stdout.readlines() -client.close() +class SSHCommander: + def __init__(self, hostname, username, password): + self.sshclient = paramiko.SSHClient() + self.sshclient.load_system_host_keys() + self.sshclient.connect(hostname=hostname, username=username, password=password) + + def emitCommand(self, comm): + stdin, stdout, stderr = self.sshclient.exec_command(comm) + print stdout.readlines() + + def closeConnection(self): + self.sshclient.close() + + +sshc = SSHCommander("141.85.37.93", "marius", "marius") +sshc.emitCommand("transmissioncli -D -U \[isoHunt\]\ ubuntu-9.10-desktop-i386.iso.torrent &> out.log") +#sshc.closeConnection() + +#~ #client.connect(hostname='p2p-next-07.grid.pub.ro', username='p2p') +#~ stdin, stdout, stderr = client.exec_command('touch gugu dudu') +#~ stdin, stdout, stderr = client.exec_command('ls -l') +#~ print stdout.readlines() +#~ client.close() + + #~ host = "p2p-next-09.grid.pub.ro" #~ port = 22 #~ transport = paramiko.Transport((host, port)) diff --git a/bt_comm/xml/XMLParser.py b/bt_comm/xml/XMLParser.py index 1f473b5..80d16b8 100644 --- a/bt_comm/xml/XMLParser.py +++ b/bt_comm/xml/XMLParser.py @@ -1,104 +1,73 @@ from lxml import etree class SwarmInstance: - def __init__(self, id, node_id, list): + def __init__(self, id, list): self.id = id; - self.node_id = node_id; - self.btclient = list[0]; - self.upload_limit = list[1]; - self.download_limit = list[2]; - self.port = list[3]; - self.download_dir = list[4]; - self.upload_dir = list[5]; + self.node_id = list[0]; + 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]; 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); -class NodeConfig: - def __init__(self, list): - self.id = list[0]; - self.public_address = list[1]; - self.public_port = list[2]; - self.private_address = list[3]; - self.private_port = list[4]; - self.ssh_port= list[5]; - self.clients_base_dir = list[6]; - - #~ def __str__(self): - #~ return '[%s: %s: %s: %s: %s: %s: %s]' \ - #~ %(self.id, self.btclient, self.upload_limit, self.download_limit, self.port, self.upload_dir, self.download_dir); - -class ClientConfig: - def __init__(self, id, node_path, filetype, options): +class Node: + def __init__(self, id, list): self.id = id; - self.filetype = filetype; - self.options = options; - #~ self.upload_limit_option= list[2]; - #~ self.download_limit_option = list[3]; - #~ self.port_option = list[4]; - #~ self.logging_dir_option = list[5]; - #~ self.download_dir_option = list[6]; - - #~ def __str__(self): - #~ return '[%s: %s: %s: %s: %s: %s: %s]' \ - #~ %(self.id, self.btclient, self.upload_limit, self.download_limit, self.port, self.upload_dir, self.download_dir); - -class FileType: - def __init__(self, list): - self.type = list[0]; - self.file = list[1]; - self.interpreter = list[2]; - self.prefix = list[3]; - self.sufix = list[4]; + 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]; def __str__(self): return '[%s: %s: %s: %s: %s: %s: %s]' \ - %(self.id, self.btclient, self.upload_limit, self.download_limit, self.port, self.upload_dir, self.download_dir); + %(self.id, self.public_address, self.public_port, self.private_address, self.private_port, self.ssh_port, self.clients_base_dir); -try: - tree = etree.parse("clients.xml") - root = tree.getroot() - clients_options = {} - for elem in root: - id = elem.get("id") - options = [elem2.text for elem2 in elem[1:]] - filetype = [elem[0].get("type")] - filetype.extend([elem2.text for elem2 in elem[0]]) - clients_options[id] = [filetype, options] +class Nodes: + def __init__(self, nodes_xml): + try: + tree = etree.parse(nodes_xml) + root = tree.getroot() + self.nodes = {} + for elem in root: + id = elem.get("id") + list = [elem2.text for elem2 in elem[:len(elem)-1]] + client_paths = {} + for elem2 in elem[len(elem)-1]: + client_id = elem2.get("id"); + client_paths [client_id]=elem2[0].text; + list.append(client_paths); + self.nodes[id] = Node(id, list) + except IOError as e: + print e + return None - print clients_options -except IOError as e: - print e - -try: - tree = etree.parse("nodes.xml") - root = tree.getroot() - nodes = {} - for elem in root: - id = elem.get("id") - list = [elem2.text for elem2 in elem[:len(elem)-1]] - client_paths = {} - for elem2 in elem[len(elem)-1]: - client_id = elem2.get("id"); - client_paths [client_id]=elem2[0].text; - nodes[id] = [client_paths, list] - print nodes - print "==================================" -except IOError as e: - print e + def getNode(self, id): + return self.nodes[id]; -try: - tree = etree.parse("swarm.xml") - root = tree.getroot() - swarm = {} - for elem in root: - id = elem.get("id") - list = [elem2.text for elem2 in elem[:len(elem)-1]] - swarm[id] = list - print swarm - print "==================================" -except IOError as e: - print e +class Swarm: + def __init__(self, swarm_xml): + try: + tree = etree.parse(swarm_xml) + root = tree.getroot() + self.swarm = {} + for elem in root: + id = elem.get("id") + list = [elem2.text for elem2 in elem[:len(elem)-1]] + self.swarm[id] = SwarmInstance(id, list); + except IOError as e: + print e + return None + + +nodes = Nodes("nodes.xml"); +swarm = Swarm("swarm.xml"); +