FSTab - file /etc/fstab
Parse the /etc/fstab
file into a list of lines. Each line is a dictionary
of fields, named according to their definitions in man fstab
:
fs_spec
- the device to mountfs_file
- the mount pointfs_vfstype
- the type of file systemfs_mntops
- the mount options as a dictionaryfs_freq
- the dump frequencyfs_passno
- check the filesystem on reboot in this pass numberraw_fs_mntops
- the mount options as a stringraw
- the RAW line which is useful to front-end
fs_freq
and fs_passno
are recorded as integers if found, and zero if
not present.
fs_mntops
is wrapped as a as a insights.parsers.mount.MountOpts
object. For instance, the option rw
in rw,dmode=0500
may be accessed as
mnt_row_info.rw
with the value True
, and the dmode
can be accessed
as mnt_row_info.dmode
with the value 0500
.
This data, as above, is available in the data
property:
Wrapped as an
FSTabEntry
, each column can also be accessed as an attribute with the same name.
The FSTabEntry
for each mount point is also available via the
FSTab.mounted_on
property; the data is the same as that stored in the
FSTab.data
list.
- class insights.parsers.fstab.FSTab(context)[source]
Bases:
Parser
Parse the content of
/etc/fstab
.Typical content of the
fstab
looks like:# # /etc/fstab # Created by anaconda on Fri May 6 19:51:54 2016 # /dev/mapper/rhel_hadoop--test--1-root / xfs defaults 0 0 UUID=2c839365-37c7-4bd5-ac47-040fba761735 /boot xfs defaults 0 0 /dev/mapper/rhel_hadoop--test--1-home /home xfs defaults 0 0 /dev/mapper/rhel_hadoop--test--1-swap swap swap defaults 0 0 /dev/sdb1 /hdfs/data1 xfs rw,relatime,seclabel,attr2,inode64,noquota 0 0 /dev/sdc1 /hdfs/data2 xfs rw,relatime,seclabel,attr2,inode64,noquota 0 0 /dev/sdd1 /hdfs/data3 xfs rw,relatime,seclabel,attr2,inode64,noquota 0 0 localhost:/ /mnt/hdfs nfs rw,vers=3,proto=tcp,nolock,timeo=600 0 0 /dev/mapper/vg0-lv2 /test1 ext4 defaults,data=writeback 1 1 nfs_hostname.redhat.com:/nfs_share/data /srv/rdu/cases/000 nfs ro,defaults,hard,intr,bg,noatime,nodev,nosuid,nfsvers=3,tcp,rsize=32768,wsize=32768 0
Examples
>>> type(fstab) <class 'insights.parsers.fstab.FSTab'> >>> len(fstab) 9 >>> fstab.data[0]['fs_spec'] # Note that data is a list not a dict here '/dev/mapper/rhel_hadoop--test--1-root' >>> fstab.data[0].fs_spec '/dev/mapper/rhel_hadoop--test--1-root' >>> fstab.data[0].raw '/dev/mapper/rhel_hadoop--test--1-root / xfs defaults 0 0' >>> fstab.data[0].fs_mntops.defaults True >>> 'relatime' in fstab.data[0].fs_mntops False >>> fstab.data[0].fs_mntops.get('relatime') None >>> fstab.mounted_on['/hdfs/data3'].fs_spec '/dev/sdd1'
- data
a list of parsed fstab entries as
FSTabEntry
objects.- Type:
list
- mounted_on
a dictionary of
FSTabEntry
objects keyed on mount point.- Type:
dict
- fsspec_of_path(path)[source]
Return the device name if longest-matched mount-point of path is found, else None. If path contains any blank, pass it in directly or escape with ‘ ‘, eg: ‘/VM TOOLS/cache’ or ‘/VM TOOLS/cache’
- search(**kwargs)[source]
Search for the given key/value pairs in the data. Please refer to the
insights.parsers.keyword_search()
function documentation for a more complete description of how to use this.Fields that can be searched (as per
man fstab
):fs_spec
: the block special or remote filesystem path or label.fs_file
: The mount point for the filesystem.fs_vfstype
: The file system type.fs_mntops
: The mount options. Since this is also a dictionary, this can be searched using __contains - see the examples below.fs_freq
: The dump frequency - rarely used.fs_passno
: The pass for file system checks - rarely used.
Examples
- Search for the root file system:
fstab.search(fs_file='/')
- Search for file systems mounted from a LABEL declaration
fstab.search(fs_spec__startswith='LABEL=')
- Search for file systems that use the ‘uid’ mount option:
fstab.search(fs_mntops__contains='uid')
- Search for XFS file systems using the ‘relatime’ option:
fstab.search(fs_vfstype='xfs', fs_mntops__contains='relatime')
- class insights.parsers.fstab.FSTabEntry(data=None)[source]
Bases:
AttributeAsDict
An object representing an entry in
/etc/fstab
. Each entry contains below fixed attributes:- fs_spec
the device to mount
- Type:
str
- fs_file
the mount point
- Type:
str
- fs_vfstype
the type of file system
- Type:
str
- fs_mntops
the mount options as a
insights.parser.mount.MountOpts
- Type:
dict
- fs_freq
the dump frequency
- Type:
int
- fs_passno
check the filesystem on reboot in this pass number
- Type:
int
- raw_fs_mntops
the mount options as a string
- Type:
str
- raw
the RAW line which is useful to front-end
- Type:
str