Merge pull request #35178 from cro/proxy_cache_fix2

Add append_minionid_config_dirs option
This commit is contained in:
Mike Place 2016-08-07 07:21:14 +09:00 committed by GitHub
commit f004b831d2
6 changed files with 74 additions and 14 deletions

View File

@ -127,6 +127,13 @@
# This data may contain sensitive data and should be protected accordingly.
#cachedir: /var/cache/salt/minion
# Append minion_id to these directories. Helps with
# multiple proxies and minions running on the same machine.
# Allowed elements in the list: pki_dir, cachedir, extension_modules
# Normally not needed unless running several proxies and/or minions on the same machine
# Defaults to ['cachedir'] for proxies, [] (empty list) for regular minions
#append_minionid_config_dirs:
# Verify and set permissions on configuration directories at startup.
#verify_env: True

View File

@ -84,6 +84,16 @@
# This data may contain sensitive data and should be protected accordingly.
#cachedir: /var/cache/salt/minion
# Append minion_id to these directories. Helps with
# multiple proxies and minions running on the same machine.
# Allowed elements in the list: pki_dir, cachedir, extension_modules
# Normally not needed unless running several proxies and/or minions on the same machine
# Defaults to ['cachedir'] for proxies, [] (empty list) for regular minions
# append_minionid_config_dirs:
# - cachedir
# Verify and set permissions on configuration directories at startup.
#verify_env: True

View File

@ -395,7 +395,24 @@ This directory may contain sensitive data and should be protected accordingly.
cachedir: /var/cache/salt/minion
.. conf_minion:: verify_env
.. conf_minion:: append_minionid_config_dirs
``append_minionid_config_dirs``
-------------------------------
Default: ``[]`` (the empty list) for regular minions, ``['cachedir']`` for proxy minions.
Append minion_id to these configuration directories. Helps with multiple proxies
and minions running on the same machine. Allowed elements in the list:
``pki_dir``, ``cachedir``, ``extension_modules``.
Normally not needed unless running several proxies and/or minions on the same machine.
.. code-block:: yaml
append_minionid_config_dirs:
- pki_dir
- cachedir
``verify_env``
--------------

View File

@ -424,7 +424,9 @@ class ProxyMinion(parsers.ProxyMinionOptionParser, DaemonsMixin): # pylint: dis
# Proxies get their ID from the command line. This may need to change in
# the future.
self.config['id'] = self.values.proxyid
# We used to set this here. Now it is set in ProxyMinionOptionParser
# by passing it via setup_config to config.minion_config
# self.config['id'] = self.values.proxyid
try:
if self.config['verify_env']:

View File

@ -176,6 +176,11 @@ VALID_OPTS = {
# The directory to store all cache files.
'cachedir': str,
# Append minion_id to these directories. Helps with
# multiple proxies and minions running on the same machine.
# Allowed elements in the list: pki_dir, cachedir, extension_modules
'append_minionid_config_dirs': list,
# Flag to cache jobs locally.
'cache_jobs': bool,
@ -876,6 +881,7 @@ DEFAULT_MINION_OPTS = {
'pki_dir': os.path.join(salt.syspaths.CONFIG_DIR, 'pki', 'minion'),
'id': '',
'cachedir': os.path.join(salt.syspaths.CACHE_DIR, 'minion'),
'append_minionid_config_dirs': [],
'cache_jobs': False,
'grains_cache': False,
'grains_cache_expiration': 300,
@ -1344,6 +1350,7 @@ DEFAULT_PROXY_MINION_OPTS = {
'log_file': os.path.join(salt.syspaths.LOGS_DIR, 'proxy'),
'add_proxymodule_to_opts': False,
'proxy_merge_grains_in_module': False,
'append_minionid_config_dirs': ['cachedir'],
}
# ----- Salt Cloud Configuration Defaults ----------------------------------->
@ -1749,7 +1756,8 @@ def minion_config(path,
env_var='SALT_MINION_CONFIG',
defaults=None,
cache_minion_id=False,
ignore_config_errors=True):
ignore_config_errors=True,
minion_id=None):
'''
Reads in the minion configuration file and sets up special options
@ -1789,7 +1797,9 @@ def minion_config(path,
overrides.update(include_config(include, path, verbose=True,
exit_on_config_errors=not ignore_config_errors))
opts = apply_minion_config(overrides, defaults, cache_minion_id=cache_minion_id)
opts = apply_minion_config(overrides, defaults,
cache_minion_id=cache_minion_id,
minion_id=minion_id)
_validate_opts(opts)
return opts
@ -2934,7 +2944,8 @@ def get_id(opts, cache_minion_id=False):
def apply_minion_config(overrides=None,
defaults=None,
cache_minion_id=False):
cache_minion_id=False,
minion_id=None):
'''
Returns minion configurations dict.
'''
@ -2948,20 +2959,28 @@ def apply_minion_config(overrides=None,
opts['__cli'] = os.path.basename(sys.argv[0])
if len(opts['sock_dir']) > len(opts['cachedir']) + 10:
opts['sock_dir'] = os.path.join(opts['cachedir'], '.salt-unix')
# No ID provided. Will getfqdn save us?
using_ip_for_id = False
if not opts.get('id'):
opts['id'], using_ip_for_id = get_id(
opts,
cache_minion_id=cache_minion_id)
if minion_id:
opts['id'] = minion_id
else:
opts['id'], using_ip_for_id = get_id(
opts,
cache_minion_id=cache_minion_id)
# it does not make sense to append a domain to an IP based id
if not using_ip_for_id and 'append_domain' in opts:
opts['id'] = _append_domain(opts)
for directory in opts.get('append_minionid_config_dirs', []):
if directory in ['pki_dir', 'cachedir', 'extension_modules']:
newdirectory = os.path.join(opts[directory], opts['id'])
opts[directory] = newdirectory
if len(opts['sock_dir']) > len(opts['cachedir']) + 10:
opts['sock_dir'] = os.path.join(opts['cachedir'], '.salt-unix')
# Enabling open mode requires that the value be set to True, and
# nothing else!
opts['open_mode'] = opts['open_mode'] is True

View File

@ -1693,13 +1693,13 @@ class MinionOptionParser(six.with_metaclass(OptionParserMeta, MasterOptionParser
class ProxyMinionOptionParser(six.with_metaclass(OptionParserMeta,
OptionParser,
ProxyIdMixIn,
ConfigDirMixIn,
MergeConfigMixIn,
LogLevelMixIn,
RunUserMixin,
DaemonMixIn,
SaltfileMixIn,
ProxyIdMixIn)): # pylint: disable=no-init
SaltfileMixIn)): # pylint: disable=no-init
description = (
'The Salt proxy minion, connects to and controls devices not able to run a minion. '
@ -1712,8 +1712,13 @@ class ProxyMinionOptionParser(six.with_metaclass(OptionParserMeta,
_default_logging_logfile_ = os.path.join(syspaths.LOGS_DIR, 'proxy')
def setup_config(self):
try:
minion_id = self.values.proxyid
except AttributeError:
minion_id = None
return config.minion_config(self.get_config_file_path(),
cache_minion_id=False)
cache_minion_id=False, minion_id=minion_id)
class SyndicOptionParser(six.with_metaclass(OptionParserMeta,