mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Merge pull request #2110 from DarkSinclair/develop
Allowing source in file.recurse to be a list object, as in file.manage. ...
This commit is contained in:
commit
36d4f9766b
@ -203,6 +203,12 @@ class Client(object):
|
||||
'''
|
||||
return []
|
||||
|
||||
def dir_list(self, env='base'):
|
||||
'''
|
||||
This function must be overwritten
|
||||
'''
|
||||
return []
|
||||
|
||||
def is_cached(self, path, env='base'):
|
||||
'''
|
||||
Returns the full path to a file if it is cached locally on the minion
|
||||
@ -449,6 +455,18 @@ class LocalClient(Client):
|
||||
ret.append(os.path.relpath(root, path))
|
||||
return ret
|
||||
|
||||
def dir_list(self, env='base'):
|
||||
'''
|
||||
List the dirs in the file_roots
|
||||
'''
|
||||
ret = []
|
||||
if env not in self.opts['file_roots']:
|
||||
return ret
|
||||
for path in self.opts['file_roots'][env]:
|
||||
for root, dirs, files in os.walk(path, followlinks=True):
|
||||
ret.append(os.path.relpath(root, path))
|
||||
return ret
|
||||
|
||||
def hash_file(self, path, env='base'):
|
||||
'''
|
||||
Return the hash of a file, to get the hash of a file in the file_roots
|
||||
@ -622,6 +640,23 @@ class RemoteClient(Client):
|
||||
except SaltReqTimeoutError:
|
||||
return ''
|
||||
|
||||
def dir_list(self, env='base'):
|
||||
'''
|
||||
List the dirs on the master
|
||||
'''
|
||||
load = {'env': env,
|
||||
'cmd': '_dir_list'}
|
||||
try:
|
||||
return self.auth.crypticle.loads(
|
||||
self.sreq.send(
|
||||
'aes',
|
||||
self.auth.crypticle.dumps(load),
|
||||
3,
|
||||
60)
|
||||
)
|
||||
except SaltReqTimeoutError:
|
||||
return ''
|
||||
|
||||
def hash_file(self, path, env='base'):
|
||||
'''
|
||||
Return the hash of a file, to get the hash of a file on the salt
|
||||
|
@ -675,6 +675,18 @@ class AESFuncs(object):
|
||||
ret.append(os.path.relpath(root, path))
|
||||
return ret
|
||||
|
||||
def _dir_list(self, load):
|
||||
'''
|
||||
Return a list of all directories on the master
|
||||
'''
|
||||
ret = []
|
||||
if load['env'] not in self.opts['file_roots']:
|
||||
return ret
|
||||
for path in self.opts['file_roots'][load['env']]:
|
||||
for root, dirs, files in os.walk(path, followlinks=True):
|
||||
ret.append(os.path.relpath(root, path))
|
||||
return ret
|
||||
|
||||
def _master_opts(self, load):
|
||||
'''
|
||||
Return the master options to the minion
|
||||
|
@ -200,6 +200,18 @@ def list_master(env='base'):
|
||||
return client.file_list(env)
|
||||
|
||||
|
||||
def list_master_dirs(env='base'):
|
||||
'''
|
||||
List all of the directories stored on the master
|
||||
|
||||
CLI Exmaple::
|
||||
|
||||
salt '*' cp.list_master_dirs
|
||||
'''
|
||||
client = salt.fileclient.get_file_client(__opts__)
|
||||
return client.dir_list(env)
|
||||
|
||||
|
||||
def list_minion(env='base'):
|
||||
'''
|
||||
List all of the files cached on the minion
|
||||
|
@ -286,6 +286,7 @@ def _source_list(source, source_hash, env):
|
||||
if isinstance(source, list):
|
||||
# get the master file list
|
||||
mfiles = __salt__['cp.list_master'](env)
|
||||
mdirs = __salt__['cp.list_master_dirs'](env)
|
||||
for single in source:
|
||||
if isinstance(single, dict):
|
||||
# check the proto, if it is http or ftp then download the file
|
||||
@ -309,7 +310,7 @@ def _source_list(source, source_hash, env):
|
||||
source_hash = single_hash
|
||||
break
|
||||
elif isinstance(single, string_types):
|
||||
if single[7:] in mfiles:
|
||||
if single[7:] in mfiles or single[7:] in mdirs:
|
||||
source = single
|
||||
break
|
||||
return source, source_hash
|
||||
@ -1501,6 +1502,9 @@ def recurse(name,
|
||||
if _ret['changes']:
|
||||
ret['changes'][path] = changetype
|
||||
|
||||
# If source is a list, find which in the list actually exists
|
||||
source, source_hash = _source_list(source, '', env)
|
||||
|
||||
vdir = set()
|
||||
for fn_ in __salt__['cp.cache_dir'](source, env, include_empty):
|
||||
if not fn_.strip():
|
||||
|
Loading…
Reference in New Issue
Block a user