def _validate_ip_version(self, ip_version, addr, name):
        ip = netaddr.IPNetwork(addr)
        if ip.version != ip_version:
            data = {'name': name,
                    'addr': addr,
                    'ip_version': ip_version}
            msg = _("%(name)s '%(addr)s' does not match "
                    "the ip_version '%(ip_version)s'") % data
            raise exc.InvalidInput(error_message=msg)
Check IP field of a subnet match specified ip version.
dataset/ETHPy150Open openstack/neutron/neutron/db/db_base_plugin_v2.py/NeutronDbPluginV2._validate_ip_version