import platform import meta import parser import tools import exc Log = tools.minimal_logger(__name__) def get_parser(**kw): """ Detect the proper parser class, and return it instantiated. Optional Arguments: parser The parser class to use instead of detecting the proper one. distro The distro to parse for (used for testing). kernel The kernel to parse for (used for testing). ifconfig The ifconfig (stdout) to pass to the parser (used for testing). """ parser = kw.get('parser', None) ifconfig = kw.get('ifconfig', None) if not parser:
import os import re import socket from meta import MetaMixin from tools import exec_cmd, hex2dotted, minimal_logger Log = minimal_logger(__name__) class IfcfgParser(MetaMixin): class Meta: ifconfig_cmd = 'ifconfig' for path in ['/sbin','/usr/sbin','/bin','/usr/bin']: if os.path.exists(os.path.join(path, ifconfig_cmd)): ifconfig_cmd = os.path.join(path, ifconfig_cmd) break ifconfig_cmd_args = [ifconfig_cmd, '-a'] patterns = [ '(?P<device>^[a-zA-Z0-9]+): flags=(?P<flags>.*) mtu (?P<mtu>.*)', '.*(inet )(?P<inet>[^\s]*).*', '.*(inet6 )(?P<inet6>[^\s]*).*', '.*(broadcast )(?P<broadcast>[^\s]*).*', '.*(netmask )(?P<netmask>[^\s]*).*', '.*(ether )(?P<ether>[^\s]*).*', '.*(prefixlen )(?P<prefixlen>[^\s]*).*', '.*(scopeid )(?P<scopeid>[^\s]*).*', '.*(ether )(?P<ether>[^\s]*).*', ] override_patterns = []