mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Merge pull request #42489 from garethgreenaway/rsync_with_salt_urls
Rsync with Salt URLs
This commit is contained in:
commit
33d350b0d0
@ -12,6 +12,8 @@ from __future__ import absolute_import
|
||||
# Import python libs
|
||||
import errno
|
||||
import logging
|
||||
import re
|
||||
import tempfile
|
||||
|
||||
# Import salt libs
|
||||
import salt.utils
|
||||
@ -70,7 +72,8 @@ def rsync(src,
|
||||
excludefrom=None,
|
||||
dryrun=False,
|
||||
rsh=None,
|
||||
additional_opts=None):
|
||||
additional_opts=None,
|
||||
saltenv='base'):
|
||||
'''
|
||||
.. versionchanged:: 2016.3.0
|
||||
Return data now contains just the output of the rsync command, instead
|
||||
@ -123,6 +126,9 @@ def rsync(src,
|
||||
additional_opts
|
||||
Any additional rsync options, should be specified as a list.
|
||||
|
||||
saltenv
|
||||
Specify a salt fileserver environment to be used.
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
@ -155,6 +161,38 @@ def rsync(src,
|
||||
if not src or not dst:
|
||||
raise SaltInvocationError('src and dst cannot be empty')
|
||||
|
||||
tmp_src = None
|
||||
if src.startswith('salt://'):
|
||||
_src = src
|
||||
_path = re.sub('salt://', '', _src)
|
||||
src_is_dir = False
|
||||
if _path in __salt__['cp.list_master_dirs'](saltenv=saltenv):
|
||||
src_is_dir = True
|
||||
|
||||
if src_is_dir:
|
||||
tmp_src = tempfile.mkdtemp()
|
||||
dir_src = __salt__['cp.get_dir'](_src,
|
||||
tmp_src,
|
||||
saltenv)
|
||||
if dir_src:
|
||||
src = tmp_src
|
||||
# Ensure src ends in / so we
|
||||
# get the contents not the tmpdir
|
||||
# itself.
|
||||
if not src.endswith('/'):
|
||||
src = '{0}/'.format(src)
|
||||
else:
|
||||
raise CommandExecutionError('{0} does not exist'.format(src))
|
||||
else:
|
||||
tmp_src = salt.utils.mkstemp()
|
||||
file_src = __salt__['cp.get_file'](_src,
|
||||
tmp_src,
|
||||
saltenv)
|
||||
if file_src:
|
||||
src = tmp_src
|
||||
else:
|
||||
raise CommandExecutionError('{0} does not exist'.format(src))
|
||||
|
||||
option = _check(delete,
|
||||
force,
|
||||
update,
|
||||
@ -173,6 +211,9 @@ def rsync(src,
|
||||
return __salt__['cmd.run_all'](cmd, python_shell=False)
|
||||
except (IOError, OSError) as exc:
|
||||
raise CommandExecutionError(exc.strerror)
|
||||
finally:
|
||||
if tmp_src:
|
||||
__salt__['file.remove'](tmp_src)
|
||||
|
||||
|
||||
def version():
|
||||
|
Loading…
Reference in New Issue
Block a user