def parse_add_loopback():
    """
    Validate params when adding a loopback adapter
    """

    class Add(argparse.Action):

        def __call__(self, parser, args, values, option_string=None):
            try:
                ipaddress.IPv4Interface("{}/{}".format(values[1], values[2]))
            except ipaddress.AddressValueError as e:
                raise argparse.ArgumentTypeError("Invalid IP address: {}".format(e))
            except ipaddress.NetmaskValueError as e:
                raise argparse.ArgumentTypeError("Invalid subnet mask: {}".format(e))
            setattr(args, self.dest, values)
    return Add
Validate params when adding a loopback adapter