[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [ooni-probe/master] Adding script for searching and adding PL nodes, .conf parameters, and class file for PL
commit 739229d24a3cc12cce0c2d8cf24e25d53f92b8b0
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun Mar 4 21:52:04 2012 -0800
Adding script for searching and adding PL nodes, .conf parameters, and class file for PL
---
addnodes.py | 59 +++++++++++++++++++++++++++++
ooni-probe.conf | 8 +++-
planetlab/planetlab.py | 97 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 163 insertions(+), 1 deletions(-)
diff --git a/addnodes.py b/addnodes.py
new file mode 100755
index 0000000..d6814a2
--- /dev/null
+++ b/addnodes.py
@@ -0,0 +1,59 @@
+#!/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 8ea67e3..1a0e607 100644
--- a/ooni-probe.conf
+++ b/ooni-probe.conf
@@ -1,6 +1,6 @@
# ooni-probe
#
-# These are the global configuration paramters necessary to
+# These are the global configuration parameters necessary to
# make ooni-probe work
[main]
reportdir = reports/
@@ -11,6 +11,12 @@ testdir = tests/
loglevel = DEBUG
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@xxxxxxxxxxxxxxx
+pl_password = yourpassword
+
# These are configurations specific to the tests that should be
# run by ooni-probe
[tests]
diff --git a/planetlab/planetlab.py b/planetlab/planetlab.py
new file mode 100644
index 0000000..0a8648e
--- /dev/null
+++ b/planetlab/planetlab.py
@@ -0,0 +1,97 @@
+#!/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
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits