Revision 8e70b181

b/lib/backend.py
1511 1511
  @param name: the OS name we should look for
1512 1512
  @type os_dir: str
1513 1513
  @param os_dir: the directory inwhich we should look for the OS
1514
  @rtype: int or None
1515
  @return:
1516
      Either an integer denoting the version or None in the
1517
      case when this is not a valid OS name.
1518
  @raise errors.InvalidOS: if the OS cannot be found
1514
  @rtype: tuple
1515
  @return: tuple (status, data) with status denoting the validity and
1516
      data holding either the vaid versions or an error message
1519 1517

  
1520 1518
  """
1521 1519
  api_file = os.path.sep.join([os_dir, "ganeti_api_version"])
......
1593 1591
  """Create an OS instance from disk.
1594 1592

  
1595 1593
  This function will return an OS instance if the given name is a
1596
  valid OS name. Otherwise, it will raise an appropriate
1597
  L{errors.InvalidOS} exception, detailing why this is not a valid OS.
1594
  valid OS name.
1598 1595

  
1599 1596
  @type base_dir: string
1600 1597
  @keyword base_dir: Base directory containing OS installations.
......
1640 1637
      return False, ("Script '%s' under path '%s' is not a regular file" %
1641 1638
                     (script, os_dir))
1642 1639

  
1643
  os_obj = objects.OS(name=name, path=os_dir, status=constants.OS_VALID_STATUS,
1640
  os_obj = objects.OS(name=name, path=os_dir,
1644 1641
                      create_script=os_scripts[constants.OS_SCRIPT_CREATE],
1645 1642
                      export_script=os_scripts[constants.OS_SCRIPT_EXPORT],
1646 1643
                      import_script=os_scripts[constants.OS_SCRIPT_IMPORT],
b/lib/constants.py
251 251
 RPC_ENCODING_ZLIB_BASE64) = range(2)
252 252

  
253 253
# os related constants
254
OS_VALID_STATUS = "VALID"
255 254
OS_SCRIPT_CREATE = 'create'
256 255
OS_SCRIPT_IMPORT = 'import'
257 256
OS_SCRIPT_EXPORT = 'export'
b/lib/errors.py
98 98
  pass
99 99

  
100 100

  
101
class InvalidOS(GenericError):
102
  """Missing OS on node.
103

  
104
  This is raised when an OS exists on the master (or is otherwise
105
  requested to the code) but not on the target node.
106

  
107
  This exception has three arguments:
108
    - the name of the os
109
    - the source directory, if any
110
    - the reason why we consider this an invalid OS (text of error message)
111

  
112
  """
113

  
114

  
115 101
class ParameterError(GenericError):
116 102
  """A passed parameter to a command is invalid.
117 103

  
b/lib/objects.py
738 738
  __slots__ = [
739 739
    "name",
740 740
    "path",
741
    "status",
742 741
    "api_versions",
743 742
    "create_script",
744 743
    "export_script",
......
746 745
    "rename_script",
747 746
    ]
748 747

  
749
  @classmethod
750
  def FromInvalidOS(cls, err):
751
    """Create an OS from an InvalidOS error.
752

  
753
    This routine knows how to convert an InvalidOS error to an OS
754
    object representing the broken OS with a meaningful error message.
755

  
756
    """
757
    if not isinstance(err, errors.InvalidOS):
758
      raise errors.ProgrammerError("Trying to initialize an OS from an"
759
                                   " invalid object of type %s" % type(err))
760

  
761
    return cls(name=err.args[0], path=err.args[1], status=err.args[2])
762

  
763
  def __nonzero__(self):
764
    return self.status == constants.OS_VALID_STATUS
765

  
766
  __bool__ = __nonzero__
767

  
768 748

  
769 749
class Node(TaggableObject):
770 750
  """Config object representing a node."""

Also available in: Unified diff