Beispiel #1
0
def parse_interface(item, logical_system=None):
    iface = Interface()
    iface.name = item['name']
    iface.description = item.get('description')
    iface.vlantagging = 'vlan-tagging' in item or 'flexible-vlan-tagging' in item
    iface.unitdict = [parse_unit(u, logical_system) for u in item.get('unit', [])]
    iface.bundle = find_first('bundle', item) or None
    iface.tunneldict = [
        {
            'source': find('tunnel.source', u),
            'destination': find('tunnel.destination', u)
        } for u in item.get('unit', []) if 'tunnel' in u
    ]
    return iface
Beispiel #2
0
    def parse(self, nodeTree, physicalInterfaces=[]):
        host_name = get_hostname(ElementParser(nodeTree))
        interfaceNodes = [ 
                interface for i in ElementParser(nodeTree).all("interfaces") 
                if i.parent().tag() in ['configuration']
                for interface in i.all("interface") ]

        interfaces = []
        for node in interfaceNodes:
            interface = Interface()
            interface.name = node.first("name").text()
            if physicalInterfaces:
                if not interface.name in physicalInterfaces:
                    logger.warn("Interface {0} is configured but not found in {1}".format(interface.name, host_name))
                    continue
                else:
                    physicalInterfaces.remove(interface.name)

            interface.vlantagging = len(node.all("vlan-tagging")) > 0
            interface.bundle = node.first("bundle").text()
            interface.description = node.first("description").text()
            #TODO: tunnel dict..? Does it make sense when source/dest is empty?
            interface.tunneldict.append({
                'source': node.first("source").text(),
                'destination': node.first("destination").text(),
                })

            #Units
            interface.unitdict = [ self._unit(u) for u in node.all("unit") ]
            interfaces.append(interface)
        for iface in physicalInterfaces:
            interface = Interface()
            interface.name = iface
            interfaces.append(interface)

        return interfaces
Beispiel #3
0
def parse_interface(data):
    iface = Interface()
    iface.name = 'et{}'.format(data['name'])
    iface.description = data.get('description')

    return iface