From 8f07dc0df2d8cf5ca30fd55ff21d16f0d76dd9f9 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Fri, 29 Jul 2011 15:56:05 +0200 Subject: [PATCH] watcher: Separate function for writing instance status file For now this will do another query to the master daemon, but with the split for node groups this issue will go away. Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- lib/watcher/__init__.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/watcher/__init__.py b/lib/watcher/__init__.py index 1dee4f390..7dee79ec2 100644 --- a/lib/watcher/__init__.py +++ b/lib/watcher/__init__.py @@ -166,9 +166,7 @@ def GetClusterData(): instances = {} - # write the instance status file - up_data = "".join(["%s %s\n" % (fields[0], fields[1]) for fields in result]) - utils.WriteFile(file_name=constants.INSTANCE_STATUS_FILE, data=up_data) + _UpdateInstanceStatus(client, constants.INSTANCE_STATUS_FILE) for fields in result: (name, status, autostart, snodes) = fields @@ -437,6 +435,25 @@ def ParseOptions(): return (options, args) +def _UpdateInstanceStatus(cl, filename): + """Get a list of instances on this cluster. + + @todo: Think about doing this per nodegroup, too + + """ + op = opcodes.OpInstanceQuery(output_fields=["name", "status"], names=[], + use_locking=True) + job_id = cl.SubmitJob([op]) + (result, ) = cli.PollJob(job_id, cl=cl, feedback_fn=logging.debug) + + cl.ArchiveJob(job_id) + + logging.debug("Got instance data, writing status file %s", filename) + + utils.WriteFile(filename, data="".join("%s %s\n" % (name, status) + for (name, status) in result)) + + @rapi.client.UsesRapiClient def Main(): """Main function. -- GitLab