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

Change Parsing format of IP to CIDR format and Add support for secondary IP addresses #12

Open
michael-edobor opened this issue Aug 6, 2022 · 0 comments

Comments

@michael-edobor
Copy link
Contributor

Parse all secondary IP addresses found under interface configs into a list and change IP address notation to cidr instead of ip address mask subnet. This can be implemented by introducing a macro to the interfaces group and using the inbuilt to_cidr method to convert the masks.

Use-case:

  1. Makes it easier to create a IPNetwork object from the netaddr library
  2. Easier to represent when comparing IPs with a SoT (e.g Netbox)
  3. Fully account for IP information in the configs
def parse_ip(data):
	if data.get('primary_ip') and data.get('primary_mask'):
		data['primary_ip'] = data['primary_ip'] + '/' + str(data['primary_mask'])
		data.pop('primary_mask')
	if data.get('secondary_ips') and data.get('secondary_masks'):
		data['secondary_ips'] = [f"{ip}/{mask}" for ip, mask in zip(data['secondary_ips'], data['secondary_masks'])]
		data.pop('secondary_masks')
</macro>

I can submit a PR for this also.

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

No branches or pull requests

1 participant