import re


def sysinfo(info):
    """
        Parses information returned from drac getsysinfo command
        and returns it as a dictionary
    """
    out={}
    parsers = [
    r'(Firmware Version\s+=\s(?P<firmware>[.\d]+))',
    r'(System BIOS Version\s+=\s(?P<bios>[.\d]+))',
        r'(System Model\s+=\s(?P<model>[ \w]+))',
        r'(Service Tag\s+=\s(?P<hw_tag>\w+))',
        r'(MAC Address\s+=\s(?P<drac>[a-f:0-9]+))',
        r'(?P<hwname>NIC\d+)\sEthernet\s+=\s(?P<hwaddr>[a-f:0-9]+)',
        ]

    for line in info.split('\n'):
        for pattern in parsers:
            match = re.search(pattern, line)
            if match:
                if 'hwname' in match.groupdict().keys():
                    num = match.group('hwname').replace('NIC','')
                    out['eth%d' % (int(num)-1)] = match.group('hwaddr')
                else:
                    for key in match.groupdict().keys():
                        out[key] = match.group(key)
                        if key == 'model' and re.match('PowerEdge', match.group(key)):
                            out['manufacturer'] = 'Dell'
    return out