Add "reason" as a common parameter for all the RAPI calls
authorMichele Tartara <mtartara@google.com>
Tue, 26 Mar 2013 09:27:37 +0000 (10:27 +0100)
committerMichele Tartara <mtartara@google.com>
Mon, 22 Apr 2013 11:18:29 +0000 (11:18 +0000)
Also, this add an infrastructure for having parameters common to all the
RAPI calls.

Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Helga Velroyen <helgav@google.com>

lib/rapi/baserlib.py

index 9596373..c396f98 100644 (file)
@@ -36,6 +36,7 @@ from ganeti import errors
 from ganeti import compat
 from ganeti import constants
 from ganeti import pathutils
+from ganeti import utils
 
 
 # Dummy value to detect unchanged parameters
@@ -496,11 +497,35 @@ class OpcodeResource(ResourceBase):
   def _GetDefaultData(self):
     return (self.request_body, None)
 
+  def _GetRapiOpName(self):
+    """Extracts the name of the RAPI operation from the class name
+
+    """
+    if self.__class__.__name__.startswith("R_2_"):
+      return self.__class__.__name__[4:]
+    return self.__class__.__name__
+
   def _GetCommonStatic(self):
     """Return the static parameters common to all the RAPI calls
 
+    The reason is a parameter present in all the RAPI calls, and the reason
+    trail has to be build for all of them, so the parameter is read here and
+    used to build the reason trail, that is the actual parameter passed
+    forward.
+
     """
-    common_static = {}
+    trail = []
+    usr_reason = self._checkStringVariable("reason", default=None)
+    if usr_reason:
+      trail.append((constants.OPCODE_REASON_SRC_USER,
+                    usr_reason,
+                    utils.EpochNano()))
+    reason_src = "%s:%s" % (constants.OPCODE_REASON_SRC_RLIB2,
+                            self._GetRapiOpName())
+    trail.append((reason_src, "", utils.EpochNano()))
+    common_static = {
+      "reason": trail,
+      }
     return common_static
 
   def _GenericHandler(self, opcode, rename, fn):