Skip to content
This repository has been archived by the owner on Jul 13, 2020. It is now read-only.

Check the input fields in the YAML file #6

Open
Kana00 opened this issue Apr 29, 2018 · 1 comment
Open

Check the input fields in the YAML file #6

Kana00 opened this issue Apr 29, 2018 · 1 comment

Comments

@Kana00
Copy link

Kana00 commented Apr 29, 2018

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.

@rememberYou
Copy link
Owner

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants