{% set optmap = {
  'addresses': 'address',
  'hwaddr': 'hwaddress',
  'up_cmds': 'up',
  'down_cmds': 'down',
  'pre_up_cmds': 'pre-up',
  'post_up_cmds': 'post-up',
  'pre_down_cmds': 'pre-down',
  'post_down_cmds': 'post-down',
  'master': 'bond-master',
  'accept_ra': 'accept_ra',
  } -%}
{% set concat_opts = ['dns_nameservers'] -%}
{% set valid_opts = [
  'autoconf', 'privext', 'dhcp', 'hwaddress', 'vlan_raw_device', 'address', 'addresses', 'netmask',
  'metric', 'gateway', 'pointopoint', 'scope', 'hostname', 'media', 'leasehours', 'leasetime',
  'vendor', 'client', 'bootfile', 'server', 'mode', 'endpoint', 'dstaddr', 'local', 'ttl', 'mtu',
  'provider', 'unit', 'options', 'master', 'dns_nameservers', 'wireless_mode', 'wpa_ap_scan',
  'wpa_conf', 'wpa_driver', 'wpa_group', 'wpa_key_mgmt', 'wpa_pairwise', 'wpa_proto', 'wpa_psk',
  'wpa_roam', 'wpa_ssid', 'accept_ra'
  ] -%}
{% if data.enabled %}auto {{ name }}
{% endif %}{% if data.hotplug %}allow-hotplug {{ name }}
{% endif %}{% for inet in ['inet', 'inet6'] -%}
{% if data.data[inet] and data.data[inet].addrfam == inet %}{% set interface = data.data[inet] -%}
{% if interface.proto and interface.addrfam %}iface {{name}} {{interface.addrfam}} {{interface.proto}}
{% for opt in valid_opts %}{% set debopt = optmap.get(opt, opt.replace('_', '-')) -%}
{% set val = interface.get(opt, False) %}{% if val -%}
{% if opt in concat_opts and val is iterable %}    {{ debopt }} {{ val|join(' ') }}
{% elif val is string or val is number       %}    {{ debopt }} {{ val }}
{% elif val is iterable %}{% for v in val    %}    {{ debopt }} {{ v }}
{% endfor %}{% endif %}{% endif -%}
{% endfor %}{% if interface.ethtool %}{% for item in interface.ethtool_keys -%}
{% if interface.ethtool[item] is string      %}    {{ item }} {{ interface.ethtool[item] }}
{% elif interface.ethtool[item] is iterable  %}    {{ item }} {{ interface.ethtool[item]|join(' ') }}
{% endif %}{% endfor %}{% endif %}{% if interface.bonding  %}{% for item in interface.bonding_keys  -%}
{% if interface.bonding[item] is string      %}    bond-{{ item }} {{ interface.bonding[item] }}
{% elif interface.bonding[item] is iterable  %}    bond-{{ item }} {{ interface.bonding[item]|join(' ') }}
{% endif %}{% endfor %}{% endif %}{% if interface.bridging %}{% for item in interface.bridging_keys -%}.
{% if interface.bridging[item] is string     %}    bridge_{{ item }} {{ interface.bridging[item] }}
{% elif interface.bridging[item] is iterable %}    bridge_{{ item }} {{ interface.bridging[item]|join(' ') }}
{% endif %}{% endfor %}{% endif %}{% endif %}{% endif %}{% endfor %}
