rpc: Convert wrappers for starting import/export daemons
authorMichael Hanselmann <hansmi@google.com>
Mon, 24 Oct 2011 16:42:31 +0000 (18:42 +0200)
committerMichael Hanselmann <hansmi@google.com>
Wed, 26 Oct 2011 08:53:42 +0000 (10:53 +0200)
Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

lib/build/rpc_definitions.py
lib/rpc.py

index b3f183e..5400b33 100644 (file)
@@ -145,6 +145,22 @@ _INSTANCE_CALLS = [
   ]
 
 _IMPEXP_CALLS = [
+  ("import_start", SINGLE, TMO_NORMAL, [
+    ("opts", OBJECT_TO_DICT, None),
+    ("instance", INST_TO_DICT, None),
+    ("component", None, None),
+    ("dest", None, None),
+    ("dest_args", "self._EncodeImportExportIO(dest, %s)", None),
+    ], None, "Starts an import daemon"),
+  ("export_start", SINGLE, TMO_NORMAL, [
+    ("opts", OBJECT_TO_DICT, None),
+    ("host", None, None),
+    ("port", None, None),
+    ("instance", INST_TO_DICT, None),
+    ("component", None, None),
+    ("source", None, None),
+    ("source_args", "self._EncodeImportExportIO(source, %s)", None),
+    ], None, "Starts an export daemon"),
   ("impexp_status", SINGLE, TMO_FAST, [
     ("names", None, "Import/export names"),
     ], "self._ImpExpStatusPostProc", "Gets the status of an import or export"),
index e4b8507..6f36ceb 100644 (file)
@@ -437,21 +437,6 @@ class _RpcProcessor:
     return self._CombineResults(results, requests, procedure)
 
 
-def _EncodeImportExportIO(ieio, ieioargs):
-  """Encodes import/export I/O information.
-
-  """
-  if ieio == constants.IEIO_RAW_DISK:
-    assert len(ieioargs) == 1
-    return (ieioargs[0].ToDict(), )
-
-  if ieio == constants.IEIO_SCRIPT:
-    assert len(ieioargs) == 2
-    return (ieioargs[0].ToDict(), ieioargs[1])
-
-  return ieioargs
-
-
 class RpcRunner(_generated_rpc.RpcClientDefault):
   """RPC runner class.
 
@@ -621,6 +606,21 @@ class RpcRunner(_generated_rpc.RpcClientDefault):
 
     return result
 
+  @staticmethod
+  def _EncodeImportExportIO(ieio, ieioargs):
+    """Encodes import/export I/O information.
+
+    """
+    if ieio == constants.IEIO_RAW_DISK:
+      assert len(ieioargs) == 1
+      return (ieioargs[0].ToDict(), )
+
+    if ieio == constants.IEIO_SCRIPT:
+      assert len(ieioargs) == 2
+      return (ieioargs[0].ToDict(), ieioargs[1])
+
+    return ieioargs
+
   #
   # Begin RPC calls
   #
@@ -832,44 +832,3 @@ class RpcRunner(_generated_rpc.RpcClientDefault):
     hv_full = objects.FillDict(cluster.hvparams.get(hvname, {}), hvparams)
     return self._MultiNodeCall(node_list, "hypervisor_validate_params",
                                [hvname, hv_full])
-
-  @_RpcTimeout(_TMO_NORMAL)
-  def call_import_start(self, node, opts, instance, component,
-                        dest, dest_args):
-    """Starts a listener for an import.
-
-    This is a single-node call.
-
-    @type node: string
-    @param node: Node name
-    @type instance: C{objects.Instance}
-    @param instance: Instance object
-    @type component: string
-    @param component: which part of the instance is being imported
-
-    """
-    return self._SingleNodeCall(node, "import_start",
-                                [opts.ToDict(),
-                                 self._InstDict(instance), component, dest,
-                                 _EncodeImportExportIO(dest, dest_args)])
-
-  @_RpcTimeout(_TMO_NORMAL)
-  def call_export_start(self, node, opts, host, port,
-                        instance, component, source, source_args):
-    """Starts an export daemon.
-
-    This is a single-node call.
-
-    @type node: string
-    @param node: Node name
-    @type instance: C{objects.Instance}
-    @param instance: Instance object
-    @type component: string
-    @param component: which part of the instance is being imported
-
-    """
-    return self._SingleNodeCall(node, "export_start",
-                                [opts.ToDict(), host, port,
-                                 self._InstDict(instance),
-                                 component, source,
-                                 _EncodeImportExportIO(source, source_args)])