Revision 75bf3149 lib/hypervisor/hv_xen.py

b/lib/hypervisor/hv_xen.py
630 630
                                   command=[pathutils.XEN_CONSOLE_WRAPPER,
631 631
                                            constants.XEN_CMD, instance.name])
632 632

  
633
  def Verify(self):
633
  def Verify(self, hvparams=None):
634 634
    """Verify the hypervisor.
635 635

  
636 636
    For Xen, this verifies that the xend process is running.
637 637

  
638
    @type hvparams: dict of strings
639
    @param hvparams: hypervisor parameters to be verified against
640

  
638 641
    @return: Problem description if something is wrong, C{None} otherwise
639 642

  
640 643
    """
641
    result = self._RunXen(["info"])
644
    if hvparams is None:
645
      return "Could not verify the hypervisor, because no hvparams were" \
646
             " provided."
647

  
648
    if constants.HV_XEN_CMD in hvparams:
649
      xen_cmd = hvparams[constants.HV_XEN_CMD]
650
      try:
651
        self._CheckToolstack(xen_cmd)
652
      except errors.HypervisorError:
653
        return "The configured xen toolstack '%s' is not available on this" \
654
               " node." % xen_cmd
655

  
656
    result = self._RunXen(["info"], hvparams=hvparams)
642 657
    if result.failed:
643
      return "'xm info' failed: %s, %s" % (result.fail_reason, result.output)
658
      return "Retrieving information from xen failed: %s, %s" % \
659
        (result.fail_reason, result.output)
644 660

  
645 661
    return None
646 662

  
......
800 816
    finally:
801 817
      utils.RunCmd([constants.XEN_CMD, "debug", "R"])
802 818

  
819
  def _CheckToolstack(self, xen_cmd):
820
    """Check whether the given toolstack is available on the node.
821

  
822
    @type xen_cmd: string
823
    @param xen_cmd: xen command (e.g. 'xm' or 'xl')
824

  
825
    """
826
    binary_found = self._CheckToolstackBinary(xen_cmd)
827
    if not binary_found:
828
      raise errors.HypervisorError("No '%s' binary found on node." % xen_cmd)
829
    elif xen_cmd == constants.XEN_CMD_XL:
830
      if not self._CheckToolstackXlConfigured():
831
        raise errors.HypervisorError("Toolstack '%s' is not enabled on this"
832
                                     "node." % xen_cmd)
833

  
834
  def _CheckToolstackBinary(self, xen_cmd):
835
    """Checks whether the xen command's binary is found on the machine.
836

  
837
    """
838
    if xen_cmd not in constants.KNOWN_XEN_COMMANDS:
839
      raise errors.HypervisorError("Unknown xen command '%s'." % xen_cmd)
840
    result = self._run_cmd_fn(["which", xen_cmd])
841
    return not result.failed
842

  
843
  def _CheckToolstackXlConfigured(self):
844
    """Checks whether xl is enabled on an xl-capable node.
845

  
846
    @rtype: bool
847
    @returns: C{True} if 'xl' is enabled, C{False} otherwise
848

  
849
    """
850
    result = self._run_cmd_fn([constants.XEN_CMD_XL, "help"])
851
    if not result.failed:
852
      return True
853
    elif result.failed:
854
      if "toolstack" in result.stderr:
855
        return False
856
      # xl fails for some other reason than the toolstack
857
      else:
858
        raise errors.HypervisorError("Cannot run xen ('%s'). Error: %s."
859
                                     % (constants.XEN_CMD_XL, result.stderr))
860

  
803 861

  
804 862
class XenPvmHypervisor(XenHypervisor):
805 863
  """Xen PVM hypervisor interface"""

Also available in: Unified diff