Skip to content

Commit

Permalink
Made "multiwalk" more generic.
Browse files Browse the repository at this point in the history
The main logic which is concerned about when to continue fetching and
with which OIDs is the same for a normal "GetNext" based walk and a
"BulkGet" based walk. This change makes "multiwalk" compatible with both
strategies.

References #16
  • Loading branch information
exhuma committed Oct 10, 2016
1 parent c8936e3 commit f06fdc7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions puresnmp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ def walk(ip: str, community: str, oid, port: int=161):
return multiwalk(ip, community, [oid], port)


def multiwalk(ip: str, community: str, oids: List[str], port: int=161):
def multiwalk(ip: str, community: str, oids: List[str], port: int=161,
fetcher=multigetnext):
"""
Executes a sequence of SNMP GETNEXT requests and returns an generator over
:py:class:`~puresnmp.pdu.VarBind` instances.
Expand All @@ -152,15 +153,15 @@ def multiwalk(ip: str, community: str, oids: List[str], port: int=161):
"""

varbinds = multigetnext(ip, community, oids, port)
varbinds = fetcher(ip, community, oids, port)

retrieved_oids = [str(bind.oid) for bind in varbinds]
prev_retrieved_oids = []
while retrieved_oids:
for bind in varbinds:
yield bind

varbinds = multigetnext(ip, community, retrieved_oids, port)
varbinds = fetcher(ip, community, retrieved_oids, port)
retrieved_oids = [str(bind.oid) for bind in varbinds]

# ending condition (check if we need to stop the walk)
Expand Down

0 comments on commit f06fdc7

Please sign in to comment.