当前位置: 首页>>代码示例>>Python>>正文


Python attributes._validate_ip_address函数代码示例

本文整理汇总了Python中neutron.api.v2.attributes._validate_ip_address函数的典型用法代码示例。如果您正苦于以下问题:Python _validate_ip_address函数的具体用法?Python _validate_ip_address怎么用?Python _validate_ip_address使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了_validate_ip_address函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _validate_allowed_address_pairs

def _validate_allowed_address_pairs(address_pairs, valid_values=None):
    unique_check = {}
    if len(address_pairs) > cfg.CONF.max_allowed_address_pair:
        raise AllowedAddressPairExhausted(quota=cfg.CONF.max_allowed_address_pair)

    for address_pair in address_pairs:
        # mac_address is optional, if not set we use the mac on the port
        if "mac_address" in address_pair:
            msg = attr._validate_mac_address(address_pair["mac_address"])
            if msg:
                raise webob.exc.HTTPBadRequest(msg)
        if "ip_address" not in address_pair:
            raise AllowedAddressPairsMissingIP()

        mac = address_pair.get("mac_address")
        ip_address = address_pair["ip_address"]
        if (mac, ip_address) not in unique_check:
            unique_check[(mac, ip_address)] = None
        else:
            raise DuplicateAddressPairInRequest(mac_address=mac, ip_address=ip_address)

        invalid_attrs = set(address_pair.keys()) - set(["mac_address", "ip_address"])
        if invalid_attrs:
            msg = _("Unrecognized attribute(s) '%s'") % ", ".join(
                set(address_pair.keys()) - set(["mac_address", "ip_address"])
            )
            raise webob.exc.HTTPBadRequest(msg)

        if "/" in ip_address:
            msg = attr._validate_subnet(ip_address)
        else:
            msg = attr._validate_ip_address(ip_address)
        if msg:
            raise webob.exc.HTTPBadRequest(msg)
开发者ID:jocado,项目名称:neutron,代码行数:34,代码来源:allowedaddresspairs.py

示例2: _validate_allowed_address_pairs

def _validate_allowed_address_pairs(address_pairs, valid_values=None):
    unique_check = {}
    for address_pair in address_pairs:
        # mac_address is optional, if not set we use the mac on the port
        if 'mac_address' in address_pair:
            msg = attr._validate_mac_address(address_pair['mac_address'])
            if msg:
                raise webob.exc.HTTPBadRequest(msg)
        if 'ip_address' not in address_pair:
            raise AllowedAddressPairsMissingIP()

        mac = address_pair.get('mac_address')
        ip_address = address_pair['ip_address']
        if (mac, ip_address) not in unique_check:
            unique_check[(mac, ip_address)] = None
        else:
            raise DuplicateAddressPairInRequest(mac_address=mac,
                                                ip_address=ip_address)

        invalid_attrs = set(address_pair.keys()) - set(['mac_address',
                                                        'ip_address'])
        if invalid_attrs:
            msg = (_("Unrecognized attribute(s) '%s'") %
                   ', '.join(set(address_pair.keys()) -
                             set(['mac_address', 'ip_address'])))
            raise webob.exc.HTTPBadRequest(msg)

        if '/' in ip_address:
            msg = attr._validate_subnet(ip_address)
        else:
            msg = attr._validate_ip_address(ip_address)
        if msg:
            raise webob.exc.HTTPBadRequest(msg)
开发者ID:PFZheng,项目名称:neutron,代码行数:33,代码来源:allowedaddresspairs.py

示例3: _validate_gbproutes

def _validate_gbproutes(data, valid_values=None):
    # Shamelessly copied from Neutron, will pass even if nexthop is valid
    if not isinstance(data, list):
        msg = _("Invalid data format for hostroute: '%s'") % data
        LOG.debug(msg)
        return msg

    expected_keys = ['destination', 'nexthop']
    hostroutes = []
    for hostroute in data:
        msg = attr._verify_dict_keys(expected_keys, hostroute)
        if msg:
            LOG.debug(msg)
            return msg
        msg = attr._validate_subnet(hostroute['destination'])
        if msg:
            LOG.debug(msg)
            return msg
        if hostroute['nexthop']:
            msg = attr._validate_ip_address(hostroute['nexthop'])
        if msg:
            LOG.debug(msg)
            return msg
        if hostroute in hostroutes:
            msg = _("Duplicate hostroute '%s'") % hostroute
            LOG.debug(msg)
            return msg
        hostroutes.append(hostroute)
开发者ID:Vikash082,项目名称:group-based-policy,代码行数:28,代码来源:group_policy.py

示例4: test_validate_ip_address_with_leading_zero

    def test_validate_ip_address_with_leading_zero(self):
        ip_addr = "1.1.1.01"
        expected_msg = "'%(data)s' is not an accepted IP address, " "'%(ip)s' is recommended"
        msg = attributes._validate_ip_address(ip_addr)
        self.assertEqual(expected_msg % {"data": ip_addr, "ip": "1.1.1.1"}, msg)

        ip_addr = "1.1.1.011"
        msg = attributes._validate_ip_address(ip_addr)
        self.assertEqual(expected_msg % {"data": ip_addr, "ip": "1.1.1.11"}, msg)

        ip_addr = "1.1.1.09"
        msg = attributes._validate_ip_address(ip_addr)
        self.assertEqual(expected_msg % {"data": ip_addr, "ip": "1.1.1.9"}, msg)

        ip_addr = "fe80:0:0:0:0:0:0:0001"
        msg = attributes._validate_ip_address(ip_addr)
        self.assertIsNone(msg)
开发者ID:manjeetbhatia,项目名称:test_l3,代码行数:17,代码来源:test_attributes.py

示例5: test_validate_ip_address

    def test_validate_ip_address(self):
        ip_addr = '1.1.1.1'
        msg = attributes._validate_ip_address(ip_addr)
        self.assertIsNone(msg)

        ip_addr = '1111.1.1.1'
        msg = attributes._validate_ip_address(ip_addr)
        self.assertEqual(msg, "'%s' is not a valid IP address" % ip_addr)

        ip_addr = '1.1.1.1 has whitespace'
        msg = attributes._validate_ip_address(ip_addr)
        self.assertEqual(msg, "'%s' is not a valid IP address" % ip_addr)

        ip_addr = '111.1.1.1\twhitespace'
        msg = attributes._validate_ip_address(ip_addr)
        self.assertEqual(msg, "'%s' is not a valid IP address" % ip_addr)

        ip_addr = '111.1.1.1\nwhitespace'
        msg = attributes._validate_ip_address(ip_addr)
        self.assertEqual(msg, "'%s' is not a valid IP address" % ip_addr)

        for ws in string.whitespace:
            ip_addr = '%s111.1.1.1' % ws
            msg = attributes._validate_ip_address(ip_addr)
            self.assertEqual(msg, "'%s' is not a valid IP address" % ip_addr)

        for ws in string.whitespace:
            ip_addr = '111.1.1.1%s' % ws
            msg = attributes._validate_ip_address(ip_addr)
            self.assertEqual(msg, "'%s' is not a valid IP address" % ip_addr)
开发者ID:leesurezen,项目名称:neutron,代码行数:30,代码来源:test_attributes.py

示例6: _validate_nexthops

def _validate_nexthops(nexthops):
    seen = []
    for ip in nexthops:
        msg = attr._validate_ip_address(ip)
        if ip in seen:
            msg = _("Duplicate nexthop in rule '%s'") % ip
        seen.append(ip)
        if msg:
            return msg
开发者ID:CiscoSystems,项目名称:neutron,代码行数:9,代码来源:routerrule.py

示例7: test_validate_ip_address

    def test_validate_ip_address(self):
        ip_addr = "1.1.1.1"
        msg = attributes._validate_ip_address(ip_addr)
        self.assertIsNone(msg)

        ip_addr = "1111.1.1.1"
        msg = attributes._validate_ip_address(ip_addr)
        self.assertEqual(msg, "'%s' is not a valid IP address" % ip_addr)

        ip_addr = "1.1.1.1 has whitespace"
        msg = attributes._validate_ip_address(ip_addr)
        self.assertEqual(msg, "'%s' is not a valid IP address" % ip_addr)

        ip_addr = "111.1.1.1\twhitespace"
        msg = attributes._validate_ip_address(ip_addr)
        self.assertEqual(msg, "'%s' is not a valid IP address" % ip_addr)

        ip_addr = "111.1.1.1\nwhitespace"
        msg = attributes._validate_ip_address(ip_addr)
        self.assertEqual(msg, "'%s' is not a valid IP address" % ip_addr)
开发者ID:ZelinIO,项目名称:neutron,代码行数:20,代码来源:test_attributes.py

示例8: test_validate_ip_address_bsd

 def test_validate_ip_address_bsd(self):
     # NOTE(yamamoto):  On NetBSD and OS X, netaddr.IPAddress() accepts
     # '1' * 59 as a valid address.  The behaviour is inherited from
     # libc behaviour there.  This test ensures that our validator reject
     # such addresses on such platforms by mocking netaddr to emulate
     # the behaviour.
     ip_addr = '1' * 59
     with mock.patch('netaddr.IPAddress') as ip_address_cls:
         msg = attributes._validate_ip_address(ip_addr)
     ip_address_cls.assert_called_once_with(ip_addr)
     self.assertEqual("'%s' is not a valid IP address" % ip_addr, msg)
开发者ID:glove747,项目名称:liberty-neutron,代码行数:11,代码来源:test_attributes.py

示例9: _validate_ip_or_subnet_or_none

def _validate_ip_or_subnet_or_none(data, valid_values=None):
    if data is None:
        return None
    msg_ip = attributes._validate_ip_address(data, valid_values)
    if not msg_ip:
        return None
    msg_subnet = attributes._validate_subnet(data, valid_values)
    if not msg_subnet:
        return None
    return _("%(msg_ip)s and %(msg_subnet)s") % {'msg_ip': msg_ip,
                                                 'msg_subnet': msg_subnet}
开发者ID:adiantum,项目名称:networking-portforwarding,代码行数:11,代码来源:portforwardings.py

示例10: test_validate_ip_address

    def test_validate_ip_address(self):
        ip_addr = '1.1.1.1'
        msg = attributes._validate_ip_address(ip_addr)
        self.assertIsNone(msg)

        ip_addr = '1111.1.1.1'
        msg = attributes._validate_ip_address(ip_addr)
        self.assertEqual(msg, "'%s' is not a valid IP address" % ip_addr)

        # Depending on platform to run UTs, this case might or might not be
        # an equivalent to test_validate_ip_address_bsd.
        ip_addr = '1' * 59
        msg = attributes._validate_ip_address(ip_addr)
        self.assertEqual("'%s' is not a valid IP address" % ip_addr, msg)

        ip_addr = '1.1.1.1 has whitespace'
        msg = attributes._validate_ip_address(ip_addr)
        self.assertEqual(msg, "'%s' is not a valid IP address" % ip_addr)

        ip_addr = '111.1.1.1\twhitespace'
        msg = attributes._validate_ip_address(ip_addr)
        self.assertEqual(msg, "'%s' is not a valid IP address" % ip_addr)

        ip_addr = '111.1.1.1\nwhitespace'
        msg = attributes._validate_ip_address(ip_addr)
        self.assertEqual(msg, "'%s' is not a valid IP address" % ip_addr)
开发者ID:kongseokhwan,项目名称:kulcloud-neutron,代码行数:26,代码来源:test_attributes.py

示例11: resolve_peer_address

    def resolve_peer_address(self, ipsec_sitecon, router):
        address = ipsec_sitecon['peer_address']
        # check if address is an ip address or fqdn
        invalid_ip_address = attributes._validate_ip_address(address)
        if invalid_ip_address:
            # resolve fqdn
            try:
                addrinfo = socket.getaddrinfo(address, None)[0]
                ipsec_sitecon['peer_address'] = addrinfo[-1][0]
            except socket.gaierror:
                raise vpnaas.VPNPeerAddressNotResolved(peer_address=address)

        ip_version = netaddr.IPAddress(ipsec_sitecon['peer_address']).version
        self._validate_peer_address(ip_version, router)
