Added gitfs_root option

This commit is contained in:
Jason Sommer 2013-08-17 20:14:57 -05:00
parent 49a6cfdc51
commit 201b4f8776
4 changed files with 55 additions and 8 deletions

View file

@ -313,6 +313,11 @@
# environments.
# Note: file:// repos will be treated as a remote, so refs you want used must
# exist in that repo as *local* refs.
#
# The gitfs_root option gives the ability to serve files from a subdirectory
# within the repository. The path is defined relative to the root of the
# repository and defaults to the repository root.
#gitfs_root: somefolder/otherfolder
##### Pillar settings #####

View file

@ -111,6 +111,31 @@ it will be pulled from the :strong:`git://github.com/example/second.git` git
repo. If :strong:`salt://haproxy/haproxy.conf` is requested then it will be
pulled from the third repo.
Serving from a Subdirectory
===========================
The ``gitfs_root`` option gives the ability to serve files from a subdirectory
within the repository. The path is defined relative to the root of the
repository.
With this repository structure:
.. code-block:: yaml
repository.git:
somefolder
otherfolder
top.sls
edit/vim.sls
edit/vimrc
nginx/init.sls
Configuration and files can be accessed normally with:
.. code-block:: yaml
gitfs_root: somefolder/otherfolder
Multiple Backends
=================

View file

@ -119,6 +119,7 @@ VALID_OPTS = {
'keep_jobs': int,
'master_roots': dict,
'gitfs_remotes': list,
'gitfs_root': str,
'ext_pillar': list,
'pillar_version': int,
'pillar_opts': bool,
@ -261,6 +262,7 @@ DEFAULT_MASTER_OPTS = {
'base': ['/srv/pillar'],
},
'gitfs_remotes': [],
'gitfs_root': '',
'ext_pillar': [],
'pillar_version': 2,
'pillar_opts': True,

View file

@ -38,6 +38,8 @@ def __virtual__():
'''
if not isinstance(__opts__['gitfs_remotes'], list):
return False
if not isinstance(__opts__['gitfs_root'], str):
return False
if not 'git' in __opts__['fileserver_backend']:
return False
if not HAS_GIT:
@ -182,6 +184,10 @@ def find_file(path, short='base', **kwargs):
'rel': ''}
if os.path.isabs(path):
return fnd
local_path = path
path = os.path.join(__opts__['gitfs_root'], local_path)
if short == 'base':
short = 'master'
dest = os.path.join(__opts__['cachedir'], 'gitfs/refs', short, path)
@ -228,7 +234,7 @@ def find_file(path, short='base', **kwargs):
with salt.utils.fopen(blobshadest, 'r') as fp_:
sha = fp_.read()
if sha == blob.hexsha:
fnd['rel'] = path
fnd['rel'] = local_path
fnd['path'] = dest
return fnd
with salt.utils.fopen(lk_fn, 'w+') as fp_:
@ -246,7 +252,7 @@ def find_file(path, short='base', **kwargs):
os.remove(lk_fn)
except (OSError, IOError):
pass
fnd['rel'] = path
fnd['rel'] = local_path
fnd['path'] = dest
return fnd
return fnd
@ -319,11 +325,14 @@ def file_list(load):
ref = _get_ref(repo, load['env'])
if not ref:
continue
tree = ref.commit.tree
try:
tree = ref.commit.tree / __opts__['gitfs_root']
except KeyError:
continue
for blob in tree.traverse():
if not isinstance(blob, git.Blob):
continue
ret.append(blob.path)
ret.append(os.path.relpath(blob.path, __opts__['gitfs_root']))
return ret
@ -341,12 +350,15 @@ def file_list_emptydirs(load):
ref = _get_ref(repo, load['env'])
if not ref:
continue
tree = ref.commit.tree
try:
tree = ref.commit.tree / __opts__['gitfs_root']
except KeyError:
continue
for blob in tree.traverse():
if not isinstance(blob, git.Tree):
continue
if not blob.blobs:
ret.append(blob.path)
ret.append(os.path.relpath(blob.path, __opts__['gitfs_root']))
return ret
@ -364,9 +376,12 @@ def dir_list(load):
ref = _get_ref(repo, load['env'])
if not ref:
continue
tree = ref.commit.tree
try:
tree = ref.commit.tree / __opts__['gitfs_root']
except KeyError:
continue
for blob in tree.traverse():
if not isinstance(blob, git.Tree):
continue
ret.append(blob.path)
ret.append(os.path.relpath(blob.path, __opts__['gitfs_root']))
return ret