Skip to content

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

@michael-edobor

Description

@michael-edobor

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions