-
Notifications
You must be signed in to change notification settings - Fork 70
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
Staticroute #45
Staticroute #45
Conversation
route['next_hop_ip'], route['distance']) | ||
|
||
# Update the routes dict | ||
routes.update({route_id: route}) |
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.
Hi Gary,
I was doing some testing and I'm not sure the hyphen-separated key is the way to go. This produces:
{'1.1.1.0/24--2.2.2.2--None--1': {'distance': '1',
'ip_dest': '1.1.1.0/24',
'next_hop': '2.2.2.2',
'next_hop_ip': None,
'route_name': None,
'tag': '0'},
'1.1.1.0/24--2.2.2.2--None--3': {'distance': '3',
'ip_dest': '1.1.1.0/24',
'next_hop': '2.2.2.2',
'next_hop_ip': None,
'route_name': None,
'tag': '0'},
'1.1.1.0/24--2.2.2.2--None--5': {'distance': '5',
'ip_dest': '1.1.1.0/24',
'next_hop': '2.2.2.2',
'next_hop_ip': None,
'route_name': None,
'tag': '0'}}
Which is a little hard to read. For routemaps, I implemented a tuple-based key, eg for staticroute:
{('1.1.1.0/24', '2.2.2.2', None, 5): {'distance': '5',
'ip_dest': '1.1.1.0/24',
'next_hop': '2.2.2.2',
'next_hop_ip': None,
'route_name': None,
'tag': '0'}}
This is nice because you can use Python's built in get method to do something like:
staticroutes_dict.get( ('1.1.1.0/24', '2.2.2.2', None, 5) ) and it would return the corresponding dictionary.
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.
Hi Phil,
This is a great suggestion, and was fairly simple to implement the
change. I'm still picking up some of the nuances of python, and
appreciate the tips you have given.
Gary
On 10/15/15 1:46 PM, Philip DiLeo wrote:
In pyeapi/api/staticroute.py
#45 (comment):
# empty strings with None
route = dict()
route['ip_dest'] = match[0]
route['next_hop'] = match[1]
route['next_hop_ip'] = None if match[2] is '' else match[2]
route['distance'] = match[3]
route['tag'] = None if match[4] is '' else match[4]
route['route_name'] = None if match[5] is '' else match[5]
# Build a unique route_id from the ip_dest, next_hop, and distance
route_id = ROUTE_ID % \
(route['ip_dest'], route['next_hop'],
route['next_hop_ip'], route['distance'])
# Update the routes dict
routes.update({route_id: route})
Hi Gary,
I was doing some testing and I'm not sure the hyphen-separated key is
the way to go. This produces:|{'1.1.1.0/24--2.2.2.2--None--1': {'distance': '1', 'ip_dest':
'1.1.1.0/24', 'next_hop': '2.2.2.2', 'next_hop_ip': None,
'route_name': None, 'tag': '0'}, '1.1.1.0/24--2.2.2.2--None--3':
{'distance': '3', 'ip_dest': '1.1.1.0/24', 'next_hop': '2.2.2.2',
'next_hop_ip': None, 'route_name': None, 'tag': '0'},
'1.1.1.0/24--2.2.2.2--None--5': {'distance': '5', 'ip_dest':
'1.1.1.0/24', 'next_hop': '2.2.2.2', 'next_hop_ip': None,
'route_name': None, 'tag': '0'}} |Which is a little hard to read. For routemaps, I implemented a
tuple-based key, eg for staticroute:|('1.1.1.0/24', '2.2.2.2', None, 5): {'distance': '5', 'ip_dest':
'1.1.1.0/24', 'next_hop': '2.2.2.2', 'next_hop_ip': None,
'route_name': None, 'tag': '0'}} |This is nice because you can use Python's built in get method to do
something like:staticroutes_dict.get( ('1.1.1.0/24', '2.2.2.2', None, 5) ) and it
would return the corresponding dictionary.—
Reply to this email directly or view it on GitHub
https://github.com/arista-eosplus/pyeapi/pull/45/files#r42170898.
distance = 1 | ||
|
||
# Make the unique route_id tuple for the requested route | ||
route_id = (ip_dest, next_hop, next_hop_ip, int(distance)) |
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.
Something to think about: If I pass in distance='a', your call for int(distance) will throw an error. You may think about a try and except and raise a ValueError if it can't cast it into an int.
Release Note: |
Add staticroute library with system/unit tests