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

Jsonify show neighbor,adj-rib-in,adj-rib-out cmds output #1240

Closed
wants to merge 1 commit into from

Conversation

vish-321
Copy link

This PR updates ExaBGP to optionally provide JSON output for API commands such as show neighbor, adj-rib-in, and adj-rib-out.

Existing Commands:

show neighbor [optional neighbor ip] summary
show neighbor [optional neighbor ip] extensive
show neighbor [optional neighbor ip] configuration
show adj-rib in [extensive] (to be integrated with neighbor)
show adj-rib out [extensive] (to be integrated with neighbor)

Example Usage for JSON Output:

show neighbor [optional json] [optional neighbor ip] summary
show neighbor [optional json] [optional neighbor ip] extensive
show adj-rib in [optional json] [extensive] (to be integrated with neighbor)
show adj-rib out [optional json] [extensive] (to be integrated with neighbor)

Examples:

show neighbor json summary
show neighbor json extensive
show adj-rib out json

This should also resolve the issue detailed in #909

@@ -73,99 +63,98 @@ class Neighbor(object):
summary_template = '%-15s %-7s %9s %-12s %10d %10d'

@classmethod
def as_dict(cls, answer):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as_dict should not be inlined. It would be better to have as _string added and use two functions for clarity.

@thomas-mangin
Copy link
Member

Thank you for this PR, I can not accept it as it but I have no objection to adding the feature.

@thomas-mangin
Copy link
Member

I will massage this patch into shape as there is too much to fix and explain.

thomas-mangin added a commit that referenced this pull request Oct 17, 2024
following an attempt with #1240 this code provide all the glue code to
make it easier to convert all the api call to json
@thomas-mangin
Copy link
Member

following the changes pushed above, it should be easier to add json support to any command.

show adj-rib was converted in a very inefficient way using json.dumps. The JSON should be generated by hand using the JSON module with a large structure as the rib allocates a lot of memory instead of using iterators, but as an example, it will do for the moment.

The JSON generated should NOT try to match the text version but instead use suitable dict structures that are easy to parse (as it is often done in the code).

__

@Command.register('show adj-rib out', False, ['extensive',], True)
@Command.register('show adj-rib in', False, ['extensive',], True)
def show_adj_rib(self, reactor, service, line, use_json):

@thomas-mangin
Copy link
Member

thomas-mangin commented Oct 18, 2024

My patch is wrong as it mixes json payload with json formatting of answers. I will fix it.

@thomas-mangin
Copy link
Member

if you want to see what you need and I missed, please open a new PR and I will help.

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