Skip to content

Commit

Permalink
Merge branch 'master' into virtual_grain_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cmcmarrow authored Dec 7, 2019
2 parents be2fcc1 + 825a3b0 commit 9b28ddd
Show file tree
Hide file tree
Showing 41 changed files with 2,538 additions and 822 deletions.
29 changes: 29 additions & 0 deletions doc/ref/configuration/minion.rst
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,35 @@ FQDN (for instance, Solaris).
append_domain: foo.org
.. conf_minion:: minion_id_remove_domain

``minion_id_remove_domain``
---------------------------

.. versionadded:: Neon

Default: ``False``

Remove a domain when the minion id is generated as a fully qualified domain
name (either by the user provided ``id_function``, or by Salt). This is useful
when the minions shall be named like hostnames. Can be a single domain (to
prevent name clashes), or True, to remove all domains.

Examples:
- minion_id_remove_domain = foo.org
- FQDN = king_bob.foo.org --> minion_id = king_bob
- FQDN = king_bob.bar.org --> minion_id = king_bob.bar.org
- minion_id_remove_domain = True
- FQDN = king_bob.foo.org --> minion_id = king_bob
- FQDN = king_bob.bar.org --> minion_id = king_bob


For more information, please see :issue:`49212` and :pull:`49378`.

.. code-block:: yaml
minion_id_remove_domain: foo.org
.. conf_minion:: minion_id_lowercase

``minion_id_lowercase``
Expand Down
29 changes: 29 additions & 0 deletions salt/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,9 @@ def _gather_buffer_space():
# Always generate minion id in lowercase.
'minion_id_lowercase': bool,

# Remove either a single domain (foo.org), or all (True) from a generated minion id.
'minion_id_remove_domain': (six.string_types, bool),

# If set, the master will sign all publications before they are sent out
'sign_pub_messages': bool,

Expand Down Expand Up @@ -1440,6 +1443,7 @@ def _gather_buffer_space():
'grains_refresh_every': 0,
'minion_id_caching': True,
'minion_id_lowercase': False,
'minion_id_remove_domain': False,
'keysize': 2048,
'transport': 'zeromq',
'auth_timeout': 5,
Expand Down Expand Up @@ -3565,6 +3569,26 @@ def call_id_function(opts):
sys.exit(salt.defaults.exitcodes.EX_GENERIC)


def remove_domain_from_fqdn(opts, newid):
'''
Depending on the values of `minion_id_remove_domain`,
remove all domains or a single domain from a FQDN, effectivly generating a hostname.
'''
opt_domain = opts.get('minion_id_remove_domain')
if opt_domain is True:
if '.' in newid:
# Remove any domain
newid, xdomain = newid.split('.', 1)
log.debug('Removed any domain (%s) from minion id.', xdomain)
else:
# Must be string type
if newid.upper().endswith('.' + opt_domain.upper()):
# Remove single domain
newid = newid[:-len('.' + opt_domain)]
log.debug('Removed single domain %s from minion id.', opt_domain)
return newid


def get_id(opts, cache_minion_id=False):
'''
Guess the id of the minion.
Expand Down Expand Up @@ -3616,6 +3640,11 @@ def get_id(opts, cache_minion_id=False):
if opts.get('minion_id_lowercase'):
newid = newid.lower()
log.debug('Changed minion id %s to lowercase.', newid)

# Optionally remove one or many domains in a generated minion id
if opts.get('minion_id_remove_domain'):
newid = remove_domain_from_fqdn(opts, newid)

if '__role' in opts and opts.get('__role') == 'minion':
if opts.get('id_function'):
log.debug(
Expand Down
2 changes: 1 addition & 1 deletion salt/modules/beacons.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def save(**kwargs):
beacons = list_(return_yaml=False, include_pillar=False, **kwargs)

# move this file into an configurable opt
sfn = os.path.join(__opts__['config_dir'],
sfn = os.path.join(os.path.dirname(__opts__['conf_file']),
os.path.dirname(__opts__['default_include']),
'beacons.conf')
if beacons:
Expand Down
22 changes: 20 additions & 2 deletions salt/modules/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3353,11 +3353,29 @@ def link(src, path):
try:
os.link(src, path)
return True
except (OSError, IOError):
raise CommandExecutionError('Could not create \'{0}\''.format(path))
except (OSError, IOError) as E:
raise CommandExecutionError('Could not create \'{0}\': {1}'.format(path, E))
return False


def is_hardlink(path):
'''
Check if the path is a hard link by verifying that the number of links
is larger than 1
CLI Example:
.. code-block:: bash
salt '*' file.is_hardlink /path/to/link
'''

# Simply use lstat and count the st_nlink field to determine if this path
# is hardlinked to something.
res = lstat(os.path.expanduser(path))
return res and res['st_nlink'] > 1


def is_link(path):
'''
Check if the path is a symbolic link
Expand Down
6 changes: 4 additions & 2 deletions salt/netapi/rest_cherrypy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,9 +820,11 @@ def cors_tool():
resp_head['Connection'] = 'keep-alive'
resp_head['Access-Control-Max-Age'] = '1400'

# CORS requests should short-circuit the other tools.
cherrypy.response.body = ''
# Note: CherryPy on Py3 uses binary objects for the response
# Python 2.6 also supports the byte prefix, so no need for conditionals
cherrypy.response.body = b''
cherrypy.response.status = 200
# CORS requests should short-circuit the other tools.
cherrypy.serving.request.handler = None

# Needed to avoid the auth_tool check.
Expand Down
4 changes: 4 additions & 0 deletions salt/states/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,10 @@ def extracted(name,
Set this to ``True`` if archive should be extracted if source_hash has
changed. This would extract regardless of the ``if_missing`` parameter.
Note that this is only checked if the ``source`` value has not changed.
If it has (e.g. to increment a version number in the path) then the
archive will not be extracted even if the hash has changed.
.. versionadded:: 2016.3.0
skip_verify : False
Expand Down
Loading

0 comments on commit 9b28ddd

Please sign in to comment.