Mount Entries

Parsers provided in this module includes:

Mount - command /bin/mount

ProcMounts - file /proc/mounts

The Mount class implements parsing for the mount command output which looks like:

/dev/mapper/rootvg-rootlv on / type ext4 (rw,relatime,barrier=1,data=ordered)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
/dev/mapper/HostVG-Config on /etc/shadow type ext4 (rw,noatime,seclabel,stripe=256,data=ordered)
dev/sr0 on /run/media/root/VMware Tools type iso9660 (ro,nosuid,nodev,relatime,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500,uhelper=udisks2) [VMware Tools]

The information is stored as a list of MountEntry objects. Each MountEntry object contains attributes for the following information that are listed in the same order as in the command output:

  • filesystem - Name of filesystem or the mounted device

  • mount_point - Name of mount point for filesystem

  • mount_type - Name of filesystem type

  • mount_options - Mount options as MountOpts object

  • mount_label - Optional label of this mount entry, empty string by default

  • mount_clause - Full raw string from command output

The MountOpts class contains the mount options as attributes accessible via the attribute name as it appears in the command output. For instance the options (rw,dmode=0500) may be accessed as ‘’mnt_row_info.rw`` with the value True and mnt_row_info.dmode with the value “0500”. The in operator may be used to determine if an option is present.

MountEntry lines are also available in a mounts property, keyed on the mount point.

class insights.parsers.mount.Mount(context, extra_bad_lines=[])[source]

Bases: insights.parsers.mount.MountedFileSystems

Class of information for all output from mount command.

Note

Please refer to its super-class MountedFileSystems for more details.

The typical output of mount command looks like:

/dev/mapper/rootvg-rootlv on / type ext4 (rw,relatime,barrier=1,data=ordered)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
/dev/mapper/HostVG-Config on /etc/shadow type ext4 (rw,noatime,seclabel,stripe=256,data=ordered)
dev/sr0 on /run/media/root/VMware Tools type iso9660 (ro,nosuid,nodev,relatime,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500,uhelper=udisks2) [VMware Tools]

Examples

>>> type(mnt_info)
<class 'insights.parsers.mount.Mount'>
>>> len(mnt_info)
4
>>> mnt_info[3].filesystem
'dev/sr0'
>>> mnt_info[3].mount_label
'[VMware Tools]'
>>> mnt_info[3].mount_type
'iso9660'
>>> 'ro' in mnt_info[3].mount_options
True
>>> mnt_info['/run/media/root/VMware Tools'].filesystem
'dev/sr0'
>>> mnt_info['/run/media/root/VMware Tools'].mount_label
'[VMware Tools]'
>>> mnt_info['/run/media/root/VMware Tools'].mount_options.ro
True
class insights.parsers.mount.MountEntry(data=None)[source]

Bases: insights.parsers.mount.AttributeAsDict

An object representing an mount entry of mount command or /proc/mounts file. Each entry contains below fixed attributes:

filesystem

Name of filesystem of mounted device

Type

str

mount_point

Name of mount point for filesystem

Type

str

mount_type

Name of filesystem type

Type

str

mount_options

Mount options as MountOpts

Type

MountOpts

mount_label

Optional label of this mount entry, an empty string by default

Type

str

mount_clause

Full raw string from command output

Type

str

class insights.parsers.mount.MountOpts(data=None)[source]

Bases: insights.parsers.mount.AttributeAsDict

An object representing the mount options found in mount or fstab entry as attributes accessible via the attribute name as it appears in the command output. For instance, the options (rw,dmode=0500) may be accessed as mnt_row_info.rw with the value True and mnt_row_info.dmode with the value “0500”.

The in operator may be used to determine if an option is present.

class insights.parsers.mount.MountedFileSystems(context, extra_bad_lines=[])[source]

Bases: insights.core.CommandParser

Base Class for Mount and ProcMounts.

rows

List of MountEntry objects for each row of the content.

Type

list

mounts

Dict with the mount_point as the key and the MountEntry objects as the value.

Type

dict

Raises
get_dir(path)[source]

This finds the most specific mount path that contains the given path, by successively removing the directory or file name on the end of the path and seeing if that is a mount point. This will always terminate since / is always a mount point. Strings that are not absolute paths will return None.

Parameters

path (str) -- The path to check.

Returns

The mount point that contains the given path.

Return type

MountEntry

parse_content(content)[source]

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

search(**kwargs)[source]

Returns a list of the mounts (in order) matching the given criteria. Keys are searched for directly - see the insights.parsers.keyword_search() utility function for more details. If no search parameters are given, no rows are returned.

Examples

>>> mounts.search(filesystem='proc')[0].mount_clause
'proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)'
>>> mounts.search(mount_options__contains='seclabel')[0].mount_clause
'/dev/mapper/HostVG-Config on /etc/shadow type ext4 (rw,noatime,seclabel,stripe=256,data=ordered)'
Parameters

**kwargs (dict) -- Dictionary of key-value pairs to search for.

Returns

The list of mount points matching the given criteria.

Return type

(list)

class insights.parsers.mount.ProcMounts(context, extra_bad_lines=[])[source]

Bases: insights.parsers.mount.MountedFileSystems

Class to parse the content of /proc/mounts file.

This class is required to parse the /proc/mounts file in addition to the /bin/mount command because it lists the mount points of those process’s which are not present in the output of the /bin/mount command.

Note

Please refer to its super-class MountedFileSystems for more details.

The typical content of /proc/mounts file looks like:

/dev/mapper/rootvg-rootlv / ext4 rw,relatime,barrier=1,data=ordered 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
/dev/mapper/HostVG-Config /etc/shadow ext4 rw,noatime,seclabel,stripe=256,data=ordered 0 0
dev/sr0 /run/media/root/VMware Tools iso9660 ro,nosuid,nodev,relatime,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500,uhelper=udisks2 0 0

Examples

>>> type(proc_mnt_info)
<class 'insights.parsers.mount.ProcMounts'>
>>> len(proc_mnt_info)
4
>>> proc_mnt_info[3].filesystem == 'dev/sr0'
True
>>> proc_mnt_info[3].mounted_device == 'dev/sr0'
True
>>> proc_mnt_info[3].mounted_device == proc_mnt_info[3].filesystem
True
>>> proc_mnt_info[3].mount_type == 'iso9660'
True
>>> proc_mnt_info[3].filesystem_type == 'iso9660'
True
>>> proc_mnt_info['/run/media/root/VMware Tools'].mount_label == ['0', '0']
True
>>> proc_mnt_info['/run/media/root/VMware Tools'].mount_options.ro
True
>>> proc_mnt_info['/run/media/root/VMware Tools'].mounted_device == 'dev/sr0'
True