Revision 03abdbe8 lib/hypervisor.py

b/lib/hypervisor.py
136 136

  
137 137
  @staticmethod
138 138
  def _WriteConfigFile(instance, block_devices, extra_args):
139
    """A Xen instance config file.
139
    """Write the Xen config file for the instance.
140 140

  
141 141
    """
142 142
    raise NotImplementedError
......
316 316

  
317 317
  @staticmethod
318 318
  def _WriteConfigFile(instance, block_devices, extra_args):
319
    """Create a Xen instance config file.
319
    """Write the Xen config file for the instance.
320 320

  
321 321
    """
322 322
    config = StringIO()
323 323
    config.write("# this is autogenerated by Ganeti, please do not edit\n#\n")
324
    config.write("kernel = '%s'\n" % constants.XEN_KERNEL)
325
    if os.path.exists(constants.XEN_INITRD):
326
      config.write("ramdisk = '%s'\n" % constants.XEN_INITRD)
324

  
325
    # kernel handling
326
    if instance.kernel_path in (None, constants.VALUE_DEFAULT):
327
      kpath = constants.XEN_KERNEL
328
    else:
329
      if not os.path.exists(instance.kernel_path):
330
        raise errors.HypervisorError("The kernel %s for instance %s is"
331
                                     " missing" % (instance.kernel_path,
332
                                                   instance.name))
333
      kpath = instance.kernel_path
334
    config.write("kernel = '%s'\n" % kpath)
335

  
336
    # initrd handling
337
    if instance.initrd_path in (None, constants.VALUE_DEFAULT):
338
      if os.path.exists(constants.XEN_INITRD):
339
        initrd_path = constants.XEN_INITRD
340
      else:
341
        initrd_path = None
342
    elif instance.initrd_path == constants.VALUE_NONE:
343
      initrd_path = None
344
    else:
345
      if not os.path.exists(instance.initrd_path):
346
        raise errors.HypervisorError("The initrd %s for instance %s is"
347
                                     " missing" % (instance.initrd_path,
348
                                                   instance.name))
349
      initrd_path = instance.initrd_path
350

  
351
    if initrd_path:
352
      config.write("ramdisk = '%s'\n" % initrd_path)
353

  
354
    # rest of the settings
327 355
    config.write("memory = %d\n" % instance.memory)
328 356
    config.write("vcpus = %d\n" % instance.vcpus)
329 357
    config.write("name = '%s'\n" % instance.name)

Also available in: Unified diff