Revision 398fd4f6 lib/hypervisor/hv_xen.py

b/lib/hypervisor/hv_xen.py
339 339

  
340 340
    self._cmd = _cmd
341 341

  
342
  def _GetCommand(self, hvparams=None):
342
  def _GetCommand(self, hvparams):
343 343
    """Returns Xen command to use.
344 344

  
345 345
    @type hvparams: dict of strings
......
347 347

  
348 348
    """
349 349
    if self._cmd is None:
350
      if hvparams is not None:
351
        cmd = hvparams[constants.HV_XEN_CMD]
350
      if hvparams is None or constants.HV_XEN_CMD not in hvparams:
351
        raise errors.HypervisorError("Cannot determine xen command.")
352 352
      else:
353
        # TODO: Remove autoconf option once retrieving the command from
354
        # the hvparams is fully implemented.
355
        cmd = constants.XEN_CMD
353
        cmd = hvparams[constants.HV_XEN_CMD]
356 354
    else:
357 355
      cmd = self._cmd
358 356

  
......
361 359

  
362 360
    return cmd
363 361

  
364
  def _RunXen(self, args, hvparams=None):
362
  def _RunXen(self, args, hvparams):
365 363
    """Wrapper around L{utils.process.RunCmd} to run Xen command.
366 364

  
367 365
    @type hvparams: dict of strings
......
369 367
    @see: L{utils.process.RunCmd}
370 368

  
371 369
    """
372
    cmd = [self._GetCommand(hvparams=hvparams)]
370
    cmd = [self._GetCommand(hvparams)]
373 371
    cmd.extend(args)
374 372

  
375 373
    return self._run_cmd_fn(cmd)
......
438 436
    utils.RenameFile(old_filename, new_filename)
439 437
    return new_filename
440 438

  
441
  def _GetInstanceList(self, include_node, hvparams=None):
439
  def _GetInstanceList(self, include_node, hvparams):
442 440
    """Wrapper around module level L{_GetInstanceList}.
443 441

  
442
    @type hvparams: dict of strings
443
    @param hvparams: hypervisor parameters to be used on this node
444

  
444 445
    """
445
    return _GetInstanceList(lambda: self._RunXen(["list"], hvparams=hvparams),
446
    return _GetInstanceList(lambda: self._RunXen(["list"], hvparams),
446 447
                            include_node)
447 448

  
448 449
  def ListInstances(self, hvparams=None):
449 450
    """Get the list of running instances.
450 451

  
451 452
    """
452
    instance_list = self._GetInstanceList(False, hvparams=hvparams)
453
    instance_list = self._GetInstanceList(False, hvparams)
453 454
    names = [info[0] for info in instance_list]
454 455
    return names
455 456

  
......
464 465
    @return: tuple (name, id, memory, vcpus, stat, times)
465 466

  
466 467
    """
467
    instance_list = self._GetInstanceList(instance_name == _DOM0_NAME,
468
                                          hvparams=hvparams)
468
    instance_list = self._GetInstanceList(instance_name == _DOM0_NAME, hvparams)
469 469
    result = None
470 470
    for data in instance_list:
471 471
      if data[0] == instance_name:
......
481 481
    @return: list of tuples (name, id, memory, vcpus, stat, times)
482 482

  
483 483
    """
484
    return self._GetInstanceList(False, hvparams=hvparams)
484
    return self._GetInstanceList(False, hvparams)
485 485

  
486 486
  def _MakeConfigFile(self, instance, startup_memory, block_devices):
487 487
    """Gather configuration details and write to disk.
......
511 511
      cmd.append("-p")
512 512
    cmd.append(self._ConfigFileName(instance.name))
513 513

  
514
    result = self._RunXen(cmd, hvparams=instance.hvparams)
514
    result = self._RunXen(cmd, instance.hvparams)
515 515
    if result.failed:
516 516
      # Move the Xen configuration file to the log directory to avoid
517 517
      # leaving a stale config file behind.
......
546 546
    else:
547 547
      action = "shutdown"
548 548

  
549
    result = self._RunXen([action, name], hvparams=hvparams)
549
    result = self._RunXen([action, name], hvparams)
550 550
    if result.failed:
551 551
      raise errors.HypervisorError("Failed to stop instance %s: %s, %s" %
552 552
                                   (name, result.fail_reason, result.output))
......
564 564
      raise errors.HypervisorError("Failed to reboot instance %s,"
565 565
                                   " not running" % instance.name)
566 566

  
567
    result = self._RunXen(["reboot", instance.name], hvparams=instance.hvparams)
567
    result = self._RunXen(["reboot", instance.name], instance.hvparams)
568 568
    if result.failed:
569 569
      raise errors.HypervisorError("Failed to reboot instance %s: %s, %s" %
570 570
                                   (instance.name, result.fail_reason,
......
597 597
    @param mem: actual memory size to use for instance runtime
598 598

  
599 599
    """
600
    result = self._RunXen(["mem-set", instance.name, mem],
601
                          hvparams=instance.hvparams)
600
    result = self._RunXen(["mem-set", instance.name, mem], instance.hvparams)
602 601
    if result.failed:
603 602
      raise errors.HypervisorError("Failed to balloon instance %s: %s (%s)" %
604 603
                                   (instance.name, result.fail_reason,
......
620 619
    @see: L{_GetNodeInfo} and L{_ParseNodeInfo}
621 620

  
622 621
    """
623
    result = self._RunXen(["info"], hvparams=hvparams)
622
    result = self._RunXen(["info"], hvparams)
624 623
    if result.failed:
625 624
      logging.error("Can't retrieve xen hypervisor information (%s): %s",
626 625
                    result.fail_reason, result.output)
627 626
      return None
628 627

  
629
    instance_list = self._GetInstanceList(True, hvparams=hvparams)
628
    instance_list = self._GetInstanceList(True, hvparams)
630 629
    return _GetNodeInfo(result.stdout, instance_list)
631 630

  
632 631
  @classmethod
......
664 663
        return "The configured xen toolstack '%s' is not available on this" \
665 664
               " node." % xen_cmd
666 665

  
667
    result = self._RunXen(["info"], hvparams=hvparams)
666
    result = self._RunXen(["info"], hvparams)
668 667
    if result.failed:
669 668
      return "Retrieving information from xen failed: %s, %s" % \
670 669
        (result.fail_reason, result.output)
......
747 746
    if self.GetInstanceInfo(instance_name, hvparams=hvparams) is None:
748 747
      raise errors.HypervisorError("Instance not running, cannot migrate")
749 748

  
750
    cmd = self._GetCommand(hvparams=hvparams)
749
    cmd = self._GetCommand(hvparams)
751 750

  
752 751
    if (cmd == constants.XEN_CMD_XM and
753 752
        not _ping_fn(target, port, live_port_needed=True)):
......
772 771

  
773 772
    args.extend([instance_name, target])
774 773

  
775
    result = self._RunXen(args, hvparams=hvparams)
774
    result = self._RunXen(args, hvparams)
776 775
    if result.failed:
777 776
      raise errors.HypervisorError("Failed to migrate instance %s: %s" %
778 777
                                   (instance_name, result.output))

Also available in: Unified diff