Commit 7c3d51d4 authored by Guido Trotter's avatar Guido Trotter
Browse files

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
parent 68dccc07
......@@ -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
......
......@@ -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)]"; \
} > $@
......@@ -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)"
......
......@@ -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"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment