import re


def parse_show_ntp_associations(raw_result):
    """
    Parse the 'show ntp associations' command raw output.

    :param str raw_result: vtysh raw result string.
    :rtype: dict
    :return: The parsed result of the show ntp associations command in a \
        dictionary of the form:

     ::

        {
            '1': { 'code': '*',
                   'id': '1'
                   'name': '192.168.1.100',
                   'remote': '192.168.1.100',
                   'version': '3',
                   'key_id': '-',
                   'reference_id': '172.16.135.123',
                   'stratum': '4',
                   'type': 'U',
                   'last': '41',
                   'poll': '64',
                   'reach': '377',
                   'delay': '0.138',
                   'offset': '17.811',
                   'jitter': '1.942'
            },
            '2': { 'code': ' ',
                   'id': '2'
                   'name': '192.168.1.101',
                   'remote': '192.168.1.101',
                   'version': '3',
                   'key_id': '10',
                   'reference_id': '172.16.135.123',
                   'stratum': '4',
                   'type': 'U',
                   'last': '50',
                   'poll': '64',
                   'reach': '377',
                   'delay': '0.162',
                   'offset': '-1.749',
                   'jitter': '8.429'
            }
        }
    """

    ntp_asssociations_re = (
        r'(?P<code>\D)\s+(?P<id>\d+)\s+(?P<name>\S+)\s+'
        r'(?P<remote>\S+)\s+(?P<version>\d+)\s+(?P<key_id>\S+)\s+'
        r'(?P<reference_id>\S+)\s+(?P<stratum>\S+)\s+(?P<type>\S+)\s+'
        r'(?P<last>\S+)\s+(?P<poll>\S+)\s+(?P<reach>\S+)\s+'
        r'(?P<delay>\S+)\s+(?P<offset>\S+)\s+(?P<jitter>\S+)'
    )

    result = {}
    for line in raw_result.splitlines():
        re_result = re.search(ntp_asssociations_re, line)
        if re_result:
            partial = re_result.groupdict()
            result[partial['id']] = partial

    return result