diff options
author | Jesus M. Rodriguez <jmrodri@firebird.home.net> | 2007-09-26 14:16:51 -0400 |
---|---|---|
committer | Jesus M. Rodriguez <jmrodri@firebird.home.net> | 2007-09-26 14:16:51 -0400 |
commit | 411b3213fd42ea8c7cc13bda6923393a18130295 (patch) | |
tree | 4495755eff5eb539dd13e4b41969cc6590ceb9de | |
parent | ae8865e776534c3150e32492af4dcdb7c6bd40a3 (diff) | |
parent | 7e7eedf591a21b7048f89f129411d25f1e98ec6a (diff) | |
download | func-411b3213fd42ea8c7cc13bda6923393a18130295.tar.gz func-411b3213fd42ea8c7cc13bda6923393a18130295.tar.xz func-411b3213fd42ea8c7cc13bda6923393a18130295.zip |
Merge branch 'master' of git://git.fedoraproject.org/git/hosted/func
-rwxr-xr-x | overlord/client.py | 69 | ||||
-rw-r--r-- | overlord/sslclient.py | 19 | ||||
-rw-r--r-- | overlord/test_func.py | 7 |
3 files changed, 84 insertions, 11 deletions
diff --git a/overlord/client.py b/overlord/client.py index 3427e20..87b665a 100755 --- a/overlord/client.py +++ b/overlord/client.py @@ -33,6 +33,32 @@ FUNC_USAGE = "Usage: %s [ --help ] [ --verbose ] target.example.org module metho # =================================== +class CommandAutomagic(): + """ + This allows a client object to act as if it were one machine, when in + reality it represents many. + """ + + def __init__(self, clientref, base): + self.base = base + self.clientref = clientref + + def __getattr__(self,name): + base2 = self.base[:] + base2.append(name) + return CommandAutomagic(self.clientref, base2) + + def __call__(self, *args): + if not self.base: + raise AttributeError("something wrong here") + if len(self.base) < 2: + raise AttributeError("no method called: %s" % ".".join(self.base)) + module = self.base[0] + method = ".".join(self.base[1:]) + return self.clientref.run(module,method,args) + +# =================================== + class Client(): def __init__(self, server_spec, port=DEFAULT_PORT, verbose=False, silent=False): @@ -79,6 +105,22 @@ class Client(): return all_urls + # ----------------------------------------------- + + def __getattr__(self, name): + """ + This getattr allows manipulation of the object as if it were + a XMLRPC handle to a single machine, when in reality it is a handle + to an unspecified number of machines. + + So, it enables stuff like this: + + Client("*.example.org").yum.install("foo") + """ + + return CommandAutomagic(self, [name]) + + # ----------------------------------------------- def run(self, module, method, args): @@ -87,7 +129,7 @@ class Client(): """ count = len(self.servers) - results = [] + results = {} for server in self.servers: @@ -114,7 +156,7 @@ class Client(): if not self.silent: sys.stderr.write("remote exception on %s: %s\n" % (server, str(e))) - results.append(retval) + results[server] = retval return results @@ -126,17 +168,26 @@ class Client(): and all sorts of crazy stuff, reduce it down to a simple integer return. It may not be useful but we need one. """ - nonzeros = [] - for x in results: + numbers = [] + for x in results.keys(): # faults are the most important if type(x) == Exception: return -911 - # then pay attention to non-zeros + # then pay attention to numbers if type(x) == int: - nonzeros.append(x) - if len(nonzeros) > 0: - return nonzeros[1] - return 0 + numbers.append(x) + + # if there were no numbers, assume 0 + if len(numbers) == 0: + return 0 + + # if there were numbers, return the highest + # (presumably the worst error code + max = -9999 + for x in numbers: + if x > max: + max = x + return max # =================================================================== diff --git a/overlord/sslclient.py b/overlord/sslclient.py index 9439c4a..928d6bb 100644 --- a/overlord/sslclient.py +++ b/overlord/sslclient.py @@ -35,10 +35,25 @@ class SSLXMLRPCServerProxy(xmlrpclib.ServerProxy): xmlrpclib.ServerProxy.__init__(self, uri, SSL_Transport(ssl_context=self.ctx, timeout=timeout)) +class FuncServer(SSLXMLRPCServerProxy): + def __init__(self, uri): + self.pem = "/etc/pki/func/slave.pem" + self.crt = "/etc/pki/func/slave.cert" + self.ca = "/etc/pki/func/ca/funcmaster.crt" + + SSLXMLRPCServerProxy.__init__(self, uri, + self.pem, + self.crt, + self.ca) + if __name__ == "__main__": - s = SSLXMLRPCServerProxy('https://localhost:51234/', '/etc/pki/func/slave.pem', '/etc/pki/func/slave.crt', '/etc/pki/func/ca/funcmaster.crt') + s = SSLXMLRPCServerProxy('https://localhost:51234/', '/etc/pki/func/slave.pem', '/etc/pki/func/slave.cert', '/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 index bcce45d..d759a2e 100644 --- a/overlord/test_func.py +++ b/overlord/test_func.py @@ -4,13 +4,20 @@ # FIXME: should import the client lib, not XMLRPC lib, when we are done import xmlrpclib +import sys +TEST_GETATTR = True TEST_PROCESS = False TEST_VIRT = False TEST_SERVICES = False TEST_HARDWARE = False TEST_SMART = True +if TEST_GETATTR: + import func.overlord.client as func_client + print func_client.Client("*").hardware.info() + sys.exit(1) + # get a connecton (to be replaced by client lib logic) s = xmlrpclib.ServerProxy("http://127.0.0.1:51234") |