<template name="Cisco_IOSXR" results="per_template">
<doc>
Sample structure produced by this template:
```
{'Cisco_IOSXR': {'switch-1': {'cdp_peers': [{'source': 'switch-1', 
                                           'src_label': 'Ge4/6',
                                           'target': {'bottom_label': 'cisco WS-C6509',
                                                      'id': 'switch-2',
                                                      'top_label': '10.2.2.2'},
                                           'trgt_label': 'Ge1/5'},
                                          {'source': 'switch-1',
                                           'src_label': 'Ge4/7',
                                           'target': {'bottom_label': 'cisco WS-C6509',
                                                      'id': 'switch-2',
                                                      'top_label': '10.2.2.2'},
                                           'trgt_label': 'Ge1/6'}],
                            'interfaces': {'Ge1/1': {'description': 'switch-3:Gi0/1',
                                                     'is_l2': True,
                                                     'l2_mode': 'trunk',
                                                     'lag_id': '11',
                                                     'lag_mode': 'active',
                                                     'mtu': '9216',
                                                     'state': {'admin': 'up',
                                                               'bw_kbits': '10000000',
                                                               'description': 'switch-3:Gi0/1',
                                                               'duplex': 'Full',
                                                               'hardware': 'Ten Gigabit Ethernet '
                                                                           'Port',
                                                               'is_physical_port': True,
                                                               'line': 'up',
                                                               'line_status': 'connected',
                                                               'link_speed': '10Gb/s',
                                                               'link_type': 'auto',
                                                               'mac': 'a89d.2163.1111',
                                                               'media_type': '10GBase-LR',
                                                               'mtu': '9216'},
                                                     'trunk_vlans': '101'}
                                           'Ge4/6': {'description': 'switch-2: trunk',
                                                     'is_l2': True,
                                                     'l2_mode': 'trunk',
                                                     'lag_id': '3',
                                                     'lag_mode': 'active',
                                                     'trunk_vlans': '200,201,202,203,204,205'}
                                           'LAG11': {'description': 'switch-3: trunk LAG',
                                                     'is_l2': True,
                                                     'l2_mode': 'trunk',
                                                     'trunk_vlans': '101'},
                                           'LAG3': {'description': 'switch-2: trunk LAG',
                                                    'is_l2': True,
                                                    'l2_mode': 'trunk',
                                                    'state': {'admin': 'up',
                                                              'bw_kbits': '20000000',
                                                              'description': 'switch-2: trunk LAG',
                                                              'duplex': 'Full',
                                                              'hardware': 'EtherChannel',
                                                              'lag_members': 'Ge4/6 Ge4/7',
                                                              'line': 'up',
                                                              'line_status': 'connected',
                                                              'link_type': '10Gb/s',
                                                              'mac': 'a89d.2163.3333',
                                                              'media_type': 'N/A',
                                                              'mtu': '1500'},
                            'node_facts': {'vlans': {'101': 'test_vlan', '200': 'ProdVMS'}}},
               'switch-2': {'cdp_peers': [{'source': 'switch-2',
                                           'src_label': 'Ge1/5',
                                           'target': {'bottom_label': 'cisco WS-C6509',
                                                      'id': 'switch-1',
                                                      'top_label': '10.1.1.1'},
                                           'trgt_label': 'Ge4/6'},
                                          {'source': 'switch-2',
                                           'src_label': 'Ge1/6',
                                           'target': {'bottom_label': 'cisco WS-C6509',
                                                      'id': 'switch-1',
                                                      'top_label': '10.1.1.1'},
                                           'trgt_label': 'Ge4/7'}],
                            'interfaces': {'Ge1/5': {'description': 'switch-1: trunk',
                                                     'is_l2': True,
                                                     'l2_mode': 'trunk',
                                                     'lag_id': '3',
                                                     'lag_mode': 'active',
                                                     'trunk_vlans': '200,201,202,203,204,205'}
                            'node_facts': {'vlans': {'101': 'test_vlan', '200': 'ProdVMS'}}}}}
```
</doc>

<vars>local_hostname="gethostname"</vars>

<macro>
def check_is_physical_port(data):
    for item in _ttp_["vars"]["physical_ports"]:
        if data.startswith(item) and not "." in item:
            return data, {"is_physical_port": True}
    return data
</macro>

<input>url = "./Cisco_IOSXR/"</input>

<!-- Interfaces configuration group -->
<group name="{{ local_hostname }}.interfaces**.{{ interface }}**">
interface {{ interface | resuball(IfsNormalize) }}
 mtu {{ mtu }}
 vrf {{ vrf }}
 description {{ description | re(".+") }}
 ipv4 address {{ ip | PHRASE | joinmatches(",") }}
 ipv4 address {{ ip | PHRASE | joinmatches(",") }} secondary
 ipv6 address {{ ip | joinmatches(",") }}
 bundle id {{ lag_id | DIGIT }} mode {{ lag_mode }}
</group>

<!-- Interfaces state group -->
<group name="{{ local_hostname }}.interfaces**.{{ interface }}**.state">
{{ interface | _start_ | resuball(IfsNormalize) | macro("check_is_physical_port") }} is {{ admin | ORPHRASE }}, line protocol is {{ line | ORPHRASE }}
  Hardware is {{ hardware }} interface(s)
  Hardware is {{ hardware }} interface
  Hardware is {{ hardware | ORPHRASE }} interface(s), address is {{ mac }}
  Hardware is {{ hardware | ORPHRASE }}, address is {{ mac }} (bia {{ ignore }})
  Description: {{ description | re(".+") }}
  Internet address is {{ ip }}
  MTU {{ mtu }} bytes, BW {{ bw_kbits }} Kbit (Max: 1000000 Kbit)
  MTU {{ mtu }} bytes, BW {{ bw_kbits }} Kbit
  {{ duplex }}-duplex, {{ link_speed }}
  {{ duplex }}-duplex, {{ link_speed }}, link type is {{ link_type }}
  {{ duplex }}-duplex, {{ link_speed }}, {{ media_type }}, link type is {{ link_type }}
      {{ lag_members | joinmatches(" ") }}  {{ ignore }}-duplex  {{ ignore }} {{ ignore }}
</group>

<!-- LLDP peers group -->
<group name="{{ local_hostname }}.lldp_peers*" expand="">
Local Interface: {{ src_label | resuball(IfsNormalize) }}
Chassis id: {{ data.chassis_id }}
Port id: {{ trgt_label | ORPHRASE | resuball(IfsNormalize) }}
Port Description: {{ data.peer_port_description | re(".+") }}
System Name: {{ target.id | split(".") | item(0) | split("(") | item(0) }}
System Capabilities: {{ data.peer_capabilities | ORPHRASE }}
  IPv4 address: {{ target.top_label }}
{{ source | set("local_hostname") }}
</group>


<!-- CDP peers group -->
<group name="{{ local_hostname }}.cdp_peers*" expand="">
Device ID: {{ target.id | split(".") | item(0) | split("(") | item(0) }}
  IPv4 address: {{ target.top_label }}
Platform: {{ target.bottom_label | ORPHRASE }},  Capabilities: {{ data.peer_capabilities | ORPHRASE }}
Interface: {{ src_label | resuball(IfsNormalize) }}
Port ID (outgoing port): {{ trgt_label | ORPHRASE | resuball(IfsNormalize) }}
{{ source | set("local_hostname") }}
</group>
</template>