-
Notifications
You must be signed in to change notification settings - Fork 68
fix issue #255 (_parse_bgp_as regex to match as and asdot) #256
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
Conversation
pyeapi/api/bgp.py
Outdated
| def _parse_bgp_as(self, config): | ||
| match = re.search(r'^router bgp (\d+)', config) | ||
| match = re.search(r'^router bgp (\d+.\d+)', config) | ||
| return dict(bgp_as=int(match.group(1))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 82 converts to integer though so even if the regex allows the dot, converting it to int will cause the script to throw an exception and stop executing:
$ python3
>>> match = "65001.10"
>>> print(int(match))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '65001.10'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, been discussing this on reddit and well and just noticed. Hoped that to be a quick fix, but this seems to be ahead me. So I guess this can be closed and somebody with more experience should try getting this to work, or confirm that this (returning also asdot) will not be implemented so I have to get asdot notation in a different way somewhere in my script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about if you handle it like this:
match = re.search(r'^router bgp (\d+)\.?(\d+)?', config)
if match.lastindex == 2:
return dict(bgp_as='.'.join(match.group(1,2)) )
else:
return dict(bgp_as=int(match.group(1)))if it is dotASN you return it as a string, and otherwise you'd return the int as currently exists
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the replies, I have updated and tested again and it seems to work now. Do I have to re-open the pull request or is this automatically added?
The reason why RE
Please amend your PR respectively and I'll approve the changes |
@dlyssenko code has been changed accordingly. |
|
@bh-rr , could you please fix indentation in |
|
@dlyssenko done (i hope) |
This will not only match AS number (i.e 65001) but also AS number in asdot notation (ie. 65001.10).