From 7c3d51d43aba8bd8703c36c3b290a1dfc7dc0eac Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Fri, 28 Sep 2007 09:39:15 +0000 Subject: [PATCH] Change constants.OS_DIR with constants.OS_SEARCH_PATH which includes all the directories which can contain OS scripts. The list defaults to the current one but can be changed at configure time. Reviewed-by: imsnah --- configure.ac | 10 +++++++ lib/Makefile.am | 1 + lib/backend.py | 71 ++++++++++++++++++++++++++++++++---------------- lib/constants.py | 2 +- 4 files changed, 59 insertions(+), 25 deletions(-) diff --git a/configure.ac b/configure.ac index 7c8191f1e..d233f1224 100644 --- a/configure.ac +++ b/configure.ac @@ -23,6 +23,16 @@ AC_ARG_WITH([export-dir], [export_dir="/srv/ganeti/export"]) AC_SUBST(EXPORT_DIR, $export_dir) +# --with-os-search-path=... +# do a bit of black sed magic to for quoting of the strings in the list +AC_ARG_WITH([os-search-path], + [AS_HELP_STRING([--with-os-search-path=LIST], + [comma separated list of directories to search for OS images (default is /srv/ganeti/os)] + )], + [os_search_path=`echo -n "$withval" | sed -e "s/\([[^,]]*\)/'\1'/g"`], + [os_search_path="'/srv/ganeti/os'"]) +AC_SUBST(OS_SEARCH_PATH, $os_search_path) + # Check common programs AC_PROG_INSTALL diff --git a/lib/Makefile.am b/lib/Makefile.am index 901b270db..3bcc2f966 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -17,4 +17,5 @@ _autoconf.py: Makefile echo "SYSCONFDIR = '$(sysconfdir)'"; \ echo "SSH_INITD_SCRIPT = '$(SSH_INITD_SCRIPT)'"; \ echo "EXPORT_DIR = '$(EXPORT_DIR)'"; \ + echo "OS_SEARCH_PATH = [$(OS_SEARCH_PATH)]"; \ } > $@ diff --git a/lib/backend.py b/lib/backend.py index 4314a6392..a5391f92c 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -886,15 +886,24 @@ def _OSOndiskVersion(name, os_dir=None): """Compute and return the api version of a given OS. This function will try to read the api version of the os given by - the 'name' parameter. By default, it wil use the constants.OS_DIR - as top-level directory for OSes, but this can be overriden by the - use of the os_dir parameter. Return value will be either an - integer denoting the version or None in the case when this is not - a valid OS name. + the 'name' parameter and residing in the 'os_dir' directory. + + By default if os_dir is not given it will search for a matching name in all + the constants.OS_SEARCH_PATH directories. + + Return value will be either an integer denoting the version or None in the + case when this is not a valid OS name. """ if os_dir is None: - os_dir = os.path.sep.join([constants.OS_DIR, name]) + for base_dir in constants.OS_SEARCH_PATH: + t_os_dir = os.path.sep.join([base_dir, name]) + if os.path.isdir(t_os_dir): + os_dir = t_os_dir + break + + if os_dir is None: + raise errors.InvalidOS(name, "OS dir not found in search path") api_file = os.path.sep.join([os_dir, "ganeti_api_version"]) @@ -927,11 +936,11 @@ def _OSOndiskVersion(name, os_dir=None): return api_version -def DiagnoseOS(top_dir=None): +def DiagnoseOS(top_dirs=None): """Compute the validity for all OSes. - For each name in the give top_dir parameter (if not given, defaults - to constants.OS_DIR), it will return an object. If this is a valid + For each name in all the given top directories (if not given defaults i + to constants.OS_SEARCH_PATH it will return an object. If this is a valid os, the object will be an instance of the object.OS class. If not, it will be an instance of errors.InvalidOS and this signifies that this name does not correspond to a valid OS. @@ -940,21 +949,23 @@ def DiagnoseOS(top_dir=None): list of objects """ - if top_dir is None: - top_dir = constants.OS_DIR + if top_dirs is None: + top_dirs = constants.OS_SEARCH_PATH - try: - f_names = os.listdir(top_dir) - except EnvironmentError, err: - logger.Error("Can't list the OS directory: %s" % str(err)) - return False result = [] - for name in f_names: - try: - os_inst = OSFromDisk(name, os.path.sep.join([top_dir, name])) - result.append(os_inst) - except errors.InvalidOS, err: - result.append(err) + for dir in top_dirs: + if os.path.isdir(dir): + try: + f_names = os.listdir(dir) + except EnvironmentError, err: + logger.Error("Can't list the OS directory %s: %s" % (dir,str(err))) + break + for name in f_names: + try: + os_inst = OSFromDisk(name, os_dir=os.path.sep.join([dir, name])) + result.append(os_inst) + except errors.InvalidOS, err: + result.append(err) return result @@ -967,11 +978,23 @@ def OSFromDisk(name, os_dir=None): `errors.InvalidOS` exception, detailing why this is not a valid OS. + Args: + os_dir: Directory containing the OS scripts. Defaults to a search + in all the OS_SEARCH_PATH directories. + """ + + if os_dir is None: + for base_dir in constants.OS_SEARCH_PATH: + t_os_dir = os.path.sep.join([base_dir, name]) + if os.path.isdir(t_os_dir): + os_dir = t_os_dir + break + if os_dir is None: - os_dir = os.path.sep.join([constants.OS_DIR, name]) + raise errors.InvalidOS(name, "OS dir not found in search path") - api_version = _OSOndiskVersion(name, os_dir) + api_version = _OSOndiskVersion(name, os_dir=os_dir) if api_version != constants.OS_API_VERSION: raise errors.InvalidOS(name, "API version mismatch (found %s want %s)" diff --git a/lib/constants.py b/lib/constants.py index 1594029c1..e4f93895d 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -49,7 +49,7 @@ LOG_DIR = _autoconf.LOCALSTATEDIR + "/log/ganeti" LOG_OS_DIR = LOG_DIR + "/os" LOG_NODESERVER = LOG_DIR + "/node-daemon.log" -OS_DIR = "/srv/ganeti/os" +OS_SEARCH_PATH = _autoconf.OS_SEARCH_PATH EXPORT_DIR = _autoconf.EXPORT_DIR EXPORT_CONF_FILE = "config.ini" -- GitLab