Skip to content

Commit

Permalink
requests.tc: root parent for kind without plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
svinota committed Dec 13, 2024
1 parent fb18c29 commit 19a7d4d
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions pyroute2/requests/tc.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pyroute2.netlink.rtnl import TC_H_ROOT
from pyroute2.netlink.rtnl.tcmsg import plugins as tc_plugins

from .common import IPRouteFilter
Expand Down Expand Up @@ -39,20 +40,25 @@ def finalize(self, context):
context['handle'] = 0

# get & run the plugin
if 'kind' in context and context['kind'] in tc_plugins:
plugin = tc_plugins[context['kind']]
context['parent'] = context.get(
'parent', getattr(plugin, 'parent', 0)
)
if set(context.keys()) > set(('kind', 'index', 'handle')):
get_parameters = None
if self.command[-5:] == 'class':
get_parameters = getattr(
plugin, 'get_class_parameters', None
)
else:
get_parameters = getattr(plugin, 'get_parameters', None)
if get_parameters is not None:
context['options'] = get_parameters(dict(context))
if hasattr(plugin, 'fix_request'):
plugin.fix_request(context)
if 'kind' in context:
if context['kind'] in tc_plugins:
plugin = tc_plugins[context['kind']]
context['parent'] = context.get(
'parent', getattr(plugin, 'parent', 0)
)
if set(context.keys()) > set(('kind', 'index', 'handle')):
get_parameters = None
if self.command[-5:] == 'class':
get_parameters = getattr(
plugin, 'get_class_parameters', None
)
else:
get_parameters = getattr(
plugin, 'get_parameters', None
)
if get_parameters is not None:
context['options'] = get_parameters(dict(context))
if hasattr(plugin, 'fix_request'):
plugin.fix_request(context)
else:
context['parent'] = TC_H_ROOT

0 comments on commit 19a7d4d

Please sign in to comment.