Bechtoldt's Network Saltstack Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

interfaces.sls 1.4KB

10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!jinja|yaml
  2. {% from "network/defaults.yaml" import rawmap with context %}
  3. {% set datamap = salt['grains.filter_by'](rawmap, merge=salt['pillar.get']('network:lookup')) %}
  4. {% set interfaces = datamap.interfaces.def_entries %}
  5. {%- macro set_p(paramname, dictvar) -%}
  6. {%- if paramname in dictvar -%}
  7. - {{ paramname }}: {{ dictvar[paramname] }}
  8. {%- endif -%}
  9. {%- endmacro -%}
  10. {% if salt['pillar.get']('network:interfaces', False) %}
  11. {% set interfaces = interfaces + salt['pillar.get']('network:interfaces') %}
  12. {% endif %}
  13. {# http://stackoverflow.com/questions/4870346/can-a-jinja-variables-scope-extend-beyond-in-an-inner-block #}
  14. {%- set vlanRequired = [] -%}
  15. {% for n in interfaces %}
  16. network-{{ n.name }}:
  17. network:
  18. - managed
  19. - name: {{ n.name }}
  20. - enabled: {{ n.enable|default(datamap.interfaces.default_values.enable) }}
  21. - proto: {{ n.proto|default(datamap.interfaces.default_values.proto) }}
  22. - type: {{ n.type|default(datamap.interfaces.default_values.type) }}
  23. {% for p in datamap.interfaces.params_supported %}
  24. {{ set_p(p, n) }}
  25. {% endfor %}
  26. {% if n.use is defined %}
  27. - use:
  28. {% for u in n.use %}
  29. - network: network-{{ u }}
  30. {% endfor %}
  31. {% endif %}
  32. {% if n.type == 'vlan' %}
  33. {% do vlanRequired.append(1) -%}
  34. - require:
  35. - pkg: vlan
  36. {% endif %}
  37. {% endfor %}
  38. {% if vlanRequired %}
  39. vlan:
  40. pkg.installed
  41. {% endif %}