ganeti-noded: quit on QuitGanetiException
[ganeti-local] / daemons / ganeti-noded
index 66e98dd..5388660 100755 (executable)
@@ -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
@@ -211,6 +222,23 @@ class ServerObject(BaseHTTPServer.BaseHTTPRequestHandler):
     cfbd = objects.Disk.FromDict(params[0])
     return backend.SnapshotBlockDevice(cfbd)
 
+  @staticmethod
+  def perspective_blockdev_grow(params):
+    """Grow a stack of devices.
+
+    """
+    cfbd = objects.Disk.FromDict(params[0])
+    amount = params[1]
+    return backend.GrowBlockDevice(cfbd, amount)
+
+  @staticmethod
+  def perspective_blockdev_close(params):
+    """Closes the given block devices.
+
+    """
+    disks = [objects.Disk.FromDict(cf) for cf in params]
+    return backend.CloseBlockDevices(disks)
+
   # export/import  --------------------------
 
   @staticmethod
@@ -341,6 +369,14 @@ class ServerObject(BaseHTTPServer.BaseHTTPRequestHandler):
     return backend.StartInstance(instance, extra_args)
 
   @staticmethod
+  def perspective_instance_migrate(params):
+    """Migrates an instance.
+
+    """
+    instance, target, live = params
+    return backend.MigrateInstance(instance, target, live)
+
+  @staticmethod
   def perspective_instance_reboot(params):
     """Reboot an instance.
 
@@ -484,6 +520,17 @@ class ServerObject(BaseHTTPServer.BaseHTTPRequestHandler):
     hr = backend.HooksRunner()
     return hr.RunHooks(hpath, phase, env)
 
+  # iallocator -----------------
+
+  @staticmethod
+  def perspective_iallocator_runner(params):
+    """Run an iallocator script.
+
+    """
+    name, idata = params
+    iar = backend.IAllocatorRunner()
+    return iar.Run(name, idata)
+
   # test -----------------------
 
   @staticmethod
@@ -581,11 +628,14 @@ def main():
   if options.fork:
     utils.Daemonize(logfile=constants.LOG_NODESERVER)
 
-  logger.SetupLogging(twisted_workaround=True, debug=options.debug,
-                      program="ganeti-noded")
+  logger.SetupLogging(program="ganeti-noded", debug=options.debug)
+
+  global _EXIT_GANETI_NODED
+  _EXIT_GANETI_NODED = False
 
   httpd = BaseHTTPServer.HTTPServer(('', port), ServerObject)
-  httpd.serve_forever()
+  while (not _EXIT_GANETI_NODED):
+    httpd.handle_request()
 
 
 if __name__ == '__main__':