From 584ea3405cab8a81ea89cceae788ae7508706b0f Mon Sep 17 00:00:00 2001 From: Michele Tartara <mtartara@google.com> Date: Mon, 25 Mar 2013 16:00:25 +0100 Subject: [PATCH] Add function for storing the reason trail of an instance 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 | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/backend.py b/lib/backend.py index 2c5471b86..abe6b3944 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -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. -- GitLab