Revision a985b417

b/lib/hypervisor/hv_kvm.py
235 235
    if not instance.hvparams[constants.HV_ACPI]:
236 236
      kvm_cmd.extend(['-no-acpi'])
237 237

  
238
    boot_disk = (instance.hvparams[constants.HV_BOOT_ORDER] == "disk")
239
    boot_cdrom = (instance.hvparams[constants.HV_BOOT_ORDER] == "cdrom")
240
    boot_network = (instance.hvparams[constants.HV_BOOT_ORDER] == "network")
238
    hvp = instance.hvparams
239
    boot_disk = hvp[constants.HV_BOOT_ORDER] == "disk"
240
    boot_cdrom = hvp[constants.HV_BOOT_ORDER] == "cdrom"
241
    boot_network = hvp[constants.HV_BOOT_ORDER] == "network"
241 242

  
242 243
    if boot_network:
243 244
      kvm_cmd.extend(['-boot', 'n'])
244 245

  
245
    disk_type = instance.hvparams[constants.HV_DISK_TYPE]
246
    disk_type = hvp[constants.HV_DISK_TYPE]
246 247
    if disk_type == constants.HT_DISK_PARAVIRTUAL:
247 248
      if_val = ',if=virtio'
248 249
    else:
......
263 264
      drive_val = 'file=%s,format=raw%s%s' % (dev_path, if_val, boot_val)
264 265
      kvm_cmd.extend(['-drive', drive_val])
265 266

  
266
    iso_image = instance.hvparams[constants.HV_CDROM_IMAGE_PATH]
267
    iso_image = hvp[constants.HV_CDROM_IMAGE_PATH]
267 268
    if iso_image:
268 269
      options = ',format=raw,media=cdrom'
269 270
      if boot_cdrom:
......
274 275
      drive_val = 'file=%s%s' % (iso_image, options)
275 276
      kvm_cmd.extend(['-drive', drive_val])
276 277

  
277
    kernel_path = instance.hvparams[constants.HV_KERNEL_PATH]
278
    kernel_path = hvp[constants.HV_KERNEL_PATH]
278 279
    if kernel_path:
279 280
      kvm_cmd.extend(['-kernel', kernel_path])
280
      initrd_path = instance.hvparams[constants.HV_INITRD_PATH]
281
      initrd_path = hvp[constants.HV_INITRD_PATH]
281 282
      if initrd_path:
282 283
        kvm_cmd.extend(['-initrd', initrd_path])
283 284
      root_append = 'root=%s ro' % instance.hvparams[constants.HV_ROOT_PATH]
......
286 287
      else:
287 288
        kvm_cmd.extend(['-append', root_append])
288 289

  
289
    mouse_type = instance.hvparams[constants.HV_USB_MOUSE]
290
    mouse_type = hvp[constants.HV_USB_MOUSE]
290 291
    if mouse_type:
291 292
      kvm_cmd.extend(['-usb'])
292 293
      kvm_cmd.extend(['-usbdevice', mouse_type])
293 294

  
294 295
    # FIXME: handle vnc password
295
    vnc_bind_address = instance.hvparams[constants.HV_VNC_BIND_ADDRESS]
296
    vnc_bind_address = hvp[constants.HV_VNC_BIND_ADDRESS]
296 297
    if vnc_bind_address:
297 298
      if utils.IsValidIP(vnc_bind_address):
298 299
        if instance.network_port > constants.VNC_BASE_PORT:
......
311 312
        # Only allow tls and other option when not binding to a file, for now.
312 313
        # kvm/qemu gets confused otherwise about the filename to use.
313 314
        vnc_append = ''
314
        if instance.hvparams[constants.HV_VNC_TLS]:
315
        if hvp[constants.HV_VNC_TLS]:
315 316
          vnc_append = '%s,tls' % vnc_append
316
          if instance.hvparams[constants.HV_VNC_X509_VERIFY]:
317
          if hvp[constants.HV_VNC_X509_VERIFY]:
317 318
            vnc_append = '%s,x509verify=%s' % (vnc_append,
318
              instance.hvparams[constants.HV_VNC_X509])
319
          elif instance.hvparams[constants.HV_VNC_X509]:
319
                                               hvp[constants.HV_VNC_X509])
320
          elif hvp[constants.HV_VNC_X509]:
320 321
            vnc_append = '%s,x509=%s' % (vnc_append,
321
              instance.hvparams[constants.HV_VNC_X509])
322
                                         hvp[constants.HV_VNC_X509])
322 323
        vnc_arg = '%s%s' % (vnc_arg, vnc_append)
323 324

  
324 325
      else:
......
331 332
    monitor_dev = 'unix:%s,server,nowait' % \
332 333
      self._InstanceMonitor(instance.name)
333 334
    kvm_cmd.extend(['-monitor', monitor_dev])
334
    if instance.hvparams[constants.HV_SERIAL_CONSOLE]:
335
      serial_dev = 'unix:%s,server,nowait' % self._InstanceSerial(instance.name)
335
    if hvp[constants.HV_SERIAL_CONSOLE]:
336
      serial_dev = ('unix:%s,server,nowait' %
337
                    self._InstanceSerial(instance.name))
336 338
      kvm_cmd.extend(['-serial', serial_dev])
337 339
    else:
338 340
      kvm_cmd.extend(['-serial', 'none'])
......
340 342
    # Save the current instance nics, but defer their expansion as parameters,
341 343
    # as we'll need to generate executable temp files for them.
342 344
    kvm_nics = instance.nics
343
    hvparams = instance.hvparams
345
    hvparams = hvp
344 346

  
345 347
    return (kvm_cmd, kvm_nics, hvparams)
346 348

  
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