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

When doing bgp parsing a 'Device' object has no attribute 'execute' error shows up #597

Closed
balmasea opened this issue Dec 22, 2021 · 5 comments · Fixed by #607
Closed

When doing bgp parsing a 'Device' object has no attribute 'execute' error shows up #597

balmasea opened this issue Dec 22, 2021 · 5 comments · Fixed by #607
Assignees

Comments

@balmasea
Copy link
Contributor

I'm parsing some bgp commands and for every command that has a non conditional instruction:

self.device.execute(cmd)

it answers
'Device' object has no attribute 'execute'

That ends with not parsing of commands like
show ip bgp neighbor {neighbor} advertised-routes
or
show bgp all cluster-ids

@ThomasJRyan
Copy link
Collaborator

9 times out of 10 this is caused due to having not first connected to your device. Run self.device.connect() first

@ThomasJRyan ThomasJRyan self-assigned this Jan 11, 2022
@balmasea
Copy link
Contributor Author

Hi Thomas. Thanks for your answer.
That's exactly my point. For most of commands there is no need to have a device connected to run them. Why is this command different? We would need to pass just the output and parse it, without executing anything else in the device.

@ThomasJRyan
Copy link
Collaborator

Ah. Well if that's what you're doing then all you should need to do is run self.device.parse('<your_command_here>', output='<your_command_output_here>') which will parse it for you.

If there's more to it than that, I'm going to need more information. What parser are you using? What command? Are there any other error logs you can provide?

@balmasea
Copy link
Contributor Author

Sorry for my late answer, we have worked around the problem with a custom parser but for sure I'd love to help.
We are mainly trying to get the parsed yml from the device output that we get with our own module, so we do not connect to the devices using this library.

We are calling ShowBgpAllNeighborsAdvertisedRoutes::cli with output being, i.e.:
Total number of prefixes 0

Then, it ends up calling the cli method from the parent, ShowBgpNeighborsAdvertisedRoutesSuperParser::cli and it fails when executing line:
out_vrf = self.device.execute('show bgp all neighbors | i BGP neighbor')
because there is no device connected.

This is what I meant with the "non conditional instruction" sentence above. Hope it is clearer now and let me know if I can continue helping. Thanks.

@ThomasJRyan
Copy link
Collaborator

The problem is this line right here:

out_vrf = self.device.execute('show bgp all neighbors | i BGP neighbor')

It's weird that this is the way it is. As far as I'm aware, this is not allowed in a parser. Despite that though, this has been in place for three years now... If I'm understanding it, lines 4819 to 4831 should be able to be safely wrapped in a try/except to mitigate this problem. Line 4820 (vrf = 'default') would have to be put before the try/except block though. That should be an effective method of fixing this properly should you be interesting in implementing it

balmasea added a commit to balmasea/genieparser that referenced this issue Jan 25, 2022
@ThomasJRyan ThomasJRyan linked a pull request Feb 1, 2022 that will close this issue
5 tasks
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 a pull request may close this issue.

2 participants