Fix unused imports or add silences where needed
[ganeti-local] / daemons / ganeti-noded
index d34c05a..fce0d29 100755 (executable)
 
 """Ganeti node daemon"""
 
-# functions in this module need to have a given name structure, so:
-# pylint: disable-msg=C0103
+# pylint: disable-msg=C0103,W0142
+
+# C0103: Functions in this module need to have a given name structure,
+# and the name of the daemon doesn't match
+
+# W0142: Used * or ** magic, since we do use it extensively in this
+# module
 
 import os
 import sys
-import traceback
-import SocketServer
-import errno
 import logging
 import signal
 
@@ -44,7 +46,7 @@ from ganeti import http
 from ganeti import utils
 from ganeti import storage
 
-import ganeti.http.server
+import ganeti.http.server # pylint: disable-msg=W0611
 
 
 queue_lock = None
@@ -74,6 +76,9 @@ class NodeHttpServer(http.server.HttpServer):
   This class holds all methods exposed over the RPC interface.
 
   """
+  # too many public methods, and unused args - all methods get params
+  # due to the API
+  # pylint: disable-msg=R0904,W0613
   def __init__(self, *args, **kwargs):
     http.server.HttpServer.__init__(self, *args, **kwargs)
     self.noded_pid = os.getpid()
@@ -202,8 +207,9 @@ class NodeHttpServer(http.server.HttpServer):
 
     """
     disks = [objects.Disk.FromDict(dsk_s)
-            for dsk_s in params]
-    return backend.BlockdevGetmirrorstatus(disks)
+             for dsk_s in params]
+    return [status.ToDict()
+            for status in backend.BlockdevGetmirrorstatus(disks)]
 
   @staticmethod
   def perspective_blockdev_find(params):
@@ -213,7 +219,12 @@ class NodeHttpServer(http.server.HttpServer):
 
     """
     disk = objects.Disk.FromDict(params[0])
-    return backend.BlockdevFind(disk)
+
+    result = backend.BlockdevFind(disk)
+    if result is None:
+      return None
+
+    return result.ToDict()
 
   @staticmethod
   def perspective_blockdev_snapshot(params):
@@ -244,6 +255,23 @@ class NodeHttpServer(http.server.HttpServer):
     disks = [objects.Disk.FromDict(cf) for cf in params[1]]
     return backend.BlockdevClose(params[0], disks)
 
+  @staticmethod
+  def perspective_blockdev_getsize(params):
+    """Compute the sizes of the given block devices.
+
+    """
+    disks = [objects.Disk.FromDict(cf) for cf in params[0]]
+    return backend.BlockdevGetsize(disks)
+
+  @staticmethod
+  def perspective_blockdev_export(params):
+    """Compute the sizes of the given block devices.
+
+    """
+    disk = objects.Disk.FromDict(params[0])
+    dest_node, dest_path, cluster_name = params[1:]
+    return backend.BlockdevExport(disk, dest_node, dest_path, cluster_name)
+
   # blockdev/drbd specific methods ----------
 
   @staticmethod
@@ -373,6 +401,14 @@ class NodeHttpServer(http.server.HttpServer):
     (su_name, su_args, name, changes) = params
     return storage.GetStorage(su_name, *su_args).Modify(name, changes)
 
+  @staticmethod
+  def perspective_storage_execute(params):
+    """Execute an operation on a storage unit.
+
+    """
+    (su_name, su_args, name, op) = params
+    return storage.GetStorage(su_name, *su_args).Execute(name, op)
+
   # bridge  --------------------------
 
   @staticmethod
@@ -420,7 +456,8 @@ class NodeHttpServer(http.server.HttpServer):
 
     """
     instance = objects.Instance.FromDict(params[0])
-    return backend.InstanceShutdown(instance)
+    timeout = params[1]
+    return backend.InstanceShutdown(instance, timeout)
 
   @staticmethod
   def perspective_instance_start(params):
@@ -472,7 +509,8 @@ class NodeHttpServer(http.server.HttpServer):
     """
     instance = objects.Instance.FromDict(params[0])
     reboot_type = params[1]
-    return backend.InstanceReboot(instance, reboot_type)
+    shutdown_timeout = params[2]
+    return backend.InstanceReboot(instance, reboot_type, shutdown_timeout)
 
   @staticmethod
   def perspective_instance_info(params):
@@ -562,7 +600,7 @@ class NodeHttpServer(http.server.HttpServer):
     """Cleanup after leaving a cluster.
 
     """
-    return backend.LeaveCluster()
+    return backend.LeaveCluster(params[0])
 
   @staticmethod
   def perspective_node_volumes(params):
@@ -751,11 +789,21 @@ class NodeHttpServer(http.server.HttpServer):
     return backend.ValidateHVParams(hvname, hvparams)
 
 
-def ExecNODED(options, args):
-  """Main NODED function, executed with the pidfile held.
+def CheckNoded(_, args):
+  """Initial checks whether to run or exit with a failure.
+
+  """
+  if args: # noded doesn't take any arguments
+    print >> sys.stderr, ("Usage: %s [-f] [-d] [-p port] [-b ADDRESS]" %
+                          sys.argv[0])
+    sys.exit(constants.EXIT_FAILURE)
+
+
+def ExecNoded(options, _):
+  """Main node daemon function, executed with the PID file held.
 
   """
-  global queue_lock
+  global queue_lock # pylint: disable-msg=W0603
 
   # Read SSL certificate
   if options.ssl:
@@ -788,7 +836,7 @@ def main():
   dirs = [(val, constants.RUN_DIRS_MODE) for val in constants.SUB_RUN_DIRS]
   dirs.append((constants.LOG_OS_DIR, 0750))
   dirs.append((constants.LOCK_DIR, 1777))
-  daemon.GenericMain(constants.NODED, parser, dirs, None, ExecNODED)
+  daemon.GenericMain(constants.NODED, parser, dirs, CheckNoded, ExecNoded)
 
 
 if __name__ == '__main__':