Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NDB Source object's counting and update documentation #1156

Merged
merged 2 commits into from
Jan 10, 2024

Conversation

pkulev
Copy link
Contributor

@pkulev pkulev commented Dec 24, 2023

The following code snippet gives me an error, but with other objects that works fine.

>>> from pyroute2 import NDB

>>> ndb = NDB()
>>> ndb.sources
AttributeError: type object 'Source' has no attribute '_count'
list(ndb.sources)
AttributeError: type object 'Source' has no attribute '_count'

With this patchset applied I got the following output:

>>> ndb.sources


NDB view for sources
Number of objects: 2

to list objects use .summary() or .dump()
    -> RecordSet (generator)
        -> Record

key: Union[Record, dict, spec]
to get objects use ...[key] / .__getitem__(key)
    -> RTNL_Object

>>> list(ndb.sources)
['localhost', 'localhost/nsmanager']

The reason behind the absence of this method is that Source subclasses dict, and there is no real interface in terms of typing that is common to Source and other NDB objects (which subclass RTNL_object). Therefore, with this PR, I am addressing only the consequence, not the root cause.

Also sources documentation has usage of an inexistent method .details(), so I gave some love to the docs too.
The the one thing I'm not sure, is the following statement:

By default NDB starts with one local RTNL source names localhost

It seems I have 2 sources on my pretty default setup. So waiting for your guidance here :)

@svinota svinota merged commit e552e6b into svinota:master Jan 10, 2024
14 checks passed
@svinota
Copy link
Owner

svinota commented Jan 10, 2024

The two sources are the default RTNL source and the network namespaces manager, you can run ndb.sources.summary(), or even ndb.sources.dump().format("json")

@pkulev pkulev deleted the bugfix/ndb-sources-count branch January 10, 2024 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants