Revision a59d5fa1 lib/backend.py

b/lib/backend.py
110 110
  """
111 111

  
112 112

  
113
def GetInstReasonFilename(instance_name):
114
  """Path of the file containing the reason of the instance status change.
115

  
116
  @type instance_name: string
117
  @param instance_name: The name of the instance
118
  @rtype: string
119
  @return: The path of the file
120

  
121
  """
122
  return utils.PathJoin(pathutils.INSTANCE_REASON_DIR, instance_name)
123

  
124

  
125
class InstReason(object):
126
  """Class representing the reason for a change of state of a VM.
127

  
128
  It is used to allow an easy serialization of the reason, so that it can be
129
  written on a file.
130

  
131
  """
132
  def __init__(self, source, text):
133
    """Initialize the class with all the required values.
134

  
135
    @type text: string
136
    @param text: The textual description of the reason for changing state
137
    @type source: string
138
    @param source: The source of the state change (RAPI, CLI, ...)
139

  
140
    """
141
    self.source = source
142
    self.text = text
143

  
144
  def GetJson(self):
145
    """Get the JSON representation of the InstReason.
146

  
147
    @rtype: string
148
    @return : The JSON representation of the object
149

  
150
    """
151
    return serializer.DumpJson(dict(source=self.source, text=self.text))
152

  
153
  def Store(self, instance_name):
154
    """Serialize on a file the reason for the last state change of an instance.
155

  
156
    The exact location of the file depends on the name of the instance and on
157
    the configuration of the Ganeti cluster defined at deploy time.
158

  
159
    @type instance_name: string
160
    @param instance_name: The name of the instance
161
    @rtype: None
162

  
163
    """
164
    filename = GetInstReasonFilename(instance_name)
165
    utils.WriteFile(filename, data=self.GetJson())
166

  
167

  
113 168
def _Fail(msg, *args, **kwargs):
114 169
  """Log an error and the raise an RPCFail exception.
115 170

  

Also available in: Unified diff