From 9ae49f2753cdd158edb910029f7d08c257d32ad0 Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Thu, 26 Jun 2008 14:42:24 +0000
Subject: [PATCH] ganeti-noded: quit on QuitGanetiException

Accoring to the usage documented in the QuitGanetiException docstring,
if we receive such an exception we'll set the global _EXIT_GANETI_NODED
variable to True, and then return either a valid value or an error
message to the user. This will be the last request we serve, though,
because the main loop will be interrupted and the daemon will terminate.

Reviewed-by: iustinp
---
 daemons/ganeti-noded | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/daemons/ganeti-noded b/daemons/ganeti-noded
index 240816669..5388660e8 100755
--- a/daemons/ganeti-noded
+++ b/daemons/ganeti-noded
@@ -77,6 +77,17 @@ class ServerObject(BaseHTTPServer.BaseHTTPRequestHandler):
       params = simplejson.loads(body)
       result = method(params)
       payload = simplejson.dumps(result)
+    except errors.QuitGanetiException, err:
+      global _EXIT_GANETI_NODED
+      _EXIT_GANETI_NODED = True
+      if isinstance(err, tuple) and len(err) == 2:
+        if err[0]:
+          self.send_error(500, "Error: %s" % str(err[1]))
+        else:
+          payload = simplejson.dumps(err[1])
+      else:
+        self.log_message('GanetiQuitException Usage Error')
+        self.send_error(500, "Error: %s" % str(err))
     except Exception, err:
       self.send_error(500, "Error: %s" % str(err))
       return False
-- 
GitLab