diff --git a/netjsonconfig/backends/raspbian/templates/hostapd.jinja2 b/netjsonconfig/backends/raspbian/templates/hostapd.jinja2 index aca7b6eb2..9f715671f 100644 --- a/netjsonconfig/backends/raspbian/templates/hostapd.jinja2 +++ b/netjsonconfig/backends/raspbian/templates/hostapd.jinja2 @@ -1,26 +1,26 @@ {% for wireless in data.wireless %} # config: /etc/hostapd/hostapd.conf - interface={{ wireless.get('ifname') }} + interface={{ wireless.ifname }} driver=nl80211 - {% if wireless.get('protocol') == 'a' or 'b' or 'g' %} - hw_mode={{ wireless.get('hwmode')}} + {% if wireless.protocol == 'a' or 'b' or 'g' %} + hw_mode={{ wireless.hwmode }} {% endif %} - channel={{ wireless.get('channel')}} - {% if wireless.get('protocol') == '80211n' %} + channel={{ wireless.channel }} + {% if wireless.protocol == '80211n' %} ieee80211n=1 {% endif %} - {% if wireless.get('protocol') == '80211ac' %} + {% if wireless.protocol == '80211ac' %} ieee80211ac=1 {% endif %} - ssid={{ wireless.get('ssid') }} - {% if wireless.get('encryption') != {} %} - auth_algs={{ wireless.get('encryption').get('auth_algs') }} - wpa={{ wireless.get('encryption').get('wpa') }} - wpa_key_mgmt={{ wireless.get('encryption').get('wpa_key_mgmt') }} - wpa_passphrase={{ wireless.get('encryption').get('wpa_passphrase') }} - {% if wireless.get('encryption', None).get('wpa_pairwise') != 'AUTO' %} - wpa_pairwise={{ wireless.get('encryption').get('wpa_pairwise')}} + ssid={{ wireless.ssid }} + {% if wireless.encryption %} + auth_algs={{ wireless.encryption.auth_algs }} + wpa={{ wireless.encryption.wpa }} + wpa_key_mgmt={{ wireless.encryption.wpa_key_mgmt }} + wpa_passphrase={{ wireless.encryption.wpa_passphrase }} + {% if wireless.encryption.wpa_pairwise != 'AUTO' %} + wpa_pairwise={{ wireless.encryption.wpa_pairwise }} {% endif %} {% endif %} {% endfor %} diff --git a/netjsonconfig/backends/raspbian/templates/hostname.jinja2 b/netjsonconfig/backends/raspbian/templates/hostname.jinja2 index 6c1df440f..d7ae654a9 100644 --- a/netjsonconfig/backends/raspbian/templates/hostname.jinja2 +++ b/netjsonconfig/backends/raspbian/templates/hostname.jinja2 @@ -1,8 +1,6 @@ -{% for general in data.general %} - {% if general.get('hostname') %} - # config: /etc/hostname +{% if data.general and data.general[0].hostname %} + # config: /etc/hostname - {{ general.get('hostname') }} - - {% endif %} -{% endfor %} + {{ data.general[0].hostname }} + +{% endif %} \ No newline at end of file diff --git a/netjsonconfig/backends/raspbian/templates/interfaces.jinja2 b/netjsonconfig/backends/raspbian/templates/interfaces.jinja2 index cacdc78ea..c860e9825 100644 --- a/netjsonconfig/backends/raspbian/templates/interfaces.jinja2 +++ b/netjsonconfig/backends/raspbian/templates/interfaces.jinja2 @@ -3,106 +3,106 @@ {% endif%} {% for interface in data.interfaces %} - {% if interface.get('iftype') in ['ethernet', 'bridge', 'loopback', 'wireless'] %} - {% if interface.get('address') != None %} - auto {{ interface.get('ifname') }} - {% for address in interface.get('address') %} - {% if address.get('proto') == 'static' %} - {% if address.get('family') == 'ipv4' %} - iface {{ interface.get('ifname') }} inet {{ address.get('proto') }} - address {{ address.get('address') }} - netmask {{ address.get('netmask') }} - {% if address.get('gateway', None) != None %} - gateway {{ address.get('gateway')}} - {% endif %} - {% if interface.get('route') != None %} - {% set route = interface.get('route')%} - post-up route add -net {{ route.get('dest') }} netmask {{ route.get('dest_mask') }} gw {{ route.get('next') }} - pre-up route del -net {{ route.get('dest') }} netmask {{ route.get('dest_mask') }} gw {{ route.get('next') }} - {% endif %} - {% if interface.get('mtu', None) != None %} - mtu {{ interface.get('mtu') }} - {% endif %} - {% if interface.get('mac', None) != None %} - hwaddress {{ interface.get('mac') }} - {% endif %} - {% if interface.get('iftype') == 'bridge' %} - bridge_ports {{ interface.get('bridge_members')[0] }} {{ interface.get('bridge_members')[1] }} - {% endif %} - {% elif address.get('family') == 'ipv6' %} - iface {{ interface.get('ifname') }} inet6 {{ address.get('proto') }} - address {{ address.get('address') }} - netmask {{ address.get('netmask') }} - {% if address.get('gateway', None) != None %} - gateway {{ address.get('gateway') }} - {% endif %} - {% if interface.get('route') != None %} - {% set route = interface.get('route')%} - up ip -6 route add {{ route.get('destination') }} via {{ route.get('next')}} dev eth0 - down ip -6 route del {{ route.get('destination') }} via {{ route.get('next')}} dev eth0 - {% endif %} - {% if interface.get('mtu', None) != None %} - mtu {{ interface.get('mtu') }} - {% endif %} - {% if interface.get('mac', None) != None %} - hwaddress {{ interface.get('mac') }} - {% endif %} - {% if interface.get('iftype') == 'bridge' %} - bridge_ports {{ interface.get('bridge_members')[0] }} {{ interface.get('bridge_members')[1] }} + {% if interface.iftype in ['ethernet', 'bridge', 'loopback', 'wireless'] %} + {% if interface.address %} + auto {{ interface.ifname }} + {% for address in interface.address %} + {% if address.proto == 'static' %} + {% if address.family == 'ipv4' %} + iface {{ interface.ifname }} inet {{ address.proto }} + address {{ address.address }} + netmask {{ address.netmask }} + {% if address.gateway %} + gateway {{ address.gateway }} + {% endif %} + {% if interface.route %} + {% set route = interface.route %} + post-up route add -net {{ route.dest }} netmask {{ route.dest_mask }} gw {{ route.next }} + pre-up route del -net {{ route.dest }} netmask {{ route.dest_mask }} gw {{ route.next }} + {% endif %} + {% if interface.mtu %} + mtu {{ interface.mtu }} + {% endif %} + {% if interface.mac %} + hwaddress {{ interface.mac }} + {% endif %} + {% if interface.iftype == 'bridge' %} + bridge_ports {{ interface.bridge_members[0] }} {{ interface.bridge_members[1] }} + {% endif %} + {% elif address.family == 'ipv6' %} + iface {{ interface.ifname }} inet6 {{ address.proto }} + address {{ address.address }} + netmask {{ address.netmask }} + {% if address.gateway %} + gateway {{ address.gateway }} + {% endif %} + {% if interface.route %} + {% set route = interface.route %} + up ip -6 route add {{ route.destination }} via {{ route.next }} dev eth0 + down ip -6 route del {{ route.destination }} via {{ route.next }} dev eth0 + {% endif %} + {% if interface.mtu %} + mtu {{ interface.mtu }} + {% endif %} + {% if interface.mac %} + hwaddress {{ interface.mac }} + {% endif %} + {% if interface.iftype == 'bridge' %} + bridge_ports {{ interface.bridge_members[0] }} {{ interface.bridge_members[1] }} {% endif %} {% endif %} - {% elif address.get('proto') == 'dhcp' %} - {% if address.get('family') == 'ipv4'%} - iface {{ interface.get('ifname') }} inet {{ address.get('proto') }} - {% if interface.get('route') != None %} - {% set route = interface.get('route')%} - post-up route add -net {{ route.get('dest') }} netmask {{ route.get('dest_mask') }} gw {{ route.get('next') }} - pre-up route del -net {{ route.get('dest') }} netmask {{ route.get('dest_mask') }} gw {{ route.get('next') }} + {% elif address.proto == 'dhcp' %} + {% if address.family == 'ipv4'%} + iface {{ interface.ifname }} inet {{ address.proto }} + {% if interface.route %} + {% set route = interface.route %} + post-up route add -net {{ route.dest }} netmask {{ route.dest_mask }} gw {{ route.next }} + pre-up route del -net {{ route.dest }} netmask {{ route.dest_mask }} gw {{ route.next }} {% endif %} - {% if interface.get('mtu', None) != None %} - pre-up /sbin/ifconfig $IFACE mtu {{ interface.get('mtu') }} + {% if interface.mtu %} + pre-up /sbin/ifconfig $IFACE mtu {{ interface.mtu }} {% endif %} - {% if interface.get('mac', None) != None %} - hwaddress {{ interface.get('mac') }} + {% if interface.mac %} + hwaddress {{ interface.mac }} {% endif %} - {% elif address.get('family') == 'ipv6' %} - iface {{ interface.get('ifname') }} inet6 {{ address.get('proto') }} - {% if interface.get('route') != None %} - {% set route = interface.get('route') %} - up ip -6 route add {{ route.get('destination') }} via {{ route.get('next')}} dev eth0 - down ip -6 route del {{ route.get('destination') }} via {{ route.get('next')}} dev eth0 + {% elif address.family == 'ipv6' %} + iface {{ interface.ifname }} inet6 {{ address.proto }} + {% if interface.route %} + {% set route = interface.route %} + up ip -6 route add {{ route.destination }} via {{ route.next }} dev eth0 + down ip -6 route del {{ route.destination }} via {{ route.next }} dev eth0 {% endif %} - {% if interface.get('mtu', None) != None %} - pre-up /sbin/ifconfig $IFACE mtu {{ interface.get('mtu') }} + {% if interface.mtu %} + pre-up /sbin/ifconfig $IFACE mtu {{ interface.mtu }} {% endif %} - {% if interface.get('mac', None) != None %} - hwaddress {{ interface.get('mac') }} + {% if interface.mac %} + hwaddress {{ interface.mac }} {% endif %} {% endif %} {% endif%} {% endfor %} {% else %} - auto {{ interface.get('ifname') }} - {% if interface.get('iftype') in ['ethernet', 'wireless'] and interface.get('mode') != 'adhoc' %} - iface {{ interface.get('ifname') }} inet manual - {% set route = interface.get('route')%} - {% if interface.get('route') != None and route.get('version') == 4 %} - post-up route add -net {{ route.get('dest') }} netmask {{ route.get('dest_mask') }} gw {{ route.get('next') }} - pre-up route del -net {{ route.get('dest') }} netmask {{ route.get('dest_mask') }} gw {{ route.get('next') }} - {% elif interface.get('route') != None and route.get('version') == 6 %} - up ip -6 route add {{ route.get('destination') }} via {{ route.get('next')}} dev eth0 - down ip -6 route del {{ route.get('destination') }} via {{ route.get('next')}} dev eth0 + auto {{ interface.ifname }} + {% if interface.iftype in ['ethernet', 'wireless'] and interface.mode != 'adhoc' %} + iface {{ interface.ifname }} inet manual + {% set route = interface.route %} + {% if interface.route and route.version == 4 %} + post-up route add -net {{ route.dest }} netmask {{ route.dest_mask }} gw {{ route.next }} + pre-up route del -net {{ route.dest }} netmask {{ route.dest_mask }} gw {{ route.next }} + {% elif interface.route and route.version == 6 %} + up ip -6 route add {{ route.destination }} via {{ route.next }} dev eth0 + down ip -6 route del {{ route.destination }} via {{ route.next }} dev eth0 {% endif %} {% endif %} - {% if interface.get('iftype') == 'bridge' %} - bridge_ports {{ interface.get('bridge_members')[0] }} {{ interface.get('bridge_members')[1] }} + {% if interface.iftype == 'bridge' %} + bridge_ports {{ interface.bridge_members[0] }} {{ interface.bridge_members[1] }} {% endif %} - {% if interface.get('mode') == 'adhoc' %} - iface {{ interface.get('ifname') }} inet static + {% if interface.mode == 'adhoc' %} + iface {{ interface.ifname }} inet static address 172.128.1.1 netmask 255.255.255.0 wireless-channel 1 - wireless-essid {{ interface.get('essid') }} + wireless-essid {{ interface.essid }} wireless-mode ad-hoc {% endif %} {% endif %}