Revision a985b417 lib/hypervisor/hv_xen.py

b/lib/hypervisor/hv_xen.py
439 439
    """Write the Xen config file for the instance.
440 440

  
441 441
    """
442
    hvp = instance.hvparams
442 443
    config = StringIO()
443 444
    config.write("# this is autogenerated by Ganeti, please do not edit\n#\n")
444 445

  
445 446
    # kernel handling
446
    kpath = instance.hvparams[constants.HV_KERNEL_PATH]
447
    kpath = hvp[constants.HV_KERNEL_PATH]
447 448
    config.write("kernel = '%s'\n" % kpath)
448 449

  
449 450
    # initrd handling
450
    initrd_path = instance.hvparams[constants.HV_INITRD_PATH]
451
    initrd_path = hvp[constants.HV_INITRD_PATH]
451 452
    if initrd_path:
452 453
      config.write("ramdisk = '%s'\n" % initrd_path)
453 454

  
......
479 480
    # just in case it exists
480 481
    utils.RemoveFile("/etc/xen/auto/%s" % instance.name)
481 482
    try:
482
      utils.WriteFile("/etc/xen/%s" % instance.name,
483
                      data=config.getvalue())
483
      utils.WriteFile("/etc/xen/%s" % instance.name, data=config.getvalue())
484 484
    except EnvironmentError, err:
485 485
      raise errors.HypervisorError("Cannot write Xen instance confile"
486 486
                                   " file /etc/xen/%s: %s" %
......
567 567
    """Create a Xen 3.1 HVM config file.
568 568

  
569 569
    """
570
    hvp = instance.hvparams
571

  
570 572
    config = StringIO()
571 573
    config.write("# this is autogenerated by Ganeti, please do not edit\n#\n")
572 574
    config.write("kernel = '/usr/lib/xen/boot/hvmloader'\n")
......
588 590
      config.write("device_model = '/usr/lib64/xen/bin/qemu-dm'\n")
589 591
    else:
590 592
      config.write("device_model = '/usr/lib/xen/bin/qemu-dm'\n")
591
    config.write("boot = '%s'\n" % instance.hvparams[constants.HV_BOOT_ORDER])
593
    config.write("boot = '%s'\n" % hvp[constants.HV_BOOT_ORDER])
592 594
    config.write("sdl = 0\n")
593 595
    config.write("usb = 1\n")
594 596
    config.write("usbdevice = 'tablet'\n")
595 597
    config.write("vnc = 1\n")
596
    if instance.hvparams[constants.HV_VNC_BIND_ADDRESS] is None:
598
    if hvp[constants.HV_VNC_BIND_ADDRESS] is None:
597 599
      config.write("vnclisten = '%s'\n" % constants.VNC_DEFAULT_BIND_ADDRESS)
598 600
    else:
599
      config.write("vnclisten = '%s'\n" %
600
                   instance.hvparams["vnc_bind_address"])
601
      config.write("vnclisten = '%s'\n" % hvp["vnc_bind_address"])
601 602

  
602 603
    if instance.network_port > constants.VNC_BASE_PORT:
603 604
      display = instance.network_port - constants.VNC_BASE_PORT
......
619 620
    config.write("localtime = 1\n")
620 621

  
621 622
    vif_data = []
622
    nic_type = instance.hvparams[constants.HV_NIC_TYPE]
623
    nic_type = hvp[constants.HV_NIC_TYPE]
623 624
    if nic_type is None:
624 625
      # ensure old instances don't change
625 626
      nic_type_str = ", type=ioemu"
......
637 638
    config.write("vif = [%s]\n" % ",".join(vif_data))
638 639
    disk_data = cls._GetConfigFileDiskData(instance.disk_template,
639 640
                                            block_devices)
640
    disk_type = instance.hvparams[constants.HV_DISK_TYPE]
641
    disk_type = hvp[constants.HV_DISK_TYPE]
641 642
    if disk_type in (None, constants.HT_DISK_IOEMU):
642 643
      replacement = ",ioemu:hd"
643 644
    else:
644 645
      replacement = ",hd"
645 646
    disk_data = [line.replace(",sd", replacement) for line in disk_data]
646
    iso_path = instance.hvparams[constants.HV_CDROM_IMAGE_PATH]
647
    iso_path = hvp[constants.HV_CDROM_IMAGE_PATH]
647 648
    if iso_path:
648 649
      iso = "'file:%s,hdc:cdrom,r'" % iso_path
649 650
      disk_data.append(iso)

Also available in: Unified diff