+ 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],
+ rename_script=os_scripts[constants.OS_SCRIPT_RENAME],
+ api_versions=api_versions)
+ return True, os_obj
+
+
+def OSFromDisk(name, base_dir=None):
+ """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{RPCFail} exception, detailing why this is not a valid OS.
+
+ This is just a wrapper over L{_TryOSFromDisk}, which doesn't raise
+ an exception but returns true/false status data.
+
+ @type base_dir: string
+ @keyword base_dir: Base directory containing OS installations.
+ Defaults to a search in all the OS_SEARCH_PATH dirs.
+ @rtype: L{objects.OS}
+ @return: the OS instance if we find a valid one
+ @raise RPCFail: if we don't find a valid OS
+
+ """
+ status, payload = _TryOSFromDisk(name, base_dir)
+
+ if not status:
+ _Fail(payload)
+
+ return payload