11{% - from "openvpn/macros.jinja" import multipart_param with context -%}
2- {% - set config = salt ['pillar.get' ]('openvpn:network_manager:networks:' +network_name , {}) -%}
2+ {% - from "openvpn/map.jinja" import map with context %}
3+
34{% - macro pairs (data ) -%}
45{% - for key , value in data |dictsort -%}
56{{ key|replace('_', '-') }}={{ value }}
@@ -24,8 +25,9 @@ uuid={{ salt['cmd.run']("python2 -c \"import uuid; print uuid.uuid5(uuid.NAMESPA
2425{% - if segment == 'vpn' %}
2526{% - if config [segment ].get ('service_type' , 'org.freedesktop.NetworkManager.openvpn' ) == 'org.freedesktop.NetworkManager.openvpn' %}
2627{% - set instance_name = config .get ('_vpn_instance' , network_name ) %}
27- {% - set instance_data = salt ['pillar.get' ]('openvpn:client:' +instance_name , {}) %}
28- {% - set vpn_data = salt ['pillar.get' ]('openvpn:network_manager:networks:{}:{}' .format (network_name , segment ), instance_data , True ) %}
28+ {% - set instance_data = clients .get (instance_name , {}) %}
29+ {% - set vpn_data = instance_data %}
30+ {% - do vpn_data .update (config .get (segment , {})) %}
2931connection-type=tls
3032service-type={{ vpn_data.pop('service_type') }}
3133
@@ -44,21 +46,24 @@ auth={{ vpn_data.pop('auths')|first }}
4446{% - endif %}
4547
4648{% - set remote = vpn_data .pop ('remote' , False ) %}
47- {% - set port = vpn_data .pop ('port' , 1194 ) %}
49+ {% - set port = vpn_data .pop ('port' , False ) %}
4850{% - if remote is iterable and not remote is string %}
4951{% - set remote = remote |first %}
5052{% - endif %}
5153{% - if remote is string %}
5254{% - set remote_pair = remote .split (' ' ) %}
5355{% - set remote = remote_pair |first %}
54- {% - if remote_pair |length > 1 %}
56+ {% - if not port and remote_pair |length > 1 %}
5557{% - set port = remote_pair |last %}
5658{% - endif %}
5759{% - endif %}
58- {% - if remote and port %}
60+ {% - if remote %}
5961remote={{ remote }}
60- port={{ port }}
6162{% - endif %}
63+ {% - if not port %}
64+ {% - set port = 1194 %}
65+ {% - endif %}
66+ port={{ port }}
6267
6368{% - if 'tls_auth' in vpn_data %}
6469ta-dir={{ multipart_param(vpn_data.tls_auth, 1) }}
0 commit comments