diff options
author | Adrian Likins <alikins@redhat.com> | 2007-09-26 15:27:24 -0400 |
---|---|---|
committer | Adrian Likins <alikins@redhat.com> | 2007-09-26 15:27:24 -0400 |
commit | 835b143c095aa7bd09ed050790a331e152599105 (patch) | |
tree | 8b1fa853c8be1c6622d081c391b4578da5eebf04 | |
parent | 32e6e4ab92f843bf505189b76f2255ab1f3dc6ea (diff) | |
parent | c85f1a8272b665ed810ca05b5b31d35a30f00600 (diff) | |
download | third_party-func-835b143c095aa7bd09ed050790a331e152599105.tar.gz third_party-func-835b143c095aa7bd09ed050790a331e152599105.tar.xz third_party-func-835b143c095aa7bd09ed050790a331e152599105.zip |
Merge branch 'master' of ssh://git.fedoraproject.org/git/hosted/func
-rwxr-xr-x | overlord/client.py | 42 | ||||
-rw-r--r-- | overlord/test_func.py | 3 |
2 files changed, 32 insertions, 13 deletions
diff --git a/overlord/client.py b/overlord/client.py index 81eb950..e16b198 100755 --- a/overlord/client.py +++ b/overlord/client.py @@ -64,17 +64,21 @@ class CommandAutomagic(): class Client(): - def __init__(self, server_spec, port=DEFAULT_PORT, verbose=False, silent=False): + def __init__(self, server_spec, port=DEFAULT_PORT, verbose=False, silent=False, noglobs=False): """ Constructor. - server_spec is something like "*.example.org" or "foosball" - everything else optional and mostly self explanatory. + @server_spec -- something like "*.example.org" or "foosball" + @port -- is the port where all funcd processes should be contacted + @verbose -- whether to print unneccessary things + @silent -- whether to print anything + @noglobs -- specifies server_spec is not a glob, and run should return single values """ self.server_spec = server_spec self.port = port self.verbose = verbose self.silent = silent + self.noglobs = noglobs self.servers = self.expand_servers(self.server_spec) # ----------------------------------------------- @@ -85,6 +89,9 @@ class Client(): of server ids. """ + if self.noglobs: + return [ "https://%s:%s" % (spec, self.port) ] + all_hosts = [] all_certs = [] seperate_gloobs = spec.split(";") @@ -101,7 +108,7 @@ class Client(): all_urls = [] for x in all_hosts: - all_urls.append("http://%s:%s" % (x, self.port)) + all_urls.append("https://%s:%s" % (x, self.port)) if self.verbose and len(all_urls) == 0: sys.stderr.write("no hosts matched\n") @@ -115,31 +122,34 @@ class Client(): 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") - """ + # WARNING: any missing values in Client's source will yield + # strange errors with this engaged. Be aware of that. + """ + return CommandAutomagic(self, [name]) - # ----------------------------------------------- def run(self, module, method, args): """ Invoke a remote method on one or more servers. + Run returns a hash, the keys are server names, the values are the returns. + The returns may include exception objects. + If Client() was constructed with noglobs=True, the return is instead just + a single value, not a hash. """ - count = len(self.servers) results = {} for server in self.servers: - # FIXME: add SSL - conn = sslclient.FuncServer(server) -# conn = xmlrpclib.ServerProxy(server) + # conn = xmlrpclib.ServerProxy(server) if self.verbose: sys.stderr.write("on %s running %s %s (%s)\n" % (server, module, method, ",".join(args))) @@ -160,7 +170,13 @@ class Client(): if not self.silent: sys.stderr.write("remote exception on %s: %s\n" % (server, str(e))) - results[server] = retval + if self.noglobs: + return retval + else: + left = server.rfind("/") + right = server.rfind(":") + server_name = server[left:right] + results[server_name] = retval return results diff --git a/overlord/test_func.py b/overlord/test_func.py index d759a2e..0ee21db 100644 --- a/overlord/test_func.py +++ b/overlord/test_func.py @@ -5,6 +5,7 @@ import xmlrpclib import sys +import socket TEST_GETATTR = True TEST_PROCESS = False @@ -16,6 +17,8 @@ TEST_SMART = True if TEST_GETATTR: import func.overlord.client as func_client print func_client.Client("*").hardware.info() + print func_client.Client("*").run("hardware","info",[]) + print func_client.Client(socket.gethostname(),silent=True,noglobs=True).test.add("1","2") sys.exit(1) # get a connecton (to be replaced by client lib logic) |