Commit 3329f4de authored by Michael Hanselmann's avatar Michael Hanselmann

constants: Move most paths to separate module

This is inpreparation for the implementation of virtual clusters. Many
paths will change based on an environment variable and are no longer
constant and should no longer be in “constants.py”. Since “constants.py”
is already huge a number of other paths are also moved in the process.

For now a wildcard import is used to re-export all paths from
“constants.py” (this will change over coming patches). Daemon log paths
have been changed to use a function. “RUN_GANETI_DIR” was moved to
“RUN_DIR” as the latter was only used in “constants.py”.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent a6798ce1
......@@ -228,6 +228,7 @@ pkgpython_PYTHON = \
lib/objectutils.py \
lib/opcodes.py \
lib/ovf.py \
lib/pathutils.py \
lib/qlang.py \
lib/query.py \
lib/rpc.py \
......
......@@ -92,12 +92,11 @@ daemonGroup (ExtraGroup AdminGroup) = C.adminGroup
-- | Returns the log file for a daemon.
daemonLogFile :: GanetiDaemon -> FilePath
daemonLogFile GanetiConfd = C.daemonsLogfilesGanetiConfd
daemonLogFile _ = error "Unimplemented"
daemonLogFile daemon = C.logDir </> daemonName daemon <.> "log"
-- | Returns the pid file name for a daemon.
daemonPidFile :: GanetiDaemon -> FilePath
daemonPidFile daemon = C.runGanetiDir </> daemonName daemon <.> "pid"
daemonPidFile daemon = C.runDir </> daemonName daemon <.> "pid"
-- | All groups list. A bit hacking, as we can't enforce it's complete
-- at compile time.
......
......@@ -2168,7 +2168,7 @@ def DiagnoseOS(top_dirs=None):
@type top_dirs: list
@param top_dirs: the list of directories in which to
search (if not given defaults to
L{constants.OS_SEARCH_PATH})
L{pathutils.OS_SEARCH_PATH})
@rtype: list of L{objects.OS}
@return: a list of tuples (name, path, status, diagnose, variants,
parameters, api_version) for all (potential) OSes under all
......@@ -3538,7 +3538,7 @@ class HooksRunner(object):
@type hooks_base_dir: str or None
@param hooks_base_dir: if not None, this overrides the
L{constants.HOOKS_BASE_DIR} (useful for unittests)
L{pathutils.HOOKS_BASE_DIR} (useful for unittests)
"""
if hooks_base_dir is None:
......
......@@ -412,7 +412,7 @@ def InitCluster(cluster_name, mac_prefix, # pylint: disable=R0913, R0914
(master_netdev,
result.output.strip()), errors.ECODE_INVAL)
dirs = [(constants.RUN_GANETI_DIR, constants.RUN_DIRS_MODE)]
dirs = [(constants.RUN_DIR, constants.RUN_DIRS_MODE)]
utils.EnsureDirs(dirs)
objects.UpgradeBeParams(beparams)
......
......@@ -26,6 +26,8 @@ import socket
from ganeti import _autoconf
from ganeti import _vcsversion
from ganeti.pathutils import * # pylint: disable=W0401,W0614
# various versions
RELEASE_VERSION = _autoconf.PACKAGE_VERSION
......@@ -129,84 +131,17 @@ WIPE_BLOCK_SIZE = 1024 ** 2
MAX_WIPE_CHUNK = 1024 # 1GB
MIN_WIPE_CHUNK_PERCENT = 10
# file paths
DATA_DIR = _autoconf.LOCALSTATEDIR + "/lib/ganeti"
RUN_DIR = _autoconf.LOCALSTATEDIR + "/run"
RUN_GANETI_DIR = RUN_DIR + "/ganeti"
BDEV_CACHE_DIR = RUN_GANETI_DIR + "/bdev-cache"
DISK_LINKS_DIR = RUN_GANETI_DIR + "/instance-disks"
RUN_DIRS_MODE = 0775
SOCKET_DIR = RUN_GANETI_DIR + "/socket"
SECURE_DIR_MODE = 0700
SECURE_FILE_MODE = 0600
CRYPTO_KEYS_DIR = RUN_GANETI_DIR + "/crypto"
IMPORT_EXPORT_DIR = RUN_GANETI_DIR + "/import-export"
ADOPTABLE_BLOCKDEV_ROOT = "/dev/disk/"
LOCK_DIR = _autoconf.LOCALSTATEDIR + "/lock"
SSCONF_LOCK_FILE = LOCK_DIR + "/ganeti-ssconf.lock"
# User-id pool lock directory
# The user-ids that are in use have a corresponding lock file in this directory
UIDPOOL_LOCKDIR = RUN_GANETI_DIR + "/uid-pool"
CLUSTER_CONF_FILE = DATA_DIR + "/config.data"
NODED_CERT_FILE = DATA_DIR + "/server.pem"
RAPI_CERT_FILE = DATA_DIR + "/rapi.pem"
CONFD_HMAC_KEY = DATA_DIR + "/hmac.key"
SPICE_CERT_FILE = DATA_DIR + "/spice.pem"
SPICE_CACERT_FILE = DATA_DIR + "/spice-ca.pem"
CLUSTER_DOMAIN_SECRET_FILE = DATA_DIR + "/cluster-domain-secret"
INSTANCE_STATUS_FILE = RUN_GANETI_DIR + "/instance-status"
SSH_KNOWN_HOSTS_FILE = DATA_DIR + "/known_hosts"
RAPI_USERS_FILE = DATA_DIR + "/rapi/users"
QUEUE_DIR = DATA_DIR + "/queue"
DAEMON_UTIL = _autoconf.PKGLIBDIR + "/daemon-util"
SETUP_SSH = _autoconf.TOOLSDIR + "/setup-ssh"
KVM_IFUP = _autoconf.PKGLIBDIR + "/kvm-ifup"
KVM_CONSOLE_WRAPPER = _autoconf.PKGLIBDIR + "/tools/kvm-console-wrapper"
XM_CONSOLE_WRAPPER = _autoconf.PKGLIBDIR + "/tools/xm-console-wrapper"
ETC_HOSTS = "/etc/hosts"
DEFAULT_FILE_STORAGE_DIR = _autoconf.FILE_STORAGE_DIR
DEFAULT_SHARED_FILE_STORAGE_DIR = _autoconf.SHARED_FILE_STORAGE_DIR
ENABLE_FILE_STORAGE = _autoconf.ENABLE_FILE_STORAGE
ENABLE_SHARED_FILE_STORAGE = _autoconf.ENABLE_SHARED_FILE_STORAGE
SYSCONFDIR = _autoconf.SYSCONFDIR
TOOLSDIR = _autoconf.TOOLSDIR
CONF_DIR = SYSCONFDIR + "/ganeti"
USER_SCRIPTS_DIR = CONF_DIR + "/scripts"
ENABLE_CONFD = _autoconf.ENABLE_CONFD
HS_CONFD = _autoconf.HS_CONFD
ENABLE_SPLIT_QUERY = _autoconf.ENABLE_SPLIT_QUERY
#: Lock file for watcher, locked in shared mode by watcher; lock in exclusive
# mode to block watcher (see L{cli._RunWhileClusterStoppedHelper.Call}
WATCHER_LOCK_FILE = LOCK_DIR + "/ganeti-watcher.lock"
#: Status file for per-group watcher, locked in exclusive mode by watcher
WATCHER_GROUP_STATE_FILE = DATA_DIR + "/watcher.%s.data"
#: File for per-group instance status, merged into L{INSTANCE_STATUS_FILE} by
#: per-group processes
WATCHER_GROUP_INSTANCE_STATUS_FILE = DATA_DIR + "/watcher.%s.instance-status"
#: File containing Unix timestamp until which watcher should be paused
WATCHER_PAUSEFILE = DATA_DIR + "/watcher.pause"
# Master IP address setup scripts paths (default and user-provided)
DEFAULT_MASTER_SETUP_SCRIPT = TOOLSDIR + "/master-ip-setup"
EXTERNAL_MASTER_SETUP_SCRIPT = USER_SCRIPTS_DIR + "/master-ip-setup"
ALL_CERT_FILES = frozenset([
NODED_CERT_FILE,
RAPI_CERT_FILE,
SPICE_CERT_FILE,
SPICE_CACERT_FILE,
])
#: LUXI socket used for job execution
MASTER_SOCKET = SOCKET_DIR + "/ganeti-master"
#: LUXI socket used for queries only
QUERY_SOCKET = SOCKET_DIR + "/ganeti-query"
NODED = "ganeti-noded"
CONFD = "ganeti-confd"
RAPI = "ganeti-rapi"
......@@ -232,23 +167,6 @@ DEFAULT_NLD_PORT = DAEMONS_PORTS[NLD][1]
FIRST_DRBD_PORT = 11000
LAST_DRBD_PORT = 14999
LOG_DIR = _autoconf.LOCALSTATEDIR + "/log/ganeti/"
DAEMONS_LOGFILES = {
# "daemon-name": "logfile"
NODED: LOG_DIR + "node-daemon.log",
CONFD: LOG_DIR + "conf-daemon.log",
RAPI: LOG_DIR + "rapi-daemon.log",
MASTERD: LOG_DIR + "master-daemon.log",
# used in the ganeti-nbma project
NLD: LOG_DIR + "nl-daemon.log",
}
LOG_OS_DIR = LOG_DIR + "os"
LOG_WATCHER = LOG_DIR + "watcher.log"
LOG_COMMANDS = LOG_DIR + "commands.log"
LOG_BURNIN = LOG_DIR + "burnin.log"
LOG_SETUP_SSH = LOG_DIR + "setup-ssh.log"
DEV_CONSOLE = "/dev/console"
PROC_MOUNTS = "/proc/mounts"
......@@ -264,9 +182,6 @@ SYSLOG_YES = "yes"
SYSLOG_ONLY = "only"
SYSLOG_SOCKET = "/dev/log"
OS_SEARCH_PATH = _autoconf.OS_SEARCH_PATH
EXPORT_DIR = _autoconf.EXPORT_DIR
EXPORT_CONF_FILE = "config.ini"
XEN_BOOTLOADER = _autoconf.XEN_BOOTLOADER
......@@ -323,8 +238,6 @@ X509_CERT_CN = "ganeti.example.com"
X509_CERT_SIGNATURE_HEADER = "X-Ganeti-Signature"
IMPORT_EXPORT_DAEMON = _autoconf.PKGLIBDIR + "/import-export"
# Import/export daemon mode
IEM_IMPORT = "import"
IEM_EXPORT = "export"
......@@ -360,7 +273,6 @@ VALUE_FALSE = "false"
EXT_PLUGIN_MASK = re.compile("^[a-zA-Z0-9_-]+$")
# hooks-related constants
HOOKS_BASE_DIR = CONF_DIR + "/hooks"
HOOKS_PHASE_PRE = "pre"
HOOKS_PHASE_POST = "post"
HOOKS_NAME_CFGUPDATE = "config-update"
......@@ -693,11 +605,6 @@ OS_VALIDATE_PARAMETERS = "parameters"
OS_VALIDATE_CALLS = frozenset([OS_VALIDATE_PARAMETERS])
# ssh constants
SSH_CONFIG_DIR = _autoconf.SSH_CONFIG_DIR
SSH_HOST_DSA_PRIV = SSH_CONFIG_DIR + "/ssh_host_dsa_key"
SSH_HOST_DSA_PUB = SSH_HOST_DSA_PRIV + ".pub"
SSH_HOST_RSA_PRIV = SSH_CONFIG_DIR + "/ssh_host_rsa_key"
SSH_HOST_RSA_PUB = SSH_HOST_RSA_PRIV + ".pub"
SSH = "ssh"
SCP = "scp"
......@@ -1193,7 +1100,6 @@ HYPER_TYPES = frozenset([
HTS_REQ_PORT = frozenset([HT_XEN_HVM, HT_KVM])
VNC_BASE_PORT = 5900
VNC_PASSWORD_FILE = CONF_DIR + "/vnc-cluster-password"
VNC_DEFAULT_BIND_ADDRESS = IP4_ADDRESS_ANY
# NIC types
......@@ -1565,11 +1471,6 @@ NODE_EVAC_MODES = frozenset([
# Job queue
JOB_QUEUE_VERSION = 1
JOB_QUEUE_LOCK_FILE = QUEUE_DIR + "/lock"
JOB_QUEUE_VERSION_FILE = QUEUE_DIR + "/version"
JOB_QUEUE_SERIAL_FILE = QUEUE_DIR + "/serial"
JOB_QUEUE_ARCHIVE_DIR = QUEUE_DIR + "/archive"
JOB_QUEUE_DRAIN_FILE = QUEUE_DIR + "/drain"
JOB_QUEUE_SIZE_HARD_LIMIT = 5000
JOB_ID_TEMPLATE = r"\d+"
......@@ -2128,3 +2029,6 @@ FAKE_OP_MASTER_TURNDOWN = "OP_CLUSTER_IP_TURNDOWN"
# Do not re-export imported modules
del re, _vcsversion, _autoconf, socket
# Unintended imports from pathutils (temporary)
del GetLogFilename
......@@ -41,6 +41,7 @@ from ganeti import netutils
from ganeti import ssconf
from ganeti import runtime
from ganeti import compat
from ganeti import pathutils
class SchedulerBreakout(Exception):
......@@ -778,15 +779,16 @@ def GenericMain(daemon_name, optionparser,
if check_fn is not None:
check_fn(options, args)
log_filename = pathutils.GetLogFilename(daemon_name)
if options.fork:
utils.CloseFDs()
(wpipe, stdio_reopen_fn) = \
utils.Daemonize(logfile=constants.DAEMONS_LOGFILES[daemon_name])
(wpipe, stdio_reopen_fn) = utils.Daemonize(logfile=log_filename)
else:
(wpipe, stdio_reopen_fn) = (None, None)
log_reopen_fn = \
utils.SetupLogging(constants.DAEMONS_LOGFILES[daemon_name], daemon_name,
utils.SetupLogging(log_filename, daemon_name,
debug=options.debug,
stderr_logging=not options.fork,
multithreaded=multithreaded,
......
......@@ -58,7 +58,7 @@ class ChrootManager(hv_base.BaseHypervisor):
- instance alive check is based on whether any process is using the chroot
"""
_ROOT_DIR = constants.RUN_GANETI_DIR + "/chroot-hypervisor"
_ROOT_DIR = constants.RUN_DIR + "/chroot-hypervisor"
PARAMETERS = {
constants.HV_INIT_SCRIPT: (True, utils.IsNormAbsPath,
......
......@@ -43,7 +43,7 @@ class FakeHypervisor(hv_base.BaseHypervisor):
"""
CAN_MIGRATE = True
_ROOT_DIR = constants.RUN_GANETI_DIR + "/fake-hypervisor"
_ROOT_DIR = constants.RUN_DIR + "/fake-hypervisor"
def __init__(self):
hv_base.BaseHypervisor.__init__(self)
......
......@@ -404,7 +404,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
"""
CAN_MIGRATE = True
_ROOT_DIR = constants.RUN_GANETI_DIR + "/kvm-hypervisor"
_ROOT_DIR = constants.RUN_DIR + "/kvm-hypervisor"
_PIDS_DIR = _ROOT_DIR + "/pid" # contains live instances pids
_UIDS_DIR = _ROOT_DIR + "/uid" # contains instances reserved uids
_CTRL_DIR = _ROOT_DIR + "/ctrl" # contains instances control sockets
......
......@@ -65,7 +65,7 @@ class LXCHypervisor(hv_base.BaseHypervisor):
notify_on_release and release_agent feature of cgroups
"""
_ROOT_DIR = constants.RUN_GANETI_DIR + "/lxc"
_ROOT_DIR = constants.RUN_DIR + "/lxc"
_DEVS = [
"c 1:3", # /dev/null
"c 1:5", # /dev/zero
......
#
#
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
"""Module containing constants and functions for filesystem paths.
"""
from ganeti import _autoconf
# Build-time constants
DEFAULT_FILE_STORAGE_DIR = _autoconf.FILE_STORAGE_DIR
DEFAULT_SHARED_FILE_STORAGE_DIR = _autoconf.SHARED_FILE_STORAGE_DIR
EXPORT_DIR = _autoconf.EXPORT_DIR
OS_SEARCH_PATH = _autoconf.OS_SEARCH_PATH
SSH_CONFIG_DIR = _autoconf.SSH_CONFIG_DIR
SYSCONFDIR = _autoconf.SYSCONFDIR
TOOLSDIR = _autoconf.TOOLSDIR
# Paths which don't change for a virtual cluster
DAEMON_UTIL = _autoconf.PKGLIBDIR + "/daemon-util"
IMPORT_EXPORT_DAEMON = _autoconf.PKGLIBDIR + "/import-export"
KVM_CONSOLE_WRAPPER = _autoconf.PKGLIBDIR + "/tools/kvm-console-wrapper"
KVM_IFUP = _autoconf.PKGLIBDIR + "/kvm-ifup"
SETUP_SSH = _autoconf.TOOLSDIR + "/setup-ssh"
XM_CONSOLE_WRAPPER = _autoconf.PKGLIBDIR + "/tools/xm-console-wrapper"
# Top-level paths
DATA_DIR = _autoconf.LOCALSTATEDIR + "/lib/ganeti"
LOCK_DIR = _autoconf.LOCALSTATEDIR + "/lock"
LOG_DIR = _autoconf.LOCALSTATEDIR + "/log/ganeti"
RUN_DIR = _autoconf.LOCALSTATEDIR + "/run/ganeti"
#: Script to configure master IP address
DEFAULT_MASTER_SETUP_SCRIPT = TOOLSDIR + "/master-ip-setup"
SSH_HOST_DSA_PRIV = SSH_CONFIG_DIR + "/ssh_host_dsa_key"
SSH_HOST_DSA_PUB = SSH_HOST_DSA_PRIV + ".pub"
SSH_HOST_RSA_PRIV = SSH_CONFIG_DIR + "/ssh_host_rsa_key"
SSH_HOST_RSA_PUB = SSH_HOST_RSA_PRIV + ".pub"
BDEV_CACHE_DIR = RUN_DIR + "/bdev-cache"
DISK_LINKS_DIR = RUN_DIR + "/instance-disks"
SOCKET_DIR = RUN_DIR + "/socket"
CRYPTO_KEYS_DIR = RUN_DIR + "/crypto"
IMPORT_EXPORT_DIR = RUN_DIR + "/import-export"
INSTANCE_STATUS_FILE = RUN_DIR + "/instance-status"
#: User-id pool lock directory (used user IDs have a corresponding lock file in
#: this directory)
UIDPOOL_LOCKDIR = RUN_DIR + "/uid-pool"
SSCONF_LOCK_FILE = LOCK_DIR + "/ganeti-ssconf.lock"
CLUSTER_CONF_FILE = DATA_DIR + "/config.data"
NODED_CERT_FILE = DATA_DIR + "/server.pem"
RAPI_CERT_FILE = DATA_DIR + "/rapi.pem"
CONFD_HMAC_KEY = DATA_DIR + "/hmac.key"
SPICE_CERT_FILE = DATA_DIR + "/spice.pem"
SPICE_CACERT_FILE = DATA_DIR + "/spice-ca.pem"
CLUSTER_DOMAIN_SECRET_FILE = DATA_DIR + "/cluster-domain-secret"
SSH_KNOWN_HOSTS_FILE = DATA_DIR + "/known_hosts"
RAPI_USERS_FILE = DATA_DIR + "/rapi/users"
QUEUE_DIR = DATA_DIR + "/queue"
CONF_DIR = SYSCONFDIR + "/ganeti"
USER_SCRIPTS_DIR = CONF_DIR + "/scripts"
VNC_PASSWORD_FILE = CONF_DIR + "/vnc-cluster-password"
HOOKS_BASE_DIR = CONF_DIR + "/hooks"
#: Lock file for watcher, locked in shared mode by watcher; lock in exclusive
# mode to block watcher (see L{cli._RunWhileClusterStoppedHelper.Call}
WATCHER_LOCK_FILE = LOCK_DIR + "/ganeti-watcher.lock"
#: Status file for per-group watcher, locked in exclusive mode by watcher
WATCHER_GROUP_STATE_FILE = DATA_DIR + "/watcher.%s.data"
#: File for per-group instance status, merged into L{INSTANCE_STATUS_FILE} by
#: per-group processes
WATCHER_GROUP_INSTANCE_STATUS_FILE = DATA_DIR + "/watcher.%s.instance-status"
#: File containing Unix timestamp until which watcher should be paused
WATCHER_PAUSEFILE = DATA_DIR + "/watcher.pause"
#: User-provided master IP setup script
EXTERNAL_MASTER_SETUP_SCRIPT = USER_SCRIPTS_DIR + "/master-ip-setup"
#: LUXI socket used for job execution
MASTER_SOCKET = SOCKET_DIR + "/ganeti-master"
#: LUXI socket used for queries only
QUERY_SOCKET = SOCKET_DIR + "/ganeti-query"
LOG_OS_DIR = LOG_DIR + "/os"
# Job queue paths
JOB_QUEUE_LOCK_FILE = QUEUE_DIR + "/lock"
JOB_QUEUE_VERSION_FILE = QUEUE_DIR + "/version"
JOB_QUEUE_SERIAL_FILE = QUEUE_DIR + "/serial"
JOB_QUEUE_ARCHIVE_DIR = QUEUE_DIR + "/archive"
JOB_QUEUE_DRAIN_FILE = QUEUE_DIR + "/drain"
ALL_CERT_FILES = frozenset([
NODED_CERT_FILE,
RAPI_CERT_FILE,
SPICE_CERT_FILE,
SPICE_CACERT_FILE,
])
def GetLogFilename(daemon_name):
"""Returns the full path for a daemon's log file.
"""
return "%s/%s.log" % (LOG_DIR, daemon_name)
LOG_WATCHER = GetLogFilename("watcher")
LOG_COMMANDS = GetLogFilename("commands")
LOG_BURNIN = GetLogFilename("burnin")
LOG_SETUP_SSH = GetLogFilename("setup-ssh")
......@@ -34,6 +34,7 @@ from ganeti import runtime
from ganeti import ssconf
from ganeti import utils
from ganeti import cli
from ganeti import pathutils
(DIR,
......@@ -117,10 +118,10 @@ def GetPaths():
"""
getent = runtime.GetEnts()
masterd_log = constants.DAEMONS_LOGFILES[constants.MASTERD]
noded_log = constants.DAEMONS_LOGFILES[constants.NODED]
confd_log = constants.DAEMONS_LOGFILES[constants.CONFD]
rapi_log = constants.DAEMONS_LOGFILES[constants.RAPI]
masterd_log = pathutils.GetLogFilename(constants.MASTERD)
noded_log = pathutils.GetLogFilename(constants.NODED)
confd_log = pathutils.GetLogFilename(constants.CONFD)
rapi_log = pathutils.GetLogFilename(constants.RAPI)
rapi_dir = os.path.join(constants.DATA_DIR, "rapi")
......@@ -166,7 +167,7 @@ def GetPaths():
(rapi_dir, DIR, 0750, getent.rapi_uid, getent.masterd_gid),
(constants.RAPI_USERS_FILE, FILE, 0640, getent.rapi_uid,
getent.masterd_gid, False),
(constants.RUN_GANETI_DIR, DIR, 0775, getent.masterd_uid,
(constants.RUN_DIR, DIR, 0775, getent.masterd_uid,
getent.daemons_gid),
(constants.SOCKET_DIR, DIR, 0750, getent.masterd_uid,
getent.daemons_gid),
......
......@@ -903,7 +903,7 @@ def DaemonPidFileName(name):
daemon name
"""
return PathJoin(constants.RUN_GANETI_DIR, "%s.pid" % name)
return PathJoin(constants.RUN_DIR, "%s.pid" % name)
def WritePidFile(pidfile):
......
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