开发者ID:JinJingLin,项目名称:neutron-vpnaas,代码行数:14,代码来源:vpn_validator.py

示例12: _get_nexthop

 def _get_nexthop(self, address, connection_id):
     # check if address is an ip address or fqdn
     invalid_ip_address = attributes._validate_ip_address(address)
     if invalid_ip_address:
         ip_addr = self._resolve_fqdn(address)
         if not ip_addr:
             self._record_connection_status(connection_id, constants.ERROR, force_status_update=True)
             raise vpnaas.VPNPeerAddressNotResolved(peer_address=address)
     else:
         ip_addr = address
     routes = self._execute(["ip", "route", "get", ip_addr])
     if routes.find("via") >= 0:
         return routes.split(" ")[2]
     return address
开发者ID:srikanthpoolla,项目名称:neutron-vpnaas,代码行数:14,代码来源:ipsec.py

示例13: _get_nexthop

 def _get_nexthop(self, address, connection_id):
     # check if address is an ip address or fqdn
     invalid_ip_address = attributes._validate_ip_address(address)
     if invalid_ip_address:
         ip_addr = self._resolve_fqdn(address)
         if not ip_addr:
             self._record_connection_status(connection_id, constants.ERROR,
                                            updated_pending_status=True)
             raise vpnaas.VPNPeerAddressNotResolved(peer_address=address)
     else:
         ip_addr = address
     routes = self._execute(['ip', 'route', 'get', ip_addr])
     if routes.find('via') >= 0:
         return routes.split(' ')[2]
     return address
开发者ID:promisejohn,项目名称:neutron-vpnaas,代码行数:15,代码来源:ipsec.py

示例14: _validate_port_dict

def _validate_port_dict(values):
    if not isinstance(values, dict):
        msg = _("%s is not a valid dictionary") % values
        LOG.debug(msg)
        return msg
    port_id = values.get('port_id')
    fixed_ip = values.get('fixed_ip_address')
    msg = attr._validate_uuid(port_id)
    if msg:
        return msg
    if fixed_ip is None:
        return
    msg = attr._validate_ip_address(fixed_ip)
    if msg:
        return msg
开发者ID:openstack,项目名称:quark,代码行数:15,代码来源:scalingip.py

示例15: _validate_allowed_address_pairs

def _validate_allowed_address_pairs(address_pairs, valid_values=None):
    unique_check = {}
    if len(address_pairs) > cfg.CONF.max_allowed_address_pair:
        raise AllowedAddressPairExhausted(
            quota=cfg.CONF.max_allowed_address_pair)

    for address_pair in address_pairs:
        # mac_address is optional, if not set we use the mac on the port
        if 'mac_address' in address_pair:
            msg = attr._validate_mac_address(address_pair['mac_address'])
            if msg:
                raise webob.exc.HTTPBadRequest(msg)
        if 'ip_address' not in address_pair:
            raise AllowedAddressPairsMissingIP()

        mac = address_pair.get('mac_address')
        ip_address = address_pair['ip_address']
        if (mac, ip_address) not in unique_check:
            unique_check[(mac, ip_address)] = None
        else:
            raise DuplicateAddressPairInRequest(mac_address=mac,
                                                ip_address=ip_address)

        invalid_attrs = set(address_pair.keys()) - set(['mac_address',
                                                        'ip_address'])
        if invalid_attrs:
            msg = (_("Unrecognized attribute(s) '%s'") %
                   ', '.join(set(address_pair.keys()) -
                             set(['mac_address', 'ip_address'])))
            raise webob.exc.HTTPBadRequest(msg)

        if (netaddr.IPNetwork(ip_address).prefixlen == 0):
            raise AllowedAddressPairsZeroPrefixNotAllowed()
        elif '/' in ip_address:
            msg = attr._validate_subnet(ip_address)
        else:
            msg = attr._validate_ip_address(ip_address)
        if msg:
            raise webob.exc.HTTPBadRequest(msg)
开发者ID:kongseokhwan,项目名称:kulcloud-neutron,代码行数:39,代码来源:allowedaddresspairs.py


注:本文中的neutron.api.v2.attributes._validate_ip_address函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。