import re


def parse_firewall_rule(rule_str):
    """
    Transforms a string of multiple inputes to a dictionary list
    parameter: (string) rules
        A firewall rule in the specified project
    Return firewall rules as dictionary list
    """
    rules = []
    regex = re.compile(r'ipprotocol=([\w\d_:.-]+),ports=([ /\w\d@_,.\*-]+)', flags=re.I)
    for f in rule_str.split(';'):
        match = regex.match(f)
        if match is None:
            raise ValueError('Could not parse field: %s' % (f,))

        rules.append({'IPProtocol': match.group(1), 'ports': match.group(2).split(',')})

    return rules