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:
Thomas S Hatch 2012-09-27 09:13:48 -07:00
commit 36d4f9766b
4 changed files with 64 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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():