Add function for storing the reason trail of an instance
authorMichele Tartara <mtartara@google.com>
Mon, 25 Mar 2013 15:00:25 +0000 (16:00 +0100)
committerMichele Tartara <mtartara@google.com>
Mon, 22 Apr 2013 11:11:38 +0000 (11:11 +0000)
We are interested in storing the reason trail for operations that changed
the state of instances. This commit adds a function to do this.

Also, the GetInstReasonFilename() function name is prepended with an
underscore because it is only used in this file.

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

lib/backend.py

index 2c5471b..abe6b39 100644 (file)
@@ -110,7 +110,7 @@ class RPCFail(Exception):
   """
 
 
-def GetInstReasonFilename(instance_name):
+def _GetInstReasonFilename(instance_name):
   """Path of the file containing the reason of the instance status change.
 
   @type instance_name: string
@@ -122,6 +122,22 @@ def GetInstReasonFilename(instance_name):
   return utils.PathJoin(pathutils.INSTANCE_REASON_DIR, instance_name)
 
 
+def _StoreInstReasonTrail(instance_name, trail):
+  """Serialize a reason trail related to an instance change of state to file.
+
+  The exact location of the file depends on the name of the instance and on
+  the configuration of the Ganeti cluster defined at deploy time.
+
+  @type instance_name: string
+  @param instance_name: The name of the instance
+  @rtype: None
+
+  """
+  json = serializer.DumpJson(trail)
+  filename = _GetInstReasonFilename(instance_name)
+  utils.WriteFile(filename, data=json)
+
+
 def _Fail(msg, *args, **kwargs):
   """Log an error and the raise an RPCFail exception.