Delete a rule

25 views
Skip to first unread message

Ragan Gidde

unread,
Jul 13, 2017, 2:12:32 AM7/13/17
to pyroute2-dev
Hi,

Please let me know what is the API to delete a rule.

======================================================================================

>>> ipdb.rules
{RuleKey(action=1, table=253, priority=32767, iifname=0, oifname=0, fwmark=0, fwmask=0, goto=0, tun_id=0): {'family': 2, 'tos': 0, 'priority': 32767, 'flags': 0, 'action': 1, 'table': 253, 'ipdb_priority': 0, 'ipdb_scope': 'system'}, RuleKey(action=1, table=254, priority=32766, iifname=0, oifname=0, fwmark=0, fwmask=0, goto=0, tun_id=0): {'family': 2, 'tos': 0, 'priority': 32766, 'flags': 0, 'action': 1, 'table': 254, 'ipdb_priority': 0, 'ipdb_scope': 'system'}, RuleKey(action=1, table=255, priority=0, iifname=0, oifname=0, fwmark=0, fwmask=0, goto=0, tun_id=0): {'family': 2, 'tos': 0, 'flags': 0, 'action': 1, 'table': 255, 'ipdb_priority': 0, 'ipdb_scope': 'system'}}

========================================================================================

Adding a new rule
>>> ipdb.rules.add({ 'src': '172.16.1.0/24', 'table': 123, 'priority':32765}).commit()
{'src': '172.16.1.0/24', 'family': 2, 'tos': 0, 'priority': 32765, 'flags': 0, 'action': 1, 'table': 123, 'ipdb_priority': 0, 'ipdb_scope': 'system'}
>>>

Added successfully...
>>> ipdb.rules
{RuleKey(action=1, table=253, priority=32767, iifname=0, oifname=0, fwmark=0, fwmask=0, goto=0, tun_id=0): {'family': 2, 'tos': 0, 'priority': 32767, 'flags': 0, 'action': 1, 'table': 253, 'ipdb_priority': 0, 'ipdb_scope': 'system'}, RuleKey(action=1, table=123, priority=32765, iifname=0, oifname=0, fwmark=0, fwmask=0, goto=0, tun_id=0): {'src': '172.16.1.0/24', 'family': 2, 'tos': 0, 'priority': 32765, 'flags': 0, 'action': 1, 'table': 123, 'ipdb_priority': 0, 'ipdb_scope': 'system'}, RuleKey(action=1, table=254, priority=32766, iifname=0, oifname=0, fwmark=0, fwmask=0, goto=0, tun_id=0): {'family': 2, 'tos': 0, 'priority': 32766, 'flags': 0, 'action': 1, 'table': 254, 'ipdb_priority': 0, 'ipdb_scope': 'system'}, RuleKey(action=1, table=255, priority=0, iifname=0, oifname=0, fwmark=0, fwmask=0, goto=0, tun_id=0): {'family': 2, 'tos': 0, 'flags': 0, 'action': 1, 'table': 255, 'ipdb_priority': 0, 'ipdb_scope': 'system'}}
=============================================================================================

Trying to delete the rule:

>>> ipdb.rules.pop({ 'src': '172.16.1.0/24', 'table': 123, 'priority':32765}).commit()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'dict'
>>> ipdb.rules.pop({ 'src': '172.16.1.0/24', 'table': 123, 'priority':32765})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'dict'
>>> ipdb.rules.clear({ 'src': '172.16.1.0/24', 'table': 123, 'priority':32765}).commit()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: clear() takes no arguments (1 given)

==================================================================================================

Thanks,
Ragan.

Peter Saveliev

unread,
Jul 13, 2017, 9:05:00 AM7/13/17
to Ragan Gidde, pyroute2-dev
Shortly: 

ipdb.rules[<key>].remove().commit()

Please let me know, if there are any issues with that. Thanks!

--
You received this message because you are subscribed to the Google Groups "pyroute2-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyroute2-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages