-
Notifications
You must be signed in to change notification settings - Fork 22
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
Update implementation.py to check for .exploded attribute #108
base: main
Are you sure you want to change the base?
Conversation
if 'host' in self.connection_info: | ||
ip = self.connection_info['host'] | ||
else: | ||
ip = self.connection_info['ip'].exploded | ||
ip = self.connection_info['ip'] | ||
if hasattr(ip, 'exploded'): | ||
ip = ip.exploded |
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.
To use an address that is not an IPAddress object, you can pass the host
key instead.
For this change I suggest the following code:
ip = self.connection_info['ip']
if isinstance(ip, (ipaddress.IPv4Address, ipaddress.IPv6Address)):
ip = ip.exploded
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.
Minor changes to proposed solution (for your review):
- Reduce scope of imports - only
ip_address
,IPv4Address
, andIPv6Address
from theipaddress
package. - IP logic to check if the
ip
is NOT an instance of IPv4 or IPv6 - if this is true, generate a newip_address
object. This allows testing of IPv6Address and subsequent URL fixup.
Example change from IOS XE follows:
ip = self.connection_info['ip']
if not isinstance(ip, (IPv4Address, IPv6Address)):
ip = ip_address(ip)
# Properly format IPv6 URL if a v6 address is provided
if isinstance(ip, IPv6Address):
ip = f"[{ip.exploded}]"
else:
ip = ip.exploded
When generating dynamic testbed objects, implementation.py expects an ipaddress object to be passed as the IP address. This change checks for the existence of the exploded attribute for each IP / host before assigning that attribute, simplifying dynamic testbed creation using string values for addresses
In addition, the IOS XE implementation has been updated to properly generate an IPv6 URL in the format [xxxx:yyyy....]:{port} to validate functionality. If this passes scrutiny and code style checks, another PR will be generated to update other implementations.