From 992e8b22cc0763e6e4c4b0fd9071c7b306d08bb1 Mon Sep 17 00:00:00 2001 From: Joseph Hall Date: Sun, 20 Jan 2013 18:32:35 -0700 Subject: [PATCH] Adding initial nfs execution module --- salt/modules/nfs.py | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 salt/modules/nfs.py diff --git a/salt/modules/nfs.py b/salt/modules/nfs.py new file mode 100644 index 0000000000..92b24ced48 --- /dev/null +++ b/salt/modules/nfs.py @@ -0,0 +1,50 @@ +''' +Module for managing NFS. +''' + +# Import python libs +import logging + +import salt.utils + +log = logging.getLogger(__name__) + + +def __virtual__(): + ''' + Only work on posix-like systems + ''' + # Disable on these platorms, specific service modules exist: + disable = [ + 'Windows', + ] + if not salt.utils.which('showmount'): + return False + return 'nfs' + + +def list_exports(exports='/etc/exports'): + ''' + List configured exports + + CLI Example:: + + salt '*' nfs.list_exports + ''' + ret = {} + f = open(exports, 'r') + for line in f.read().splitlines(): + if not line: + continue + if line.startswith('#'): + continue + comps = line.split() + ret[comps[0]] = {'hosts': [], 'options': []} + for perm in comps[1:]: + permcomps = perm.split('(') + permcomps[1] = permcomps[1].replace(')', '') + ret[comps[0]]['hosts'] = permcomps[0].split(',') + ret[comps[0]]['options'] = permcomps[1].split(',') + f.close() + return ret +