Commit bb0cd358 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Device component - gNMI OpenConfig Driver:

- Enhance deletion of interfaces to respect MTUs on parent interfaces
parent 469138e4
Loading
Loading
Loading
Loading
+23 −2
Original line number Diff line number Diff line
@@ -28,9 +28,22 @@ class InterfaceHandler(_Handler):
        self, resource_key : str, resource_value : Dict, yang_handler : YangHandler, delete : bool = False
    ) -> Tuple[str, str]:
        if_name   = get_str(resource_value, 'name'    )  # ethernet-1/1
        sif_index = get_int(resource_value, 'index', 0)  # 0
        sif_index = get_int(resource_value, 'index', None)  # 0

        if delete:
            address_ip = get_str(resource_value, 'address_ip', None)
            if address_ip is not None:
                if sif_index is None:
                    return None, None
                PATH_TMPL = (
                    '/interfaces/interface[name={:s}]/subinterfaces/subinterface[index={:d}]'
                    '/openconfig-if-ip:ipv4/addresses/address[ip={:s}]'
                )
                str_path = PATH_TMPL.format(if_name, sif_index, address_ip)
                return str_path, json.dumps({})

            if sif_index is None:
                return None, None
            PATH_TMPL = '/interfaces/interface[name={:s}]/subinterfaces/subinterface[index={:d}]'
            str_path = PATH_TMPL.format(if_name, sif_index)
            str_data = json.dumps({})
@@ -51,7 +64,7 @@ class InterfaceHandler(_Handler):

            return str_path, str_data

        enabled        = get_bool(resource_value, 'enabled',  True) # True/False
        enabled        = get_bool(resource_value, 'enabled',  None) # True/False
        #if_type        = get_str (resource_value, 'type'         ) # 'l3ipvlan'
        vlan_id        = get_int (resource_value, 'vlan_id',      ) # 127
        address_ip     = get_str (resource_value, 'address_ip'    ) # 172.16.0.1
@@ -65,6 +78,14 @@ class InterfaceHandler(_Handler):
        if enabled is not None: yang_if.create_path('config/enabled', enabled)
        if mtu     is not None: yang_if.create_path('config/mtu',     mtu)

        if sif_index is None:
            str_path = '/interfaces/interface[name={:s}]'.format(if_name)
            str_data = yang_if.print_mem('json')
            json_data = json.loads(str_data)
            json_data = json_data['openconfig-interfaces:interface'][0]
            str_data = json.dumps(json_data)
            return str_path, str_data

        yang_sifs : libyang.DContainer = yang_if.create_path('subinterfaces')
        yang_sif_path = 'subinterface[index="{:d}"]'.format(sif_index)
        yang_sif : libyang.DContainer = yang_sifs.create_path(yang_sif_path)