Merge pull request #7400 from evinrude/develop

Symlink functionality in the default file server roots
This commit is contained in:
Thomas S Hatch 2013-09-22 16:08:03 -07:00
commit 9c3f3b1c2e
5 changed files with 81 additions and 0 deletions

View File

@ -220,6 +220,12 @@ class Client(object):
'''
return []
def symlink_list(self, env='base', prefix=''):
'''
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
@ -744,6 +750,23 @@ class RemoteClient(Client):
except SaltReqTimeoutError:
return ''
def symlink_list(self, env='base', prefix=''):
'''
List symlinked files and dirs on the master
'''
load = {'env': env,
'prefix': prefix,
'cmd': '_symlink_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

@ -271,3 +271,16 @@ class Fileserver(object):
if fstr in self.servers:
ret.update(self.servers[fstr](load))
return sorted(ret)
def symlink_list(self, load):
'''
Return a list of symlinked files and dirs
'''
ret = {}
if 'env' not in load:
return {}
for fsb in self._gen_back(None):
symlstr = '{0}.symlink_list'.format(fsb)
if symlstr in self.servers:
ret = self.servers[symlstr](load)
return ret

View File

@ -234,3 +234,33 @@ def dir_list(load):
followlinks=__opts__['fileserver_followsymlinks']):
ret.append(os.path.relpath(root, path))
return ret
def symlink_list(load):
'''
Return a dict of all symlinks based on a given path on the Master
'''
ret = {}
if load['env'] not in __opts__['file_roots']:
return ret
for path in __opts__['file_roots'][load['env']]:
try:
prefix = load['prefix'].strip('/')
except KeyError:
prefix = ''
# No need to follow symlinks here, this is a symlink hunt :-)
for root, dirs, files in os.walk(os.path.join(path, prefix),
followlinks=False):
for fname in files:
if not os.path.islink(os.path.join(root, fname)):
continue
rel_fn = os.path.relpath(
os.path.join(root, fname),
path
)
if not salt.fileserver.is_file_ignored(__opts__, rel_fn):
ret[rel_fn] = os.readlink(os.path.join(root, fname))
for dname in dirs:
if os.path.islink(os.path.join(root, dname)):
ret[dname] = os.readlink(os.path.join(root, dname))
return ret

View File

@ -731,6 +731,7 @@ class AESFuncs(object):
self._file_list = fs_.file_list
self._file_list_emptydirs = fs_.file_list_emptydirs
self._dir_list = fs_.dir_list
self._symlink_list = fs_.symlink_list
self._file_envs = fs_.envs
def __verify_minion(self, id_, token):

View File

@ -362,6 +362,20 @@ def list_master_dirs(env='base', prefix=''):
return __context__['cp.fileclient'].dir_list(env, prefix)
def list_master_symlinks(env='base', prefix=''):
'''
List all of the symlinks stored on the master
CLI Example:
.. code-block:: bash
salt '*' cp.list_master_symlinks
'''
_mk_client()
return __context__['cp.fileclient'].symlink_list(env, prefix)
def list_minion(env='base'):
'''
List all of the files cached on the minion