
commit fd5bfe89decac46cb5d6e3eee1454faac59a3f56 Author: Isis Lovecruft <isis@patternsinthevoid.net> Date: Mon Mar 5 13:00:15 2012 -0800 moved class PlanetLab to nodes.py, removed nodefinder script, updated .conf file for added parameters --- addnodes.py | 59 ----------------------------- ooni-probe.conf | 2 +- planetlab/planetlab.py | 97 ------------------------------------------------ plugoo/nodes.py | 94 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+), 157 deletions(-) diff --git a/addnodes.py b/addnodes.py deleted file mode 100755 index d6814a2..0000000 --- a/addnodes.py +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/python -""" - addnodes.py - *********** - Script to add PlanetLab nodes to a slice. Takes an argument in the - form of a dictionary boot_state_filter, which searches for nodes which - match a pattern. Authentication patterns can be optionally defined in - ooniprobe.config. - - :copyright: (c)2012 Isis Lovecruft - :license: see LICENSE for more details -""" - -from ooniprobe import ooni -try: - import paramiko -except: - "Error: paramiko module was not found." -import pprint -try: - import pyXMLRPCssh -except: - "Error: pyXMLRPCssh module was not found. Please download and install from: https://pypi.python.org/pypi/pyXMLRPCssh/1.0-0" -import xmlrpclib - -class PlanetLab: - def __init__(self, ooni): - self.config = ooni.config - self.logger = ooni.logger - self.name = "PlanetLab" - - def api_auth(self): - api_server = xmlrpclib.ServerProxy('https://www.planet-lab.org/PLCAPI/') - auth = {} - auth['Username'] = self.config.main.pl_username - auth['AuthString'] = self.config.main.pl_password - auth['AuthMethod'] = "password" - authorized = api_server.AuthCheck(auth) - - if authorized: - print 'We are authorized!' - return auth - else: - print 'Authorization failed. Please check the ooni-probe.conf file.' - - def search_for_nodes(self, boot_state_filter=None): - api_server = xmlrpclib.ServerProxy('https://www.planet-lab.org/PLCAPI/') - boot_state_filter = {'hostname': '*.cert.org.cn'} - all_nodes = api_server.GetNodes(self.api_auth(), boot_state_filter) - pp = pprint.PrettyPrinter() - pp.pprint(all_nodes) - -def main(): - o = ooni() - pl = PlanetLab(o) - pl.search_for_nodes() - -if __name__=="__main__": - main() diff --git a/ooni-probe.conf b/ooni-probe.conf index 1a0e607..9563493 100644 --- a/ooni-probe.conf +++ b/ooni-probe.conf @@ -14,7 +14,7 @@ proxyaddress = 127.0.0.1:9050 # The following configurations are for searching for PlanetLab # nodes, adding them to a slice, and PlanetLab general API # authentication: -pl_username = you@youraddress.com +pl_username = yourusername pl_password = yourpassword # These are configurations specific to the tests that should be diff --git a/planetlab/planetlab.py b/planetlab/planetlab.py deleted file mode 100644 index 0a8648e..0000000 --- a/planetlab/planetlab.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -""" - planetlab.py - ************ - - Classes for using ooni-probe with PlanetLab nodes. - - :copyright: (c)2012 Isis Lovecruft - :license: see LICENSE for more details -""" - -from binascii import hexlify -from ooniprobe import ooni -import os -import xmlrpclib -import pprint -try: - import paramiko -except: - print "Error: paramiko module is not installed." -try: - import pyXMLRPCssh -except: - print "Error: pyXMLRPCssh module was not found. Please download and install from : https://pypi.python.org/pypi/pyXMLRPCssh/1.0-0" - -class PlanetLab: - - """Defines a PlanetLab node""" - - ## should inherit from CODE EXEC NODE and NETWORK - ## ADD UNIT OF WORK, adds the unit to pl's schedule - ## needs GET STATUS method for reporting - ## needs upload() and run() private methods - - def __init__(self, ooni): - self.config = ooni.config - self.logger = ooni.logger - self.name = "PlanetLab" - - def api_auth(self): - api_server = xmlrpclib.ServerProxy('https://www.planet-lab.org/PLCAPI/') - auth = {} - ## should be changed to separate node.conf file - auth['Username'] = self.config.main.pl_username - auth['AuthString'] = self.config.main.pl_password - auth['AuthMethod'] = "password" - authorized = api_server.AuthCheck(auth) - - if authorized: - print 'We are authorized!' - return auth - else: - print 'Authorization failed. Please check your settings for pl_username and pl_password in the ooni-probe.conf file.' - - def search_for_nodes(self, boot_state_filter=None): - api_server = xmlrpclib.ServerProxy('https://www.planet-lab.org/PLCAPI/') - boot_state_filter = {'hostname': '*.cert.org.cn'} - all_nodes = api_server.GetNodes(self.api_auth(), boot_state_filter) - pp = pprint.PrettyPrinter() - pp.pprint(all_nodes) - - def auth_login(slicename, machinename): - """Attempt to authenticate to the given PL node, slicename and - machinename, using any of the private keys in ~/.ssh/ """ - - agent = paramiko.Agent() - agent_keys = agent.get_keys() - if len(agent_keys) == 0: - return - - for key in agent_keys: - print 'Trying ssh-agent key %s' % hexlify(key.get_fingerprint()), - try: - paramiko.transport.auth_publickey(machinename, slicename) - print 'Public key authentication to PlanetLab node %s successful.' % machinename, - return - except paramiko.SSHException: - print 'Public key authentication to PlanetLab node %s failed.' % machinename, - - def make_client(slicename, machinename, command): - """Attempt to make a standard OpenSSH client to PL node.""" - - command = PlanetLab.get_command() - - client = paramiko.SSHClient() - client.load_system_host_keys() - client.connect(machinename) - - stdin, stdout, stderr = client.exec_command(command) - - def send_files(files): - """Attempt to rsync a tree to the PL node. Requires PyRsync: - https://pypi.python.org/pypi/pyrsync/0.1.0""" - pass - - def get_command: - pass diff --git a/plugoo/nodes.py b/plugoo/nodes.py index a76601d..320caa7 100644 --- a/plugoo/nodes.py +++ b/plugoo/nodes.py @@ -1,9 +1,21 @@ #!/usr/bin/env python # -*- coding: UTF-8 +from binascii import hexlify +from ooniprobe import ooni import os +try: + import paramiko +except: + print "Error: module paramiko is not installed." +from pprint import pprint +try: + import pyXMLRPCssh +except: + print "Error: module pyXMLRPCssh is not installed." import sys import socks +import xmlrpclib class Node(object): def __init__(self, address, port): @@ -68,4 +80,86 @@ class CodeExecNode(Node): def get_status(self): pass +class PlanetLab(Node, CodeExecNode): + def __init__(self, address, auth_creds, ooni): + self.auth_creds = auth_creds + + self.config = ooni.config + self.logger = ooni.logger + self.name = "PlanetLab" + + def _api_auth(self): + api_server = xmlrpclib.ServerProxy('https://www.planet-lab.org/PLCAPI/') + auth = {} + ## should be changed to separate node.conf file + auth['Username'] = self.config.main.pl_username + auth['AuthString'] = self.config.main.pl_password + auth['AuthMethod'] = "password" + authorized = api_server.AuthCheck(auth) + + if authorized: + print 'We are authorized!' + return auth + else: + print 'Authorization failed. Please check your settings for pl_username and pl_password in the ooni-probe.conf file.' + + def _search_for_nodes(self, node_filter=None): + api_server = xmlrpclib.ServerProxy('https://www.planet-lab.org/PLCAPI/', allow_none=True) + node_filter = {'hostname': '*.cert.org.cn'} + return_fields = ['hostname', 'site_id'] + all_nodes = api_server.GetNodes(self.api_auth(), node_filter, boot_state_filter) + pprint(all_nodes) + return all_nodes + def _add_nodes_to_slice(self): + api_server = xmlrpclib.ServerProxy('https://www.planet-lab.org/PLCAPI/', allow_none=True) + all_nodes = self.search_for_nodes() + for node in all_nodes: + api_server.AddNode(self.api_auth(), node['site_id'], all_nodes) + print 'Adding nodes %s' % node['hostname'] + + def _auth_login(slicename, machinename): + """Attempt to authenticate to the given PL node, slicename and + machinename, using any of the private keys in ~/.ssh/ """ + + agent = paramiko.Agent() + agent_keys = agent.get_keys() + if len(agent_keys) == 0: + return + + for key in agent_keys: + print 'Trying ssh-agent key %s' % hexlify(key.get_fingerprint()), + try: + paramiko.transport.auth_publickey(machinename, slicename) + print 'Public key authentication to PlanetLab node %s successful.' % machinename, + return + except paramiko.SSHException: + print 'Public key authentication to PlanetLab node %s failed.' % machinename, + + def _get_command: + pass + + def ssh_and_run_(slicename, machinename, command): + """Attempt to make a standard OpenSSH client to PL node, and run + commands from a .conf file.""" + + ## needs a way to specify 'ssh -l <slicename> <machinename>' + ## with public key authentication. + + command = PlanetLab.get_command() + + client = paramiko.SSHClient() + client.load_system_host_keys() + client.connect(machinename) + + stdin, stdout, stderr = client.exec_command(command) + + def send_files_to_node(directory, files): + """Attempt to rsync a tree to the PL node.""" + pass + + def add_unit: + pass + + def get_status: + pass