mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add environment seeking to the master file server
This commit is contained in:
parent
77c67af2cc
commit
677cac28c3
2 changed files with 25 additions and 13 deletions
|
@ -61,7 +61,7 @@
|
|||
# roots cannot match, otherwise the downloaded files will not be able to be
|
||||
# reliably ensured. A base environment is required to house the top file
|
||||
# Example:
|
||||
# file_root:
|
||||
# file_roots:
|
||||
# - base:
|
||||
# - /srv/salt/
|
||||
# - dev:
|
||||
|
|
|
@ -325,17 +325,28 @@ class MWorker(multiprocessing.Process):
|
|||
self._send_cluster()
|
||||
return ret
|
||||
|
||||
def _find_file(self, path, env='base'):
|
||||
'''
|
||||
Search the environment for the relative path
|
||||
'''
|
||||
if not self.opts['file_roots'].has_key(env):
|
||||
return False
|
||||
for root in self.opts['file_roots'][env]:
|
||||
full = os.path.join(root, path)
|
||||
if os.path.isfile(full):
|
||||
return full
|
||||
return False
|
||||
|
||||
def _serve_file(self, load):
|
||||
'''
|
||||
Return a chunk from a file based on the data received
|
||||
'''
|
||||
if not load.has_key('path') or not load.has_key('loc'):
|
||||
if not load.has_key('path')\
|
||||
or not load.has_key('loc')\
|
||||
or not load.has_key('env'):
|
||||
return False
|
||||
path = load['path']
|
||||
if path.startswith('/'):
|
||||
path = load['path'][1:]
|
||||
path = os.path.join(self.opts['file_root'], path)
|
||||
if not os.path.isfile(path):
|
||||
path = self._find_file(load['path'], load['env'])
|
||||
if not path:
|
||||
return ''
|
||||
fn_ = open(path, 'rb')
|
||||
fn_.seek(load['loc'])
|
||||
|
@ -345,14 +356,15 @@ class MWorker(multiprocessing.Process):
|
|||
'''
|
||||
Return a file hash, the hash type is set in the master config file
|
||||
'''
|
||||
if not load.has_key('path'):
|
||||
return False
|
||||
path = os.path.join(self.opts['file_root'], load['path'])
|
||||
if not os.path.isfile(path):
|
||||
if not load.has_key('path')\
|
||||
or not load.has_key('env'):
|
||||
return False
|
||||
path = self._find_file(load['path'], load['env'])
|
||||
if not path:
|
||||
return ''
|
||||
ret = {}
|
||||
ret['hsum'] = getattr(hashlib, self.opts['hash_type'])(open(path,
|
||||
'rb').read()).hexdigest()
|
||||
ret['hsum'] = getattr(hashlib, self.opts['hash_type'])(
|
||||
open(path, 'rb').read()).hexdigest()
|
||||
ret['hash_type'] = self.opts['hash_type']
|
||||
return self.crypticle.dumps(ret)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue