import re


def parse_bytes(units_string):
    """Parse an LVM size string into bytes

    :returns: integer number of bytes
    """

    units_string = str(units_string)

    units = "bBkKmMgGtTpPeE"

    match = re.match(r"^(\d+(?:[.]\d+)?)([%s]|)$" % units, units_string)
    if not match:
        raise ValueError("Invalid LVM Unit syntax %r" % units_string)
    number, unit = match.groups()
    if not unit:
        unit = "M"
    unit = unit.upper()

    try:
        exponent = "BKMGTPE".index(unit)
    except ValueError:
        raise ValueError("Invalid unit %r. Must be B,K,M,G,T,P or E" % unit)

    return int(float(number) * 1024 ** (exponent))