import re


def parse_show_platform(output):
    """
    :param output: output from 'show platform'
    :return: dictionary of nodes

    Platform: NCS6K
    RP/0/RP0/CPU0:Deploy#show platform
    Node              Type                       State             Config state
    --------------------------------------------------------------------------------
    0/2/CPU0          NC6-10X100G-M-P            IOS XR RUN        NSHUT
    0/RP0/CPU0        NC6-RP(Active)             IOS XR RUN        NSHUT
    0/RP1/CPU0        NC6-RP(Standby)            IOS XR RUN        NSHUT

    Platform: ASR9K-X64
    Node              Type                       State             Config state
    --------------------------------------------------------------------------------
    0/RSP0/CPU0       A9K-RSP880-SE(Active)      IOS XR RUN        NSHUT
    0/RSP1/CPU0       A9K-RSP880-SE(Standby)     IOS XR RUN        NSHUT
    0/FT0             ASR-9904-FAN               OPERATIONAL       NSHUT
    0/0/CPU0          A9K-8X100GE-L-SE           IOS XR RUN        NSHUT
    0/PT0
    """
    inventory = {}
    lines = output.split('\n')
    for line in lines:
        line = line.strip()
        if len(line) > 0 and line[0].isdigit():
            states = re.split('\s\s+', line)

            if not re.search('CPU\d+$', states[0]):
                continue

            node, node_type, state, config_state = states

            entry = {
                'type': node_type,
                'state': state,
                'config_state': config_state
            }
            inventory[node] = entry

    return inventory