Add initial support for source to accept a list

This commit will allow file.managed to accept a list for the source
option. If the list index is a string then it must be a salt:// proto,
if the index is a single key dict then it can be an http/ftp source and
the value must be the source_hash
This commit is contained in:
Thomas S Hatch 2012-02-06 15:53:43 -07:00
parent dad4aa04f0
commit 7d12264110

View File

@ -459,6 +459,36 @@ def managed(name,
# Gather the source file from the server
sfn = ''
source_sum = {}
# If the source is a list then find which file exists
if isinstance(source, list):
# get the master file list
mfiles = __salt__['cp.list_master'](__env__)
for single in source:
if isinstance(single, dict):
# check the proto, if it is http or ftp then download the file
# to check, if it is salt then check the master list
if len(single) != 1:
continue
single_src = single[single.keys()[0]]
single_hash = single[single_src]
proto = urlparse.urlparse(single_src).scheme
if proto == 'salt':
if single_src in mfiles:
source = single_src
break
elif proto.startswith('http') or proto == 'ftp':
dest = temptile.mkstemp()[1]
fn_ = __salt__['cp.get_url'](single_src, dest)
os.remove(fn_)
if fn_:
source = single_src
source_hash = single_hash
break
elif isinstance(single, str):
if single in mfiles:
source = single
break
# If the file is a template and the contents is managed
# then make sure to cpy it down and templatize things.