{%- if configuration.asset.version -%}
version {{ configuration.asset.version | default('15.2') }}
{%- endif %}
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
service compress-config
!
{%- if configuration.system.config.hostname %}
hostname {{ configuration.system.config.hostname.value }}
{%- endif %}
!
boot-start-marker
boot-end-marker
!
!
{%- for ni in configuration.network_instances.values() %}
{%-   if ni.name.value != "global" %}
vrf definition {{ ni.name.value }}
 !
 address-family ipv4
 exit-address-family
 !
 address-family ipv6
 exit-address-family
!
{%-   endif %}
{%- endfor %}
!
!
!
{%- if configuration.system.aaa.config is defined and configuration.system.aaa.config.enabled %}
aaa new-model
{%- else %}
no aaa new-model
{%- endif %}
!
!
!
!
!
!
!
!
{%- if configuration.system.config.domain_name is defined and configuration.system.config.domain_name %}
ip domain-name {{ configuration.system.config.domain_name.value }}
{%- endif %}
{%- if configuration.cef is not defined or configuration.cef %}
ip cef
{%- endif %}
no ipv6 cef
!
!
!
spanning-tree mode pvst
spanning-tree extend system-id
!
!
!
!
!
!
!
!
!
!
!
!
!
{%- for _, intf in configuration.interfaces.items() %}
{%-  if intf.metadata.type == "softwareLoopback" %}
interface Loopback{{ intf.index.value }}
{%-    if intf.description %}
 description {{ intf.description.value }}
{%-    endif %}
{%- if 'vrf' in intf %}
 vrf forwarding {{ intf.vrf}}
{%- endif %}
{%-    if intf.ipv4 %}
 ip address {{ intf.ipv4.value|cidr_to_addrmask }}
{%-     endif %}
{%-  endif %}
{%- endfor %}
!
{%- for _, intf in configuration.interfaces.items() %}
{%-  if intf.metadata.type == "ieee8023adLag" %}
interface {{ intf.name }}
{%-    if intf.description %}
 description {{ intf.description.value }}
{%-    endif %}
{%- if 'vrf' in intf %}
 vrf forwarding {{ intf.vrf}}
{%- endif %}
{%- if 'ipv4' in intf %}
{%-    if intf.ipv4 %}
 ip address {{ intf.ipv4.value|cidr_to_addrmask }}
{%-     endif %}
{%- endif %}
{%-  if intf.switchport and intf.switchport.value %}
{%-    if intf.switchport_mode and intf.switchport_mode.value == "access" %}
 switchport mode access
{%-      if intf.native_vlan %}
 switchport access vlan {{ intf.native_vlan.value }}
{%-      endif %}
{%-    endif %}
{%-    if intf.switchport_mode and intf.switchport_mode.value == "trunk" %}
{%-      if intf.trunk_allowed_vlans %}
 switchport trunk allowed vlan {{ intf.trunk_allowed_vlans.value | join(',') }}
{%-      endif %}
{%-      if intf.native_vlan %}
 switchport trunk native vlan {{ intf.native_vlan.value }}
{%-      endif %}
 switchport trunk encapsulation dot1q
 switchport mode trunk
{%-    endif %}
{%-  endif %}
{%-  if intf.enabled and not intf.enabled.value %}
 shutdown
{%-   endif %}
{%-  endif %}
{%-  if intf.metadata.type == "ieee8023adLag" %}
!
{%-  endif %}
{%- endfor %}
!
{%- for _, intf in configuration.interfaces.items() %}
{%-  if intf.metadata.type == "ethernetCsmacd" %}
interface {{ intf.name }}
{%-    if intf.description %}
 description {{ intf.description.value }}
{%-    endif %}
{%- if 'vrf' in intf %}
 vrf forwarding {{ intf.vrf}}
{%- endif %}
{%- if 'ipv4' in intf %}
{%-    if intf.ipv4 %}
 ip address {{ intf.ipv4.value|cidr_to_addrmask }}
{%-     endif %}
{%- endif %}
{%-  if intf.switchport and intf.switchport.value %}
{%-    if intf.switchport_mode and intf.switchport_mode.value == "access" %}
 switchport mode access
{%-      if intf.native_vlan %}
 switchport access vlan {{ intf.native_vlan.value }}
{%-      endif %}
{%-    endif %}
{%-    if intf.switchport_mode and intf.switchport_mode.value == "trunk" %}
{%-      if intf.trunk_allowed_vlans %}
 switchport trunk allowed vlan {{ intf.trunk_allowed_vlans.value | join(',') }}
{%-      endif %}
{%-      if intf.native_vlan %}
 switchport trunk native vlan {{ intf.native_vlan.value }}
{%-      endif %}
 switchport trunk encapsulation dot1q
 switchport mode trunk
{%-  endif %}
{%-  if intf.lacp_enabled %}
 channel-group {{ intf.aggregate_id.value }} mode {{ intf.lacp_mode.value | default('active') }}
{%-    if intf.lacp_port_priority %}
 lacp port-priority {{ intf.lacp_port_priority.value }}
{%-    endif %}
{%-    if intf.lacp_interval %}
 lacp rate {{ intf.lacp_interval.value }}
{%-    endif %}
{%-  endif %}
{%-  endif %}
{%-  if intf.enabled and not intf.enabled.value %}
 shutdown
{%-   endif %}
{%-  endif %}
{%- if 'negotiation' in intf and intf.negotiation and intf.negotiation.value %}
 negotiation auto
{%- endif %}
{%-  if intf.metadata.type == "ethernetCsmacd" %}
!
{%-  endif %}
{%- endfor %}
{%- for _, intf in configuration.interfaces.items() %}
{%-  if intf.metadata.type == "l3ipvlan" and intf.vlan_id %}
interface Vlan{{ intf.vlan_id }}
{%-    if intf.description %}
 description {{ intf.description.value }}
{%-    endif %}
{%- if 'vrf' in intf %}
 vrf forwarding {{ intf.vrf}}
{%- endif %}
{%-    if intf.ipv4 %}
 ip address {{ intf.ipv4.value|cidr_to_addrmask }}
{%-     endif %}
{%-    if intf.enabled and not intf.enabled.value %}
 shutdown
{%-     endif %}
{%-  endif %}
{%-  if intf.metadata.type == "l3ipvlan" %}
!
{%-  endif %}
{%- endfor %}
{%- for _, intf in configuration.interfaces.items() %}
{%-  if intf.metadata.type == "ManagementInterface" and intf.name %}
interface {{ intf.name.value }}
{%-    if intf.description %}
 description {{ intf.description.value }}
{%-    endif %}
{%- if 'vrf' in intf %}
 vrf forwarding {{ intf.vrf}}
{%- endif %}
{%-    if intf.ipv4 %}
 ip address {{ intf.ipv4.value|cidr_to_addrmask }}
{%-     endif %}
{%-    if intf.enabled and not intf.enabled.value %}
 shutdown
{%-     endif %}
{%-  endif %}
{%-  if intf.metadata.type == "ManagementInterface" and intf.name %}
!
{%-  endif %}
{%- endfor %}
{%- if configuration.system.config.default_gateway is defined and configuration.system.config.default_gateway %}
ip default-gateway {{ configuration.system.config.default_gateway }}
{%- endif %}
ip forward-protocol nd
!
ip http server
ip http secure-server
!
{%- for _,ni in configuration.network_instances.items() %}
{%-   if ni.protocols.static_routes is not none %}
{%-      for _,route in ni.protocols.static_routes.items() %}
{%-        if route.network_instance.value != "global" %}
{%-          for _,next_hop in route.next_hops.items() %}
{%-            if next_hop.metric.value is defined %}
ip route vrf {{ route.network_instance.value }} {{ route.prefix.value }} {{ next_hop.next_hop.value }} metric {{ next_hop.metric.value }}
{%-            else %}
ip route vrf {{ route.network_instance.value }} {{ route.prefix.value }} {{ next_hop.next_hop.value }}
{%-            endif %}
{%-          endfor %}
{%-        else %}
{%-          for _,next_hop in route.next_hops.items() %}
{%-            if next_hop.metric.value is defined %}
ip route {{ route.prefix.value }} {{ next_hop.next_hop.value }} metric {{ next_hop.metric.value }}
{%-            else %}
ip route {{ route.prefix.value }} {{ next_hop.next_hop.value }}
{%-            endif %}
{%-          endfor %}
{%-        endif %}
{%-      endfor %}
{%-   endif %}
{%- endfor %}
{%- set ssh = configuration.system.ssh.config -%}
{%- if ssh and ssh.get('enable') and ssh.get('enable').value %}
{%-   if ssh.get('protocol_version') %}
ip ssh version {{ ssh.get('protocol_version').value | default(2) }}
{%-   endif %}
{%-   if ssh.get('timeout') %}
ip ssh time-out {{ ssh.get('timeout').value }}
{%-   endif %}
{%-   if ssh.get('auth_retries') %}
ip ssh authentication-retries {{ ssh.get('auth_retries').value }}
{%-   endif %}
{%-   if ssh.get('source_interface') %}
ip ssh source-interface {{ ssh['source_interface'] }}
{%-   endif %}
{%- endif %}
ip ssh server algorithm encryption aes128-ctr aes192-ctr aes256-ctr
ip ssh client algorithm encryption aes128-ctr aes192-ctr aes256-ctr
!
{%- if "lacp" in configuration -%}
{%-   if configuration.lacp.config.system_priority %}
lacp system-priority {{ configuration.lacp.config.system_priority.value }}
{%-   endif %}
{%-   if configuration.lacp.config.system_id_mac %}
lacp system-id mac {{ configuration.lacp.config.system_id_mac.value }}
{%-   endif %}
{%-   if configuration.lacp.config.load_balance_algorithm %}
{%-     set alg = configuration.lacp.config.load_balance_algorithm.value %}
{%-     if alg is string %}
port-channel load-balance {{ alg }}
{%-     elif alg is sequence and alg | length >= 2 %}
port-channel load-balance extended {{ alg | join(' ') }}
{%-     elif alg is sequence and alg | length == 1 %}
port-channel load-balance {{ alg[0] }}
{%-     else %}
port-channel load-balance {{ alg }}
{%-     endif %}
{%-   endif %}
{%- endif %}
!
{%- if "snmp" in configuration -%}
{%- if configuration.snmp.community %}
snmp-server community {{ configuration.snmp.community }} {{ configuration.snmp.access | default('RO') }}
{%- endif %}
{%- if configuration.snmp.location %}
snmp-server location {{ configuration.snmp.location }}
{%- endif %}
{%- if configuration.snmp.contact %}
snmp-server contact {{ configuration.snmp.contact }}
{%- endif %}
{%- endif %}
!
{%- if configuration.system.ntp -%}
{%- for server in configuration.system.ntp.servers.values() %}
{%-   if server.prefer %}
ntp server {{ server.address.value }} prefer
{%-   else %}
ntp server {{ server.address.value }}
{%-   endif %}
{%- endfor %}
{%- endif %}
!
{%- if configuration.system.logging -%}
{%-   if configuration.system.logging.config and configuration.system.logging.config.get('buffer_size') %}
logging buffered {{ configuration.system.logging.config['buffer_size'].value | default(4096) }}
{%-   endif %}
{%-   if configuration.system.logging.get('remote_servers') %}
{%-     for server in configuration.system.logging.get('remote_servers').values() %}
{%-       if server.host %}
logging host {{ server.host }}
{%-         if server.source_address %}
logging source-interface {{ server.source_address.value }}
{%-         endif %}
{%-       endif %}
{%-     endfor %}
{%-   endif %}
{%- endif %}
!
!
control-plane
!
banner exec ^C
IOSv - Cisco Systems Confidential -
Supplemental End User License Restrictions
This IOSv software is provided AS-IS without warranty of any kind. Under no circumstances may this software be used separate from the Cisco Modeling Labs Software that this software was provided with, or deployed or used as part of a production environment.
By using the software, you agree to abide by the terms and conditions of the Cisco End User License Agreement at http://www.cisco.com/go/eula. Unauthorized use or distribution of this software is expressly prohibited.
^C
banner incoming ^C
IOSv - Cisco Systems Confidential -
Supplemental End User License Restrictions
This IOSv software is provided AS-IS without warranty of any kind. Under no circumstances may this software be used separate from the Cisco Modeling Labs Software that this software was provided with, or deployed or used as part of a production environment.
By using the software, you agree to abide by the terms and conditions of the Cisco End User License Agreement at http://www.cisco.com/go/eula. Unauthorized use or distribution of this software is expressly prohibited.
^C
{%- if configuration.system.config.login_banner is defined and configuration.system.config.login_banner.value %}
banner login ^C
{{ configuration.system.config.login_banner.value }}
^C
{%- endif %}
{%- if configuration.system.config.motd_banner is not none and configuration.system.config.motd_banner.value %}
banner motd ^C
{{ configuration.system.config.motd_banner.value  }}
^C
{%- endif %}
!
line con 0
line aux 0
line vty 0 4
 login local
 transport input ssh
!
!
end