Mount Entries

Parsers provided in this module includes:

Mount - command /bin/mount

ProcMounts - file /proc/mounts

MountInfo - file /proc/self/mountinfo

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:

  • mount_source - 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_addtlinfo - Additional mount information as MountAddtlInfo object

  • mount_clause - Full raw string from command output

  • filesystem - Name of filesystem or the mounted device (Deprecated)

ProcMounts and MountInfo classes have the similar style as mount.

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

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

Bases: object

Set the given key, value pair data as attribute of object.

The in operator could be used to determine if an attribute exists before direct accessing.

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

Bases: 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.MountAddtlInfo(data=None)[source]

Bases: AttributeAsDict

An object representing the additional information for an mount entry as attributes accessible via the attribute name. Object will provides different set of attributes according to different data sources.

mount_label

Label of this mount entry from command /bin/mount

Type

str

fs_freq

fs_freq of this mount entry from file /proc/mounts

Type

str

fs_passno

fs_passno of this mount entry from file /proc/mounts

Type

str

mount_id

Unique identifier of the mount from file /proc/self/mountinfo

Type

str

parent_id

Unique identifier of the parent mount from file /proc/self/mountinfo

Type

str

major_minor

Value of st_dev for files on filesystem from file /proc/self/mountinfo

Type

str

root

Root of the mount within the filesystem from file /proc/self/mountinfo

Type

str

optional_fields

Zero or more fields of the form “tag[:value]” from file /proc/self/mountinfo

Type

str

mount_clause_binmount

Full raw string from command /bin/mount

Type

str

mount_clause_procmounts

Full raw string from file /proc/mounts

Type

str

mount_clause_mountinfo

Full raw string from file /proc/self/mountinfo

Type

str

For instance, the major:minor number 253:4 could be accessed as mnt_row_info.major_minor with the value 253:4.

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

Bases: AttributeAsDict

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

mount_source

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_addtlinfo

Additional mount information as MountAddtlInfo

Type

MountAddtlInfo

mount_clause

Full raw string from command output

Type

str

filesystem

Name of filesystem of mounted device (Deprecated, use mount_source instead)

Type

str

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

Bases: MountedFileSystems

Class to parse the content of /proc/self/mountinfo file.

Note

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

The typical content of /proc/self/mountinfo file looks like:

39 0 253:0 / / rw,relatime shared:1 - xfs /dev/mapper/rootvg-lvlocroot rw,attr2,inode64,noquota
47 39 8:1 / /boot rw,relatime shared:30 - xfs /dev/sda1 rw,attr2,inode64,noquota
65 39 253:19 / /data rw,relatime shared:44 - ext4 /dev/mapper/vgdata-lvdata rw,data=ordered
58 39 253:15 / /opt rw,relatime shared:45 - xfs /dev/mapper/rootvg-lvlocopt rw,attr2,inode64,noquota
61 39 253:17 / /home rw,nosuid,relatime shared:46 - xfs /dev/mapper/rootvg-lvlochome rw,attr2,inode64,noquotao

Examples

>>> type(proc_mountinfo)
<class 'insights.parsers.mount.MountInfo'>
>>> len(proc_mountinfo)
5
>>> proc_mountinfo[2].mount_source
'/dev/mapper/vgdata-lvdata'
>>> proc_mountinfo[2].mount_type
'ext4'
>>> proc_mountinfo[2].mount_point
'/data'
>>> 'data' in proc_mountinfo[2].mount_options
True
>>> proc_mountinfo[2].mount_options.data
'ordered'
>>> 'major_minor' in proc_mountinfo[4]
False
>>> 'major_minor' in proc_mountinfo[4].mount_addtlinfo
True
>>> proc_mountinfo[4].mount_addtlinfo.major_minor
'253:17'
>>> proc_mountinfo['/boot'].mount_source
'/dev/sda1'
class insights.parsers.mount.MountOpts(data=None)[source]

Bases: 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”.

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

Bases: CommandParser

Base Class for Mount, ProcMounts and MountInfo.

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=None)[source]

Bases: 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