Skip to content

Commit

Permalink
Update compat.py
Browse files Browse the repository at this point in the history
error handling to default to ndb calls if ipdb returns errors
  • Loading branch information
chateaulav authored Oct 6, 2023
1 parent 32f5fa0 commit 47d74f4
Showing 1 changed file with 39 additions and 18 deletions.
57 changes: 39 additions & 18 deletions pyroute2/ndb/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,51 @@ def ipdb_interfaces_view(ndb):
interface = record._as_dict()
interface['ipdb_scope'] = 'system'
interface['ipdb_priority'] = 0
interface['ipaddr'] = tuple(
(
(x.address, x.prefixlen)
for x in (
ndb.addresses.dump().select_records(index=record.index)
try:
interface['ipaddr'] = tuple(
(
(x.address, x.prefixlen)
for x in (
ndb.addresses.dump().select_records(index=record.index)
)
)
)
)
interface['ports'] = tuple(
(
x.index
for x in (
ndb.interfaces.dump().select_records(master=record.index)
except:
with ndb.addresses.summary() as report:
report.select_records(ifname=f"{record.ifname}")
interface['ipaddr'] = tuple(
((x.address, x.prefixlen) for x in report)
)
try:
interface['ports'] = tuple(
(
x.index
for x in (
ndb.interfaces.dump().select_records(master=record.index)
)
)
)
)
interface['neighbours'] = tuple(
(
x.dst
for x in (
ndb.neighbours.dump().select_records(ifindex=record.index)
except:
with ndb.interfaces.dump() as report:
report.select_records(ifname=f"{record.ifname}")
interface['ports'] = tuple(
(x.index for x in report)
)
try:
interface['neighbours'] = tuple(
(
x.dst
for x in (
ndb.neighbours.dump().select_records(ifindex=record.index)
)
)
)
)
except:
with ndb.neighbours.dump() as report:
report.select_records(ifindex=record.index)
interface['neighbours'] = tuple(
(x.dst for x in report)
)
ret[record.ifname] = interface

return ret

0 comments on commit 47d74f4

Please sign in to comment.