From ea79664429b419642b817c1db7a5029e33159fe8 Mon Sep 17 00:00:00 2001 From: "Tomasz Zietkowski -X (tzietkow - CODILIME SP ZOO at Cisco)" Date: Fri, 3 Mar 2023 08:46:09 +0100 Subject: [PATCH] add encapsulation --- vmngclient/api/templates/__init__.py | 4 ++ .../cisco_vpn_interface_ethernet_model.py | 13 ++++ .../feature/tunnel.json.j2 | 59 +++++++++++-------- 3 files changed, 53 insertions(+), 23 deletions(-) diff --git a/vmngclient/api/templates/__init__.py b/vmngclient/api/templates/__init__.py index a3b2605ff..68dced6de 100644 --- a/vmngclient/api/templates/__init__.py +++ b/vmngclient/api/templates/__init__.py @@ -29,6 +29,8 @@ from vmngclient.api.templates.payloads.cisco_vpn_interface_ethernet.cisco_vpn_interface_ethernet_model import ( CiscoVpnInterfaceEthernetModel, ColorType, + Encapsulation, + EncapType, InterfaceType, Tunnel, TypeAddress, @@ -54,4 +56,6 @@ "TypeAddress", "ColorType", "Tunnel", + "Encapsulation", + "EncapType", ] diff --git a/vmngclient/api/templates/payloads/cisco_vpn_interface_ethernet/cisco_vpn_interface_ethernet_model.py b/vmngclient/api/templates/payloads/cisco_vpn_interface_ethernet/cisco_vpn_interface_ethernet_model.py index 85e50effa..9dac102b0 100644 --- a/vmngclient/api/templates/payloads/cisco_vpn_interface_ethernet/cisco_vpn_interface_ethernet_model.py +++ b/vmngclient/api/templates/payloads/cisco_vpn_interface_ethernet/cisco_vpn_interface_ethernet_model.py @@ -57,6 +57,18 @@ class ColorType(Enum): SILVER = "silver" +class EncapType(Enum): + GRE = "gre" + IPSEC = "ipsec" + + +@define +class Encapsulation: + type: EncapType + preference: Optional[int] = None + weight: Optional[int] = None + + @define class Tunnel: color: Optional[ColorType] = None @@ -72,6 +84,7 @@ class Tunnel: stun: Optional[bool] = None https: Optional[bool] = None snmp: Optional[bool] = None + encapsulation: list[Encapsulation] = [] class CiscoVpnInterfaceEthernetModel(FeatureTemplate): diff --git a/vmngclient/api/templates/payloads/cisco_vpn_interface_ethernet/feature/tunnel.json.j2 b/vmngclient/api/templates/payloads/cisco_vpn_interface_ethernet/feature/tunnel.json.j2 index 108164981..815435365 100644 --- a/vmngclient/api/templates/payloads/cisco_vpn_interface_ethernet/feature/tunnel.json.j2 +++ b/vmngclient/api/templates/payloads/cisco_vpn_interface_ethernet/feature/tunnel.json.j2 @@ -2,29 +2,42 @@ "encapsulation": { "vipType": "constant", "vipValue": [ - { - "preference": { - "vipObjectType": "object", - "vipType": "ignore", - "vipVariableName": "vpn_if_tunnel_ipsec_preference" - }, - "weight": { - "vipObjectType": "object", - "vipType": "ignore", - "vipValue": 1, - "vipVariableName": "vpn_if_tunnel_ipsec_weight" - }, - "encap": { - "vipType": "constant", - "vipValue": "ipsec", - "vipObjectType": "object" - }, - "priority-order": [ - "encap", - "preference", - "weight" - ] - } + {% for encap in tunnel.encapsulation %} + { + "preference": { + "vipObjectType": "object", + {% if encap.preference is not none %} + "vipType": "constant", + "vipValue": {{ encap.preference }}, + {% else %} + "vipType": "ignore" + {% endif %} + "vipVariableName": "vpn_if_tunnel_{{ encap.type.value }}_preference" + }, + "weight": { + "vipObjectType": "object", + {% if encap.weight is not none %} + "vipType": "constant", + "vipValue": {{ encap.weight }}, + {% else %} + "vipType": "ignore" + "vipValue": 1, + {% endif %} + "vipVariableName": "vpn_if_tunnel_{{ encap.type.value }}_weight" + }, + "encap": { + "vipType": "constant", + "vipValue": "{{ encap.type.value }}", + "vipObjectType": "object" + }, + "priority-order": [ + "encap", + "preference", + "weight" + ] + } + {% if not loop.last %},{% endif %} + {% endfor %} ], "vipObjectType": "tree", "vipPrimaryKey": [