# NFS exports configuration¶

NFSExports and NFSExportsD provide a parsed output of the content of an exports file as defined in man exports(5). The content is parsed into a dictionary, where the key is the export path and the value is another dictionary, where the key is the hostname and the value is the option list, parsed into an actual list.

The default ("-") hostname is not specially handled, nor are wildcards.

If export paths are defined multiple times in a file, only the first one is parsed. All subsequent redefinitions are not parsed and the raw line is added to the ignored_lines member.

All raw lines are kept in raw_lines, which is a dict where the key is the export path and the value is the stripped raw line.

Parsers included in this module are:

## NFSExportsD - files in the nfs_exports.d directory¶

Sample content of the /etc/exports file:

/home/utcs/shared/ro                    @group(ro,sync)   ins1.example.com(rw,sync,no_root_squash) ins2.example.com(rw,sync,no_root_squash)
/home/insights/shared/rw                @group(rw,sync)   ins1.example.com(rw,sync,no_root_squash) ins2.example.com(ro,sync,no_root_squash)
/home/insights/shared/special/all/mail  @group(rw,sync,no_root_squash)
/home/insights/ins/special/all/config   @group(ro,sync,no_root_squash)  ins1.example.com(rw,sync,no_root_squash)
#/home/insights                          ins1.example.com(rw,sync,no_root_squash)
/home/example                           @group(rw,sync,root_squash) ins1.example.com(rw,sync,no_root_squash) ins2.example.com(rw,sync,no_root_squash)
# A duplicate host for this exported path
/home/example                           ins2.example.com(rw,sync,no_root_squash)


Examples

>>> type(exports)
<class 'insights.parsers.nfs_exports.NFSExports'>
>>> type(exports.data) == type({})
True
>>> exports.raw_lines['/home/insights/shared/rw']  # List of lines that define this path
['/home/insights/shared/rw                @group(rw,sync)   ins1.example.com(rw,sync,no_root_squash) ins2.example.com(ro,sync,no_root_squash)']
>>> exports.raw_lines['/home/example']  # Lines are stored even if they contain duplicate hosts
['/home/example                           @group(rw,sync,root_squash) ins1.example.com(rw,sync,no_root_squash) ins2.example.com(rw,sync,no_root_squash)', '/home/example                           ins2.example.com(rw,sync,no_root_squash)']
>>> exports.ignored_exports
{'/home/example': {'ins2.example.com': ['rw', 'sync', 'no_root_squash']}}
>>> sorted(list(exports.all_options()))
['no_root_squash', 'ro', 'root_squash', 'rw', 'sync']
>>> sorted(list(exports.export_paths()))
['/home/example', '/home/insights/ins/special/all/config', '/home/insights/shared/rw', '/home/insights/shared/special/all/mail', '/home/utcs/shared/ro']

class insights.parsers.nfs_exports.NFSExports(context)[source]

Subclass to attach nfs_exports spec to

class insights.parsers.nfs_exports.NFSExportsBase(context)[source]

Class to parse /etc/exports and /etc/exports.d/*.exports.

Exports are stored keyed on the path of the export, and then the host definition. The flags are stored as a list. NFS allows the same path to be listed on multiple lines and in multiple files, but an exported path can only have one definition for a given host.

data

Key is export path, value is a dict, where the key is the client host and the value is a list of options.

Type

dict

ignored_exports

A dictionary of exported paths that have host definitions that conflicted with a previous definition.

Type

dict

ignored_lines

A synonym for the above ignored_exports dictionary, for historical reasons.

Type

dict

raw_lines

The list of the raw lines that define each exported path, including any lines that may have ignored exports.

Type

dict of lists

all_options()[source]

Returns the set of all options used in all export entries

export_paths()[source]

Returns the set of all export paths as strings

parse_content(content)[source]

This method must be implemented by classes based on this class.

static reconstitute(path, d)[source]

Warning

This function is deprecated. Please use the raw_lines dictionary property of the parser instance instead, as this contains the actual lines from the exports file.

‘Reconstitute’ a line from its parsed value. The original lines are not used for this. The hosts in d are listed in alphabetical order, and the options are listed in the order originally given.

Parameters
• path (str) -- The exported path

• d (dict) -- The hosts definition of the exported path

Returns

A line simulating the definition of that exported path to those hosts.

Return type

str

class insights.parsers.nfs_exports.NFSExportsD(context)[source]

Subclass to attach nfs_exports.d spec to