mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add the features into the file server to support file caching from the
environments
This commit is contained in:
parent
9aa5b7a296
commit
b3e7fb1886
2 changed files with 44 additions and 24 deletions
|
@ -329,28 +329,36 @@ class MWorker(multiprocessing.Process):
|
|||
'''
|
||||
Search the environment for the relative path
|
||||
'''
|
||||
fnd = {'path': '',
|
||||
'rel': ''}
|
||||
if not self.opts['file_roots'].has_key(env):
|
||||
return False
|
||||
return fnd
|
||||
for root in self.opts['file_roots'][env]:
|
||||
full = os.path.join(root, path)
|
||||
if os.path.isfile(full):
|
||||
return full
|
||||
return False
|
||||
fnd['path'] = full
|
||||
fnd['rel'] = path
|
||||
return fnd
|
||||
return fnd
|
||||
|
||||
def _serve_file(self, load):
|
||||
'''
|
||||
Return a chunk from a file based on the data received
|
||||
'''
|
||||
ret = {'data': '',
|
||||
'dest': ''}
|
||||
if not load.has_key('path')\
|
||||
or not load.has_key('loc')\
|
||||
or not load.has_key('env'):
|
||||
return self.crypticle.dumps('')
|
||||
path = self._find_file(load['path'], load['env'])
|
||||
if not path:
|
||||
return self.crypticle.dumps('')
|
||||
fn_ = open(path, 'rb')
|
||||
return self.crypticle.dumps(ret)
|
||||
fnd = self._find_file(load['path'], load['env'])
|
||||
if not fnd['path']:
|
||||
return self.crypticle.dumps(ret)
|
||||
ret['dest'] = fnd['rel']
|
||||
fn_ = open(fnd['path'], 'rb')
|
||||
fn_.seek(load['loc'])
|
||||
return self.crypticle.dumps(fn_.read(self.opts['file_buffer_size']))
|
||||
ret['data'] = fn_.read(self.opts['file_buffer_size'])
|
||||
return self.crypticle.dumps(ret)
|
||||
|
||||
def _file_hash(self, load):
|
||||
'''
|
||||
|
|
|
@ -354,32 +354,45 @@ class FileClient(object):
|
|||
raise MinionError('Unsupported path')
|
||||
return path[7:]
|
||||
|
||||
def get_file(self, path, dest, makedirs=False, env='base'):
|
||||
def get_file(self, path, dest='', makedirs=False, env='base'):
|
||||
'''
|
||||
Get a single file from the salt-master
|
||||
'''
|
||||
path = self._check_proto(path)
|
||||
payload = {'enc': 'aes'}
|
||||
destdir = os.path.dirname(dest)
|
||||
if not os.path.isdir(destdir):
|
||||
if makedirs:
|
||||
os.makedirs(destdir)
|
||||
else:
|
||||
return False
|
||||
fn_ = open(dest, 'w+')
|
||||
fn_ = None
|
||||
if dest:
|
||||
destdir = os.path.dirname(dest)
|
||||
if not os.path.isdir(destdir):
|
||||
if makedirs:
|
||||
os.makedirs(destdir)
|
||||
else:
|
||||
return False
|
||||
fn_ = open(dest, 'w+')
|
||||
load = {'path': path,
|
||||
'env': env,
|
||||
'cmd': '_serve_file'}
|
||||
while True:
|
||||
load['loc'] = fn_.tell()
|
||||
if not fn_:
|
||||
load['loc'] = 0
|
||||
else:
|
||||
load['loc'] = fn_.tell()
|
||||
payload['load'] = self.auth.crypticle.dumps(load)
|
||||
self.socket.send_pyobj(payload)
|
||||
data = self.auth.crypticle.loads(self.socket.recv_pyobj())
|
||||
if data == False:
|
||||
return False
|
||||
if not data:
|
||||
if not data['data']:
|
||||
break
|
||||
fn_.write(data)
|
||||
if not fn_:
|
||||
dest = os.path.join(
|
||||
self.opts['cachedir'],
|
||||
'files',
|
||||
data['dest']
|
||||
)
|
||||
destdir = os.path.dirname(dest)
|
||||
if not os.path.isdir(destdir):
|
||||
os.makedirs(destdir)
|
||||
fn_ = open(dest, 'w+')
|
||||
fn_.write(data['data'])
|
||||
return dest
|
||||
|
||||
def cache_file(self, path, env='base'):
|
||||
|
@ -387,8 +400,7 @@ class FileClient(object):
|
|||
Pull a file down from the file server and store it in the minion file
|
||||
cache
|
||||
'''
|
||||
dest = os.path.join(self.opts['cachedir'], 'files', path)
|
||||
return self.get_file(path, dest, True, env)
|
||||
return self.get_file(path, '', True, env)
|
||||
|
||||
def cache_files(self, paths, env='base'):
|
||||
'''
|
||||
|
|
Loading…
Add table
Reference in a new issue