@param name: the OS name we should look for
@type os_dir: str
@param os_dir: the directory inwhich we should look for the OS
- @rtype: int or None
- @return:
- Either an integer denoting the version or None in the
- case when this is not a valid OS name.
- @raise errors.InvalidOS: if the OS cannot be found
+ @rtype: tuple
+ @return: tuple (status, data) with status denoting the validity and
+ data holding either the vaid versions or an error message
"""
api_file = os.path.sep.join([os_dir, "ganeti_api_version"])
"""Create an OS instance from disk.
This function will return an OS instance if the given name is a
- valid OS name. Otherwise, it will raise an appropriate
- L{errors.InvalidOS} exception, detailing why this is not a valid OS.
+ valid OS name.
@type base_dir: string
@keyword base_dir: Base directory containing OS installations.
return False, ("Script '%s' under path '%s' is not a regular file" %
(script, os_dir))
- os_obj = objects.OS(name=name, path=os_dir, status=constants.OS_VALID_STATUS,
+ os_obj = objects.OS(name=name, path=os_dir,
create_script=os_scripts[constants.OS_SCRIPT_CREATE],
export_script=os_scripts[constants.OS_SCRIPT_EXPORT],
import_script=os_scripts[constants.OS_SCRIPT_IMPORT],
RPC_ENCODING_ZLIB_BASE64) = range(2)
# os related constants
-OS_VALID_STATUS = "VALID"
OS_SCRIPT_CREATE = 'create'
OS_SCRIPT_IMPORT = 'import'
OS_SCRIPT_EXPORT = 'export'
pass
-class InvalidOS(GenericError):
- """Missing OS on node.
-
- This is raised when an OS exists on the master (or is otherwise
- requested to the code) but not on the target node.
-
- This exception has three arguments:
- - the name of the os
- - the source directory, if any
- - the reason why we consider this an invalid OS (text of error message)
-
- """
-
-
class ParameterError(GenericError):
"""A passed parameter to a command is invalid.
__slots__ = [
"name",
"path",
- "status",
"api_versions",
"create_script",
"export_script",
"rename_script",
]
- @classmethod
- def FromInvalidOS(cls, err):
- """Create an OS from an InvalidOS error.
-
- This routine knows how to convert an InvalidOS error to an OS
- object representing the broken OS with a meaningful error message.
-
- """
- if not isinstance(err, errors.InvalidOS):
- raise errors.ProgrammerError("Trying to initialize an OS from an"
- " invalid object of type %s" % type(err))
-
- return cls(name=err.args[0], path=err.args[1], status=err.args[2])
-
- def __nonzero__(self):
- return self.status == constants.OS_VALID_STATUS
-
- __bool__ = __nonzero__
-
class Node(TaggableObject):
"""Config object representing a node."""