From 62b705f2ef608e212229a234b9e53cf60f9dd83f Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Wed, 26 Sep 2007 16:35:26 -0400 Subject: The addition of an example program to find which systems have parts subject to recall. --- examples/find_recalled_parts.py | 24 ++++++++++++++++++++++++ examples/part_data.txt | 12 ++++++++++++ overlord/client.py | 15 +++++++-------- overlord/test_func.py | 7 ++++--- 4 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 examples/find_recalled_parts.py create mode 100644 examples/part_data.txt diff --git a/examples/find_recalled_parts.py b/examples/find_recalled_parts.py new file mode 100644 index 0000000..f9ca4bb --- /dev/null +++ b/examples/find_recalled_parts.py @@ -0,0 +1,24 @@ +#!/usr/bin/python +# find all parts that need to be recalled +# (C) Michael DeHaan, 2007 +# =============================================== + +import func.overlord.client as fc + +bad = open("./part_data.txt").read().split() + +info = fc.Client("*").hardware.info() + +for (host,details) in info.iteritems(): + + if type(details) != dict: + print "%s had an error : %s" % (host,str(details)) + break + + for device in details["devices"]: + for bad_value in bad: + if device["Description"].find(bad_value) != -1: + print "%s has flagged part: %s " % (host, device["Description"]) + break + + diff --git a/examples/part_data.txt b/examples/part_data.txt new file mode 100644 index 0000000..3d2cf3a --- /dev/null +++ b/examples/part_data.txt @@ -0,0 +1,12 @@ +#-BAD-ITEM-PARTS +92P1072 92P1073 92P1088 92P1089 92P1142 92P1141 92P1170", "92P1169", +93P5028 92P1174 92P1173 93P5030 + +#-BAD-DELL-PARTS +1K055 C5446 F2100 KD494 W5915 Y1333 3K590 C6269 F5132 OR33X5308 Y4500 5P474 +C6270 GD785 M3006 X5329 Y5466 6P922 D2961 H3191 RD857 X5332 C2603 D5555 J1524 TD349 +X5333 C5339 D6024 JD616 U5867 X5875 C5340 D6025 JD617 U5882 X5877 + +#-RANDOM-STUFF-SO-GET-A-FALSE-POSITIVE +SCSI + diff --git a/overlord/client.py b/overlord/client.py index e16b198..c4b9fa4 100755 --- a/overlord/client.py +++ b/overlord/client.py @@ -64,20 +64,19 @@ class CommandAutomagic(): class Client(): - def __init__(self, server_spec, port=DEFAULT_PORT, verbose=False, silent=False, noglobs=False): + def __init__(self, server_spec, port=DEFAULT_PORT, interactive=False, verbose=False, noglobs=False): """ Constructor. @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.interactive = interactive self.noglobs = noglobs self.servers = self.expand_servers(self.server_spec) @@ -151,7 +150,7 @@ class Client(): conn = sslclient.FuncServer(server) # conn = xmlrpclib.ServerProxy(server) - if self.verbose: + if self.interactive: sys.stderr.write("on %s running %s %s (%s)\n" % (server, module, method, ",".join(args))) # FIXME: support userland command subclassing only if a module @@ -163,17 +162,17 @@ class Client(): # we call gettatr around it. meth = "%s.%s" % (module, method) retval = getattr(conn, meth)(*args[:]) - if not self.silent: + if self.interactive: print retval except Exception, e: retval = e - if not self.silent: + if self.interactive: sys.stderr.write("remote exception on %s: %s\n" % (server, str(e))) if self.noglobs: return retval else: - left = server.rfind("/") + left = server.rfind("/")+1 right = server.rfind(":") server_name = server[left:right] results[server_name] = retval @@ -289,7 +288,7 @@ class FuncCommandLine(): """ Runs the actual command. """ - client = Client(self.server_spec,port=self.port,verbose=self.verbose) + client = Client(self.server_spec,port=self.port,interactive=True,verbose=self.verbose) results = client.run(self.module, self.method, self.method_args) # TO DO: add multiplexer support diff --git a/overlord/test_func.py b/overlord/test_func.py index 0ee21db..1e0d72b 100644 --- a/overlord/test_func.py +++ b/overlord/test_func.py @@ -16,9 +16,10 @@ 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") + print func_client.Client("*").test.add(1,2) + #print func_client.Client("*").hardware.info() + #print func_client.Client("*").run("hardware","info",[]) + #print func_client.Client(socket.gethostname(),noglobs=True).test.add("1","2") sys.exit(1) # get a connecton (to be replaced by client lib logic) -- cgit