gen-cisco
gen-cisco copied to clipboard
Check the input fields in the YAML file
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.
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.