def parse_png()

in src/sonic-config-engine/minigraph.py [0:0]


def parse_png(png, hname, dpg_ecmp_content = None):
    neighbors = {}
    devices = {}
    console_dev = ''
    console_port = ''
    mgmt_dev = ''
    mgmt_port = ''
    port_speeds = {}
    console_ports = {}
    mux_cable_ports = {}
    port_device_map = {}
    png_ecmp_content = {}
    FG_NHG_MEMBER = {}
    FG_NHG = {}
    NEIGH = {}

    for child in png:
        if child.tag == str(QName(ns, "DeviceInterfaceLinks")):
            for link in child.findall(str(QName(ns, "DeviceLinkBase"))):
                linktype = link.find(str(QName(ns, "ElementType"))).text
                if linktype == "DeviceSerialLink":
                    enddevice = link.find(str(QName(ns, "EndDevice"))).text
                    endport = link.find(str(QName(ns, "EndPort"))).text
                    startdevice = link.find(str(QName(ns, "StartDevice"))).text
                    startport = link.find(str(QName(ns, "StartPort"))).text
                    baudrate = link.find(str(QName(ns, "Bandwidth"))).text
                    flowcontrol = 1 if link.find(str(QName(ns, "FlowControl"))) is not None and link.find(str(QName(ns, "FlowControl"))).text == 'true' else 0
                    if enddevice.lower() == hname.lower() and endport.isdigit():
                        console_ports[endport] = {
                            'remote_device': startdevice,
                            'baud_rate': baudrate,
                            'flow_control': flowcontrol
                        }
                    elif startport.isdigit():
                        console_ports[startport] = {
                            'remote_device': enddevice,
                            'baud_rate': baudrate,
                            'flow_control': flowcontrol
                        }
                    continue

                if linktype == "DeviceInterfaceLink":
                    endport = link.find(str(QName(ns, "EndPort"))).text
                    startdevice = link.find(str(QName(ns, "StartDevice"))).text
                    port_device_map[endport] = startdevice

                if linktype != "DeviceInterfaceLink" and linktype != "UnderlayInterfaceLink" and linktype != "DeviceMgmtLink":
                    continue

                enddevice = link.find(str(QName(ns, "EndDevice"))).text
                endport = link.find(str(QName(ns, "EndPort"))).text
                startdevice = link.find(str(QName(ns, "StartDevice"))).text
                startport = link.find(str(QName(ns, "StartPort"))).text
                bandwidth_node = link.find(str(QName(ns, "Bandwidth")))
                bandwidth = bandwidth_node.text if bandwidth_node is not None else None
                if enddevice.lower() == hname.lower():
                    if endport in port_alias_map:
                        endport = port_alias_map[endport]
                    if linktype != "DeviceMgmtLink":
                        neighbors[endport] = {'name': startdevice, 'port': startport}
                    if bandwidth:
                        port_speeds[endport] = bandwidth
                elif startdevice.lower() == hname.lower():
                    if startport in port_alias_map:
                        startport = port_alias_map[startport]
                    if linktype != "DeviceMgmtLink":
                        neighbors[startport] = {'name': enddevice, 'port': endport}
                    if bandwidth:
                        port_speeds[startport] = bandwidth

        if child.tag == str(QName(ns, "Devices")):
            for device in child.findall(str(QName(ns, "Device"))):
                (lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, name, hwsku, d_type, deployment_id, cluster, d_subtype) = parse_device(device)
                device_data = {}
                if hwsku != None:
                    device_data['hwsku'] = hwsku
                if cluster != None:
                    device_data['cluster'] = cluster
                if deployment_id != None:
                    device_data['deployment_id'] = deployment_id
                if lo_prefix != None:
                    device_data['lo_addr'] = lo_prefix
                if lo_prefix_v6 != None:
                    device_data['lo_addr_v6'] = lo_prefix_v6
                if mgmt_prefix != None:
                    device_data['mgmt_addr'] = mgmt_prefix
                if mgmt_prefix_v6 != None:
                    device_data['mgmt_addr_v6'] = mgmt_prefix_v6
                if d_type != None:
                    device_data['type'] = d_type
                if d_subtype != None:
                    device_data['subtype'] = d_subtype
                devices[name] = device_data

        if child.tag == str(QName(ns, "DeviceInterfaceLinks")):
            for if_link in child.findall(str(QName(ns, 'DeviceLinkBase'))):
                if str(QName(ns3, "type")) in if_link.attrib:
                    link_type = if_link.attrib[str(QName(ns3, "type"))]
                    if link_type == 'DeviceSerialLink':
                        for node in if_link:
                            if node.tag == str(QName(ns, "EndPort")):
                                console_port = node.text.split()[-1]
                            elif node.tag == str(QName(ns, "EndDevice")):
                                console_dev = node.text
                    elif link_type == 'DeviceMgmtLink':
                        for node in if_link:
                            if node.tag == str(QName(ns, "EndPort")):
                                mgmt_port = node.text.split()[-1]
                            elif node.tag == str(QName(ns, "EndDevice")):
                                mgmt_dev = node.text


        if child.tag == str(QName(ns, "DeviceInterfaceLinks")):
            for link in child.findall(str(QName(ns, 'DeviceLinkBase'))):
                if link.find(str(QName(ns, "ElementType"))).text == "LogicalLink":
                    intf_name = link.find(str(QName(ns, "EndPort"))).text
                    start_device = link.find(str(QName(ns, "StartDevice"))).text
                    if intf_name in port_alias_map:
                        intf_name = port_alias_map[intf_name]

                    mux_cable_ports[intf_name] = start_device

        if dpg_ecmp_content and (len(dpg_ecmp_content)):
            for version, content in dpg_ecmp_content.items():  # version is ipv4 or ipv6
                fine_grained_content = formulate_fine_grained_ecmp(version, content, port_device_map, port_alias_map)  # port_alias_map
                FG_NHG_MEMBER.update(fine_grained_content['FG_NHG_MEMBER'])
                FG_NHG.update(fine_grained_content['FG_NHG'])
                NEIGH.update(fine_grained_content['NEIGH'])

            png_ecmp_content = {"FG_NHG_MEMBER": FG_NHG_MEMBER, "FG_NHG": FG_NHG, "NEIGH": NEIGH}

    return (neighbors, devices, console_dev, console_port, mgmt_dev, mgmt_port, port_speeds, console_ports, mux_cable_ports, png_ecmp_content)