mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Add upload_path
to cp.push_dir
This commit is contained in:
parent
72ed91a00b
commit
c4cf0a687a
@ -705,7 +705,7 @@ def push(path, keep_symlinks=False, upload_path=None):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def push_dir(path, glob=None):
|
def push_dir(path, glob=None, upload_path=None):
|
||||||
'''
|
'''
|
||||||
Push a directory from the minion up to the master, the files will be saved
|
Push a directory from the minion up to the master, the files will be saved
|
||||||
to the salt master in the master's minion files cachedir (defaults to
|
to the salt master in the master's minion files cachedir (defaults to
|
||||||
@ -718,18 +718,24 @@ def push_dir(path, glob=None):
|
|||||||
is disabled by default for security purposes. To enable, set ``file_recv``
|
is disabled by default for security purposes. To enable, set ``file_recv``
|
||||||
to ``True`` in the master configuration file, and restart the master.
|
to ``True`` in the master configuration file, and restart the master.
|
||||||
|
|
||||||
|
upload_path
|
||||||
|
Provide a different path and directory name inside the master's minion
|
||||||
|
files cachedir
|
||||||
|
|
||||||
CLI Example:
|
CLI Example:
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
salt '*' cp.push /usr/lib/mysql
|
salt '*' cp.push /usr/lib/mysql
|
||||||
|
salt '*' cp.push /usr/lib/mysql upload_path='/newmysql/path'
|
||||||
salt '*' cp.push_dir /etc/modprobe.d/ glob='*.conf'
|
salt '*' cp.push_dir /etc/modprobe.d/ glob='*.conf'
|
||||||
'''
|
'''
|
||||||
if '../' in path or not os.path.isabs(path):
|
if '../' in path or not os.path.isabs(path):
|
||||||
return False
|
return False
|
||||||
|
tmpupload_path = upload_path
|
||||||
path = os.path.realpath(path)
|
path = os.path.realpath(path)
|
||||||
if os.path.isfile(path):
|
if os.path.isfile(path):
|
||||||
return push(path)
|
return push(path, upload_path=upload_path)
|
||||||
else:
|
else:
|
||||||
filelist = []
|
filelist = []
|
||||||
for root, dirs, files in os.walk(path):
|
for root, dirs, files in os.walk(path):
|
||||||
@ -737,7 +743,11 @@ def push_dir(path, glob=None):
|
|||||||
if glob is not None:
|
if glob is not None:
|
||||||
filelist = [fi for fi in filelist if fnmatch.fnmatch(fi, glob)]
|
filelist = [fi for fi in filelist if fnmatch.fnmatch(fi, glob)]
|
||||||
for tmpfile in filelist:
|
for tmpfile in filelist:
|
||||||
ret = push(tmpfile)
|
if upload_path and tmpfile.startswith(path):
|
||||||
|
tmpupload_path = os.path.join(os.path.sep,
|
||||||
|
upload_path.strip(os.path.sep),
|
||||||
|
tmpfile.replace(path, '').strip(os.path.sep))
|
||||||
|
ret = push(tmpfile, upload_path=tmpupload_path)
|
||||||
if not ret:
|
if not ret:
|
||||||
return ret
|
return ret
|
||||||
return True
|
return True
|
||||||
|
Loading…
Reference in New Issue
Block a user