diff options
author | Adrian Likins <alikins@redhat.com> | 2007-09-25 11:50:28 -0400 |
---|---|---|
committer | Adrian Likins <alikins@redhat.com> | 2007-09-25 11:50:28 -0400 |
commit | fb7df2a5b7834ead29effb5c60bdc33558546631 (patch) | |
tree | 6c70ccfb037ab621cc69085ba8d5b540753d81dd /overlord | |
parent | 9c72cbd826528bb64267ba2184ae16099343c7ab (diff) | |
parent | 47100aa2f165b47175af1e1aef736c5769a83169 (diff) | |
download | third_party-func-fb7df2a5b7834ead29effb5c60bdc33558546631.tar.gz third_party-func-fb7df2a5b7834ead29effb5c60bdc33558546631.tar.xz third_party-func-fb7df2a5b7834ead29effb5c60bdc33558546631.zip |
Merge branch 'master' of ssh://git.fedoraproject.org/git/hosted/func
Diffstat (limited to 'overlord')
-rw-r--r-- | overlord/__init__.py | 0 | ||||
-rwxr-xr-x | overlord/dumb_client.py | 50 | ||||
-rw-r--r-- | overlord/sslclient.py | 44 | ||||
-rw-r--r-- | overlord/test_func.py | 51 |
4 files changed, 145 insertions, 0 deletions
diff --git a/overlord/__init__.py b/overlord/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/overlord/__init__.py diff --git a/overlord/dumb_client.py b/overlord/dumb_client.py new file mode 100755 index 0000000..c6a31ed --- /dev/null +++ b/overlord/dumb_client.py @@ -0,0 +1,50 @@ +#!/usr/bin/python + + +# all the cool kids would use optparse instead +import getopt +import sys +import xmlrpclib + +myname, argv = sys.argv[0], sys.argv[1:] + +def usage(): + return "Usage: %s [ --help ] [ --verbose ] [ --server=http://hostname:port ] method arg1 [ ... ]" % myname + +verbose = 0 +server = "http://127.0.0.1:51234" + +try: + opts, args = getopt.getopt(argv, "hvs:", + ["help", + "verbose", + "server="]) +except getopt.error, e: + print _("Error parsing list arguments: %s") % e + print usage() + sys.exit() + +for (opt, val) in opts: + print "opt = %s, val = %s" % (opt, val) + if opt in ["-h", "--help"]: + print usage() + sys.exit() + if opt in ["-v", "--verbose"]: + verbose = verbose + 1 + if opt in ["-s", "--server"]: + server = val + +if len(args) < 1: + print usage() + sys.exit() + +s = xmlrpclib.ServerProxy(server) + +method = args[0] +print "calling %s with args: %s" % (method, args[1:]) + +# thats some pretty code right there aint it? -akl +# we can't call "call" on s, since thats a rpc, so +# we call gettatr around it. +print getattr(s, method)(*args[1:]) + diff --git a/overlord/sslclient.py b/overlord/sslclient.py new file mode 100644 index 0000000..9439c4a --- /dev/null +++ b/overlord/sslclient.py @@ -0,0 +1,44 @@ +#!/usr/bin/python + +import os +import sys +import xmlrpclib +import urllib + +from func import SSLCommon + + +class SSL_Transport(xmlrpclib.Transport): + + user_agent = "pyOpenSSL_XMLRPC/%s - %s" % ('0.1', xmlrpclib.Transport.user_agent) + + def __init__(self, ssl_context, timeout=None, use_datetime=0): + if sys.version_info[:3] >= (2, 5, 0): + xmlrpclib.Transport.__init__(self, use_datetime) + self.ssl_ctx=ssl_context + self._timeout = timeout + + def make_connection(self, host): + # Handle username and password. + try: + host, extra_headers, x509 = self.get_host_info(host) + except AttributeError: + # Yay for Python 2.2 + pass + _host, _port = urllib.splitport(host) + return SSLCommon.HTTPS(_host, int(_port), ssl_context=self.ssl_ctx, timeout=self._timeout) + + +class SSLXMLRPCServerProxy(xmlrpclib.ServerProxy): + def __init__(self, uri, pkey_file, cert_file, ca_cert_file, timeout=None): + self.ctx = SSLCommon.CreateSSLContext(pkey_file, cert_file, ca_cert_file) + xmlrpclib.ServerProxy.__init__(self, uri, SSL_Transport(ssl_context=self.ctx, timeout=timeout)) + + + +if __name__ == "__main__": + s = SSLXMLRPCServerProxy('https://localhost:51234/', '/etc/pki/func/slave.pem', '/etc/pki/func/slave.crt', '/etc/pki/func/ca/funcmaster.crt') + f = s.ping(1, 2) + print f + +
\ No newline at end of file diff --git a/overlord/test_func.py b/overlord/test_func.py new file mode 100644 index 0000000..bcce45d --- /dev/null +++ b/overlord/test_func.py @@ -0,0 +1,51 @@ +#!/usr/bin/python + + +# FIXME: should import the client lib, not XMLRPC lib, when we are done + +import xmlrpclib + +TEST_PROCESS = False +TEST_VIRT = False +TEST_SERVICES = False +TEST_HARDWARE = False +TEST_SMART = True + +# get a connecton (to be replaced by client lib logic) +s = xmlrpclib.ServerProxy("http://127.0.0.1:51234") + +# here's the basic test... +print s.test.add(1, 2) + +if TEST_SMART: + print s.smart.info() + +if TEST_PROCESS: + print s.process.info() + # print s.process.pkill("thunderbird") + +# here's the service module testing +if TEST_SERVICES: + print s.service.restart("httpd") + +if TEST_HARDWARE: + print s.hardware.info() + +# this is so I can remember how the virt module works +if TEST_VIRT: + + # example of using koan to install a virtual machine + #s.virt_install("mdehaan.rdu.redhat.com","profileX") + + # wait ... + vms = s.virt.list_vms() + # example of stopping all stopped virtual machines + print "list of virtual instances = %s" % vms + for vm in vms: + status = s.virt.status(vm) + print status + if status == "shutdown": + s.virt.start(vm) + +# add more tests here + |