mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 09:40:20 +00:00
Add source: {http,ftp} to the file.managed state
This commit is contained in:
parent
6c5e36f4a4
commit
1607550633
2 changed files with 43 additions and 22 deletions
|
@ -567,7 +567,6 @@ class Matcher(object):
|
|||
if not matcher:
|
||||
# If an unknown matcher is called at any time, fail out
|
||||
return False
|
||||
print comps
|
||||
results.append(
|
||||
str(getattr(
|
||||
self,
|
||||
|
@ -582,7 +581,6 @@ class Matcher(object):
|
|||
)('@'.join(comps[1:]))
|
||||
))
|
||||
|
||||
print ' '.join(results)
|
||||
return eval(' '.join(results))
|
||||
|
||||
class FileClient(object):
|
||||
|
@ -695,14 +693,28 @@ class FileClient(object):
|
|||
'''
|
||||
Get a single file from a URL.
|
||||
'''
|
||||
if urlparse.urlparse(url).scheme == 'salt':
|
||||
url_data = urlparse.urlparse(url)
|
||||
if url_data.scheme == 'salt':
|
||||
return self.get_file(url, dest, makedirs, env)
|
||||
destdir = os.path.dirname(dest)
|
||||
if not os.path.isdir(destdir):
|
||||
if makedirs:
|
||||
if dest:
|
||||
destdir = os.path.dirname(dest)
|
||||
if not os.path.isdir(destdir):
|
||||
if makedirs:
|
||||
os.makedirs(destdir)
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
dest = os.path.join(
|
||||
self.opts['cachedir'],
|
||||
'extrn_files',
|
||||
env,
|
||||
os.path.join(
|
||||
url_data.netloc,
|
||||
os.path.relpath(url_data.path, '/'))
|
||||
)
|
||||
destdir = os.path.dirname(dest)
|
||||
if not os.path.isdir(destdir):
|
||||
os.makedirs(destdir)
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
with contextlib.closing(urllib2.urlopen(url)) as srcfp:
|
||||
with open(dest, 'wb') as destfp:
|
||||
|
@ -722,7 +734,7 @@ class FileClient(object):
|
|||
Pull a file down from the file server and store it in the minion file
|
||||
cache
|
||||
'''
|
||||
return self.get_file(path, '', True, env)
|
||||
return self.get_url(path, '', True, env)
|
||||
|
||||
def cache_files(self, paths, env='base'):
|
||||
'''
|
||||
|
|
|
@ -144,6 +144,7 @@ def _clean_dir(root, keep):
|
|||
if fn_ == '/':
|
||||
break
|
||||
rm_files = []
|
||||
print real_keep
|
||||
for roots, dirs, files in os.walk(root):
|
||||
for name in files:
|
||||
nfn = os.path.join(roots, name)
|
||||
|
@ -428,26 +429,34 @@ def managed(name,
|
|||
source_sum = __salt__['cp.hash_file'](source, __env__)
|
||||
if not source_sum:
|
||||
ret['result'] = False
|
||||
ret['comment'] = ('Checksum for source file {0} not'
|
||||
' found').format(source)
|
||||
ret['comment'] = 'Source file {0} not found'.format(source)
|
||||
return ret
|
||||
else:
|
||||
# This file is not on a salt file server
|
||||
sum_file = __salt__['cp.cache_file'](source_hash)
|
||||
if not sum_file:
|
||||
elif source_hash:
|
||||
hash_fn = __salt__['cp.cache_file'](source_hash)
|
||||
if not hash_fn:
|
||||
ret['result'] = False
|
||||
ret['comment'] = ('Checksum for source file {0} not'
|
||||
' found').format(source)
|
||||
ret['comment'] = 'Source hash file {0} not found'.format(
|
||||
source_hash
|
||||
)
|
||||
return ret
|
||||
comps = open(sum_source, 'r').read().split('=')
|
||||
comps = open(hash_fn, 'r').read().split('=')
|
||||
if len(comps) < 2:
|
||||
ret['result'] = False
|
||||
ret['comment'] = ('Checksum for source file {0} not'
|
||||
' formatted properly').format(source)
|
||||
ret['comment'] = ('Source hash file {0} contains an '
|
||||
' invalid hash format, it must be in '
|
||||
' the format <hash type>=<hash>').format(
|
||||
source_hash
|
||||
)
|
||||
return ret
|
||||
source_sum['hash_type'] = comps[0]
|
||||
source_sum['hsum'] = comps[1]
|
||||
|
||||
source_sum['hash_type'] = comps[0]
|
||||
else:
|
||||
ret['result'] = False
|
||||
ret['comment'] = ('Unable to determine upstream hash of'
|
||||
' source file {0}').format(
|
||||
source
|
||||
)
|
||||
return ret
|
||||
# If the source file is a template render it accordingly
|
||||
|
||||
# Check changes if the target file exists
|
||||
|
|
Loading…
Add table
Reference in a new issue