Skip to content

Commit

Permalink
[raspbian] Improved readability of templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Ritwick DSouza committed Jul 20, 2017
1 parent 7c5f62a commit 1af682e
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 103 deletions.
28 changes: 14 additions & 14 deletions netjsonconfig/backends/raspbian/templates/hostapd.jinja2
Original file line number Diff line number Diff line change
@@ -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 %}
12 changes: 5 additions & 7 deletions netjsonconfig/backends/raspbian/templates/hostname.jinja2
Original file line number Diff line number Diff line change
@@ -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 %}
164 changes: 82 additions & 82 deletions netjsonconfig/backends/raspbian/templates/interfaces.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down

0 comments on commit 1af682e

Please sign in to comment.