Revision 8d528b7c lib/backend.py

b/lib/backend.py
1633 1633
    return rr
1634 1634

  
1635 1635

  
1636
class IAllocatorRunner(object):
1637
  """IAllocator runner.
1638

  
1639
  This class is instantiated on the node side (ganeti-noded) and not on
1640
  the master side.
1641

  
1642
  """
1643
  def Run(self, name, idata):
1644
    """Run an iallocator script.
1645

  
1646
    Return value: tuple of:
1647
       - run status (one of the IARUN_ constants)
1648
       - stdout
1649
       - stderr
1650
       - fail reason (as from utils.RunResult)
1651

  
1652
    """
1653
    alloc_script = utils.FindFile(name, constants.IALLOCATOR_SEARCH_PATH,
1654
                                  os.path.isfile)
1655
    if alloc_script is None:
1656
      return (constants.IARUN_NOTFOUND, None, None, None)
1657

  
1658
    fd, fin_name = tempfile.mkstemp(prefix="ganeti-iallocator.")
1659
    try:
1660
      os.write(fd, idata)
1661
      os.close(fd)
1662
      result = utils.RunCmd([alloc_script, fin_name])
1663
      if result.failed:
1664
        return (constants.IARUN_FAILURE, result.stdout, result.stderr,
1665
                result.fail_reason)
1666
    finally:
1667
      os.unlink(fin_name)
1668

  
1669
    return (constants.IARUN_SUCCESS, result.stdout, result.stderr, None)
1670

  
1671

  
1636 1672
class DevCacheManager(object):
1637 1673
  """Simple class for managing a cache of block device information.
1638 1674

  

Also available in: Unified diff