Commit 623bf640 authored by Pablo Armingol's avatar Pablo Armingol
Browse files

acl big fixed

parent 0a5392e8
Loading
Loading
Loading
Loading
+38 −24
Original line number Diff line number Diff line
@@ -35,8 +35,13 @@ LOG_ACTION_MAPPING = {
    'ACLLOGACTION_NOLOG'    : 'LOG_NONE',
    'ACLLOGACTION_SYSLOG'   : 'LOG_SYSLOG',
}
def acl_mgmt(parameters,vendor,delete):
    acl   = []
    acl.append(acl_set_mng(  parameters,vendor,delete))
    acl.append(acl_interface(parameters,vendor,delete))
    return acl

def acl_set_mng(data, DEL):
def acl_set_mng(data,vendor, delete):
    doc, tag, text = Doc().tagtext()

    Acl_data    = data["rule_set"]
@@ -45,7 +50,7 @@ def acl_set_mng(data, DEL):
    Acl_desc    = Acl_data['description']
    Acl_entries = Acl_data['entries']
    with tag('acl', xmlns="http://openconfig.net/yang/acl"):
        if DEL:
        if delete:
            with tag('acl-sets' ,'xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="delete"'):
                with tag('acl-set'):
                    with tag('name'):text(Acl_name)
@@ -76,11 +81,12 @@ def acl_set_mng(data, DEL):
                            with tag('acl-entry'): 
                                with tag('sequence-id'):text(ID)
                                with tag('config'):
                                        with tag('acl-entry'):   text(ID)
                                    with tag('sequence-id'):   text(ID)
                                    with tag('description'): text(desc)
                                # Configuration per type
                                if "L2" in Acl_type:
                                    with tag('l2'):
                                        with tag('config'):
                                            for key, value in match.items():
                                                if   "src_address"     in key and len(value) != 0: 
                                                    with tag('source-mac'):text(value)
@@ -88,6 +94,7 @@ def acl_set_mng(data, DEL):
                                                    with tag('destination-mac'):text(value)   
                                elif "IPV4" in Acl_type:
                                    with tag('ipv4'):
                                        with tag('config'):
                                            for key, value in match.items():
                                                if   "src_address"       in key and len(value) != 0:
                                                    with tag('source-address'):text(value)
@@ -100,6 +107,7 @@ def acl_set_mng(data, DEL):
                                                elif "dscp"              in key                    : 
                                                    with tag('dscp'):text(value)
                                    with tag('transport'):
                                        with tag('config'):
                                            for key, value in match.items():
                                                if   "src_port"     in key : 
                                                    with tag('source-port'):text(value)
@@ -109,6 +117,7 @@ def acl_set_mng(data, DEL):
                                                    with tag('tcp-flags'):text(value)        
                                elif "IPV6" in Acl_type:
                                    with tag('ipv6'):
                                        with tag('config'):
                                            for key, value in match.items():
                                                if   "src_address"       in key and len(value) != 0:
                                                    with tag('source-address'):text(value)
@@ -121,9 +130,10 @@ def acl_set_mng(data, DEL):
                                                elif "dscp"              in key                    : 
                                                    with tag('dscp'):text(value)
                                with tag('actions'):
                                    with tag('config'):
                                        for key, value in action.items():
                                            if "forward_action" in key : 
                                                with tag('forward-action'):text(FORWARDING_ACTION_MAPPING[value])
                                                with tag('forwarding-action'):text(FORWARDING_ACTION_MAPPING[value])
                                            elif "log_action"     in key :
                                                with tag('log-action'):text(LOG_ACTION_MAPPING[value])
    result = indent(
@@ -133,7 +143,8 @@ def acl_set_mng(data, DEL):
    )
    return result

def acl_interface(data,vendor, DEL):

def acl_interface(data,vendor, delete):
    doc, tag, text = Doc().tagtext()

    ID        = data['endpoint_id']['endpoint_uuid']['uuid']
@@ -158,6 +169,9 @@ def acl_interface(data,vendor, DEL):
                        with tag('ingress-acl-set'):
                            with tag('set-name'):text(Acl_name)
                            with tag('type'):text(Acl_type)
                            with tag('config'):
                                with tag('set-name'):text(Acl_name)
                                with tag('type'):text(Acl_type)
    result = indent(
        doc.getvalue(),
        indentation = ' '*2,
+2 −2
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@
import json
import lxml.etree as ET
from typing import Collection, Dict, Any
from .ACL.ACL_multivendor              import acl_set_mng        
from .ACL.ACL_multivendor              import acl_mgmt        
from .VPN.Network_instance_multivendor import create_NI, associate_virtual_circuit, associate_RP_to_NI, add_protocol_NI, create_table_conns, associate_If_to_NI
from .VPN.Interfaces_multivendor       import create_If_SubIf  
from .VPN.Routing_policy               import create_rp_def, create_rp_statement
@@ -84,6 +84,6 @@ def generate_templates(resource_key: str, resource_value: str, delete: bool,vend
            result_templates.append(create_rp_statement(data, delete))
    else:
        if "acl_ruleset" in resource_key:                                               # acl rules management
            result_templates.extend(acl_set_mng(resource_value, delete))
            result_templates.extend(acl_mgmt(resource_value,vendor, delete))

    return result_templates
 No newline at end of file