gen-cisco icon indicating copy to clipboard operation
gen-cisco copied to clipboard

Check the input fields in the YAML file

Open Kana00 opened this issue 6 years ago โ€ข 1 comments

Hi,

Thanks for gen-cisco, I was wondering if it would be possible to include an input parser for the specified YAML file in the command line.

For example, this parser could distinguish an incorrect IP address based on the network mask. This could save time debugging.

May be a REGEX matcher, like:

^(25[0โ€“5]|2[0โ€“4][0โ€“9]|[01]?[0โ€“9][0โ€“9]?).(25[0โ€“5]|2[0โ€“4][0โ€“9]|[01]?[0โ€“9][0โ€“9]?).(25[0โ€“5]|2[0โ€“4][0โ€“9]|[01]?[0โ€“9][0โ€“9]?).(25[0โ€“5]|2[0โ€“4][0โ€“9]|[01]?[0โ€“9][0โ€“9]?)$

Whatever, I think the best way is to check if this address is correctly installed with the context of the current installed network.

Kana00 avatar Apr 29 '18 14:04 Kana00

Thank you for your contribution, Jinja2 already provides a basic check, but does not allow to validate the consistency of a field.

^(25[0โ€“5]|2[0โ€“4][0โ€“9]|[01]?[0โ€“9][0โ€“9]?).(25[0โ€“5]|2[0โ€“4][0โ€“9]|[01]?[0โ€“9][0โ€“9]?).(25[0โ€“5]|2[0โ€“4][0โ€“9]|[01]?[0โ€“9][0โ€“9]?).(25[0โ€“5]|2[0โ€“4][0โ€“9]|[01]?[0โ€“9][0โ€“9]?)$

No need to go through a regex to check an IP address, Python already has a library for that.

import socket

def is_valid_ipv4(ip):
    try:
        socket.inet_aton(ip)
        return True
    except socket.error:
        return False

Whatever, I think the best way is to check if this address is correctly installed with the context of the current installed network.

Being able to check the IP address against the real network does not fit into the scope of gen-cisco. Even if this is not the priority at the moment, we could actually verify the validation of some entered values against the values accepted by the appropriate Cisco device by returning an error to the user, if necessary.

rememberYou avatar Apr 29 '18 15:04 rememberYou