IfCFG - files /etc/sysconfig/network-scripts/ifcfg-*

IfCFG is a parser for the network interface definition files in /etc/sysconfig/network-scripts. These are pulled into the network scripts using source, so they are mainly bash environment declarations of the form KEY=value. These are stored in the data property as a dictionary. Quotes surrounding the value

Three options are handled differently:

  • BONDING_OPTS is usually a quoted list of key=value arguments separated by spaces.

  • TEAM_CONFIG and TEAM_PORT_CONFIG are treated as JSON stored as a single string. Double quotes within the string are escaped using double back slashes, and these are removed so that the quoting is preserved.

Because this parser reads multiple files, the interfaces are stored as a list within the parser and need to be iterated through in order to find specific interfaces.

Sample configuration from a teamed interface in file /etc/sysconfig/network-scripts/ifcfg-team1:

TEAM_CONFIG='{"runner": {"name": "lacp", "active": "true", "tx_hash": ["eth", "ipv4"]}, "tx_balancer": {"name": "basic"}, "link_watch": {"name": "ethtool"}}'


>>> for nic in shared[IfCFG]: # Parser contains list of all interfaces
...     print 'NIC:', nic.iname
...     print 'IP address:', nic['IPADDR']
...     if 'TEAM_CONFIG' in nic:
...         print 'Team runner name:', nic['TEAM_CONFIG']['runner']['name']
NIC: team1
IP addresss:
Team runner name: lacp
class insights.parsers.ifcfg.IfCFG(context)[source]

Bases: LegacyItemAccess, CommandParser

Parse ifcfg- file,return a dict contain ifcfg config file info. “iface” key is interface name parse from file name TEAM_CONFIG, TEAM_PORT_CONFIG will return a dict with user config dict BONDING_OPTS also will return a dict

ifname (str): The interface name as defined in the name of the file

(i.e. the part after ifcfg-).

property bonding_mode

(int) the numeric value of bonding mode, or None if no bonding mode is found.

property has_empty_line

(bool) True if the file has empty line else False.


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