!
version 15.1
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
!
{%- if configuration.system.config['domain-name'] %}
ip domain-name {{ configuration.system.config['domain-name'].config.value.value  }}
{%- endif %}
{%- if configuration.cef is not defined or configuration.cef %}
!
ip cef
{%- endif %}
!
{%- if configuration.system.config.hostname %}
{# hostname {{ configuration.system.config.hostname.config.value.value }} #}
hostname {{ configuration.system.config.hostname.value.value }}
{%- endif %}
{%- if configuration.enable_secret %}
enable secret {{ configuration.enable_secret }}
{%- endif %}
!
{%- if configuration.system.users %}
{%- for user in configuration.system.users.config %}
username {{ user.name }} privilege {{ user.privilege | default(15) }} secret {{ user.secret }}
{%- endfor %}
{%- endif %}
!
{%- 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 intf.vrf %}
 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 == "ethernetCsmacd" %}
interface {{ intf.name }}
{%-    if intf.description %}
 description {{ intf.description.value }}
{%-    endif %}
{%- if intf.vrf %}
 vrf forwarding {{ intf.vrf}}
{%- endif %}
{%-    if intf.ipv4 %}
 ip address {{ intf.ipv4.value|cidr_to_addrmask }}
{%-     endif %}
{%-    if intf.enabled.value %}
 no shutdown
{%-    else %}
 shutdown
{%-   endif %}
{%-  endif %}
{%- endfor %}
!
{%- for _, intf in configuration.interfaces.items() %}
{%-  if intf.metadata.type == "l3ipvlan" %}
interface vlan{{ intf.vlan_id }}
{%-    if intf.description %}
 description {{ intf.description.value }}
{%-    endif %}
{%- if intf.vrf %}
 vrf forwarding {{ intf.vrf}}
{%- endif %}
{%-    if intf.ipv4 %}
 ip address {{ intf.ipv4.value|cidr_to_addrmask }}
{%-     endif %}
{%-    if intf.enabled.value %}
 no shutdown
{%- else %}
 shutdown
{%-     endif %}
{%-  endif %}
!
{%- endfor %}


{# 
!
{%- if configuration.routing %}
{%- if configuration.routing.static_routes %}
{%- for route in configuration.routing.static_routes %}
ip route {{ route.network }} {{ route.mask }} {{ route.next_hop }}
{%- endfor %}
{%- endif %}
{%- if configuration.routing.ospf %}
router ospf {{ configuration.routing.ospf.process_id | default(1) }}
{%- if configuration.routing.ospf.router_id %}
 router-id {{ configuration.routing.ospf.router_id }}
{%- endif %}
{%- if configuration.routing.ospf.networks %}
{%- for network in configuration.routing.ospf.networks %}
 network {{ network.address }} {{ network.wildcard }} area {{ network.area }}
{%- endfor %}
{%- endif %}
{%- endif %}
{%- endif %}
!
{%- for _, ni in configuration.network_instances.items() %}
{%-   for _, vlan in ni.vlans.items() %}
vlan {{ vlan.config.vlan_id.value }}
{%-      if vlan.config.vlan_name %}
 name {{ vlan.config.vlan_name.value }}
{%-      endif %}
!
{%-   endfor %}
{%- endfor %}
{%- if configuration.spanning_tree %}
spanning-tree mode {{ configuration.spanning_tree.mode | default('pvst') }}
{%- endif %}
!
{%- if configuration.snmp %}
{%- 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.ntp %}
{%- for server in configuration.ntp.servers %}
ntp server {{ server }}
{%- endfor %}
{%- endif %}
!
{%- if configuration.logging %}
{%- if configuration.logging.host %}
logging host {{ configuration.logging.host }}
{%- endif %}
logging buffered {{ configuration.logging.buffer_size | default(4096) }}
{%- endif %}
!
line con 0
 logging synchronous
 exec-timeout 0 0
line vty 0 4
{%- if configuration.users %}
 login local
{%- endif %}
 transport input ssh
!
{%- if configuration.ssh %}
ip ssh version 2
{%- if configuration.ssh.timeout %}
ip ssh time-out {{ configuration.ssh.timeout }}
{%- endif %}
{%- if configuration.ssh.authentication_retries %}
ip ssh authentication-retries {{ configuration.ssh.authentication_retries }}
{%- endif %}
{%- endif %}
! #}
