Revision 38e250ba

b/lib/hypervisor/hv_kvm.py
32 32
from ganeti import utils
33 33
from ganeti import constants
34 34
from ganeti import errors
35
from ganeti import serializer
36
from ganeti import objects
35 37
from ganeti.hypervisor import hv_base
36 38

  
37 39

  
......
70 72
    """
71 73
    return '%s/%s.serial' % (self._CTRL_DIR, instance_name)
72 74

  
75
  def _InstanceKVMRuntime(self, instance_name):
76
    """Returns the instance KVM runtime filename
77

  
78
    """
79
    return '%s/%s.runtime' % (self._CONF_DIR, instance_name)
80

  
73 81
  def _WriteNetScript(self, instance, seq, nic):
74 82
    """Write a script to connect a net interface to the proper bridge.
75 83

  
......
237 245

  
238 246
    return (kvm_cmd, kvm_nics)
239 247

  
248
  def _WriteKVMRuntime(self, instance_name, data):
249
    """Write an instance's KVM runtime
250

  
251
    """
252
    try:
253
      utils.WriteFile(self._InstanceKVMRuntime(instance_name),
254
                      data=data)
255
    except IOError, err:
256
      raise errors.HypervisorError("Failed to save KVM runtime file: %s" % err)
257

  
258
  def _ReadKVMRuntime(self, instance_name):
259
    """Read an instance's KVM runtime
260

  
261
    """
262
    try:
263
      file_content = utils.ReadFile(self._InstanceKVMRuntime(instance_name))
264
    except IOError, err:
265
      raise errors.HypervisorError("Failed to load KVM runtime file: %s" % err)
266
    return file_content
267

  
268
  def _SaveKVMRuntime(self, instance, kvm_runtime):
269
    """Save an instance's KVM runtime
270

  
271
    """
272
    kvm_cmd, kvm_nics = kvm_runtime
273
    serialized_nics = [nic.ToDict() for nic in kvm_nics]
274
    serialized_form = serializer.Dump((kvm_cmd, serialized_nics))
275
    self._WriteKVMRuntime(instance.name, serialized_form)
276

  
277
  def _LoadKVMRuntime(self, instance):
278
    """Load an instance's KVM runtime
279

  
280
    """
281
    serialized_form = self._ReadKVMRuntime(instance.name)
282
    loaded_runtime = serializer.Load(serialized_form)
283
    kvm_cmd, serialized_nics = loaded_runtime
284
    kvm_nics = [objects.NIC.FromDict(snic) for snic in serialized_nics]
285
    return (kvm_cmd, kvm_nics)
286

  
240 287
  def _ExecuteKVMRuntime(self, instance, kvm_runtime):
241 288
    """Execute a KVM cmd, after completing it with some last minute data
242 289

  
......
283 330
                                   (instance.name, "already running"))
284 331

  
285 332
    kvm_runtime = self._GenerateKVMRuntime(instance, block_devices, extra_args)
333
    self._SaveKVMRuntime(instance, kvm_runtime)
286 334
    self._ExecuteKVMRuntime(instance, kvm_runtime)
287 335

  
288 336
  def StopInstance(self, instance, force=False):
......
309 357
      utils.RemoveFile(pid_file)
310 358
      utils.RemoveFile(self._InstanceMonitor(instance.name))
311 359
      utils.RemoveFile(self._InstanceSerial(instance.name))
360
      utils.RemoveFile(self._InstanceKVMRuntime(instance.name))
312 361

  
313 362
  def RebootInstance(self, instance):
314 363
    """Reboot an instance.

Also available in: Unified diff