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


Python netutils.is_valid_ipv6方法代码示例

本文整理汇总了Python中oslo_utils.netutils.is_valid_ipv6方法的典型用法代码示例。如果您正苦于以下问题:Python netutils.is_valid_ipv6方法的具体用法?Python netutils.is_valid_ipv6怎么用?Python netutils.is_valid_ipv6使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oslo_utils.netutils的用法示例。


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

示例1: get_uri

# 需要导入模块: from oslo_utils import netutils [as 别名]
# 或者: from oslo_utils.netutils import is_valid_ipv6 [as 别名]
def get_uri(self):
        if netutils.is_valid_ipv6(self.server_host):
            base_url = '%s://[%s]%s' % (self.scheme,
                                        self.server_host, self.path)
        else:
            base_url = '%s://%s%s' % (self.scheme,
                                      self.server_host, self.path)

        return '%s?%s' % (base_url, self.query)

    # NOTE(flaper87): Commenting out for now, it's probably better to do
    # it during image add/get. This validation relies on a config param
    # which doesn't make sense to have in the StoreLocation instance.
    # def _is_valid_path(self, path):
    #    sdir = self.conf.glance_store.vmware_store_image_dir.strip('/')
    #    return path.startswith(os.path.join(DS_URL_PREFIX, sdir)) 
开发者ID:openstack,项目名称:glance_store,代码行数:18,代码来源:vmware_datastore.py

示例2: export_unc_path

# 需要导入模块: from oslo_utils import netutils [as 别名]
# 或者: from oslo_utils.netutils import is_valid_ipv6 [as 别名]
def export_unc_path(ip_addr):
    """Convert IPv6 address to valid UNC path.

    In Microsoft Windows OS, UNC (Uniform Naming Convention) specifies a
    common syntax to describe the location of a network resource.

    The colon which used by IPv6 is an illegal character in a UNC path name.
    So the IPv6 address need to be converted to valid UNC path.

    References:
    - https://en.wikipedia.org/wiki/IPv6_address
      #Literal_IPv6_addresses_in_UNC_path_names
    - https://en.wikipedia.org/wiki/Path_(computing)#Uniform_Naming_Convention

    :param ip_addr: IPv6 address.
    :return: UNC path.
    """
    unc_suffix = '.ipv6-literal.net'
    if netutils.is_valid_ipv6(ip_addr):
        ip_addr = ip_addr.replace(':', '-') + unc_suffix
    return ip_addr 
开发者ID:openstack,项目名称:manila,代码行数:23,代码来源:utils.py

示例3: is_valid_ip_address

# 需要导入模块: from oslo_utils import netutils [as 别名]
# 或者: from oslo_utils.netutils import is_valid_ipv6 [as 别名]
def is_valid_ip_address(ip_address, ip_version):
    ip_version = ([int(ip_version)] if not isinstance(ip_version, list)
                  else ip_version)

    if not set(ip_version).issubset(set([4, 6])):
        raise exception.ManilaException(
            _("Provided improper IP version '%s'.") % ip_version)

    if 4 in ip_version:
        if netutils.is_valid_ipv4(ip_address):
            return True
    if 6 in ip_version:
        if netutils.is_valid_ipv6(ip_address):
            return True

    return False 
开发者ID:openstack,项目名称:manila,代码行数:18,代码来源:utils.py

示例4: _fix_esx_url

# 需要导入模块: from oslo_utils import netutils [as 别名]
# 或者: from oslo_utils.netutils import is_valid_ipv6 [as 别名]
def _fix_esx_url(url, host, port):
        """Fix netloc in the case of an ESX host.

        In the case of an ESX host, the netloc is set to '*' in the URL
        returned in HttpNfcLeaseInfo. It should be replaced with host name
        or IP address.
        """
        urlp = urlparse.urlparse(url)
        if urlp.netloc == '*':
            scheme, netloc, path, params, query, fragment = urlp
            if netutils.is_valid_ipv6(host):
                netloc = '[%s]:%d' % (host, port)
            else:
                netloc = "%s:%d" % (host, port)
            url = urlparse.urlunparse((scheme,
                                       netloc,
                                       path,
                                       params,
                                       query,
                                       fragment))
        return url 
开发者ID:openstack,项目名称:oslo.vmware,代码行数:23,代码来源:rw_handles.py

示例5: bind_udp

# 需要导入模块: from oslo_utils import netutils [as 别名]
# 或者: from oslo_utils.netutils import is_valid_ipv6 [as 别名]
def bind_udp(host, port):
    """Bind to an UDP port and listen.
    Use reuseaddr, reuseport if available

    :param host: IPv4/v6 address or "". "" binds to every IPv4 interface.
    :type host: str
    :param port: UDP port
    :type port: int
    :returns: socket
    """
    LOG.info('Opening UDP Listening Socket on %(host)s:%(port)d',
             {'host': host, 'port': port})
    family = socket.AF_INET6 if is_valid_ipv6(host) else socket.AF_INET
    sock_udp = socket.socket(family, socket.SOCK_DGRAM)
    sock_udp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

    # NOTE: Linux supports socket.SO_REUSEPORT only in 3.9 and later releases.
    try:
        sock_udp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
    except Exception:
        LOG.info('SO_REUSEPORT not available, ignoring.')

    sock_udp.settimeout(1)
    sock_udp.bind((host, port))
    if port == 0:
        newport = sock_udp.getsockname()[1]
        LOG.info('Listening on UDP port %(port)d', {'port': newport})

    return sock_udp 
开发者ID:openstack,项目名称:designate,代码行数:31,代码来源:utils.py

示例6: _set_url_prefix

# 需要导入模块: from oslo_utils import netutils [as 别名]
# 或者: from oslo_utils.netutils import is_valid_ipv6 [as 别名]
def _set_url_prefix(self):
        path = os.path.join(DS_URL_PREFIX,
                            self.store_image_dir)

        if netutils.is_valid_ipv6(self.server_host):
            self._url_prefix = '%s://[%s]%s' % (self.scheme,
                                                self.server_host, path)
        else:
            self._url_prefix = '%s://%s%s' % (self.scheme,
                                              self.server_host, path) 
开发者ID:openstack,项目名称:glance_store,代码行数:12,代码来源:vmware_datastore.py

示例7: _sanitize_mon_hosts

# 需要导入模块: from oslo_utils import netutils [as 别名]
# 或者: from oslo_utils.netutils import is_valid_ipv6 [as 别名]
def _sanitize_mon_hosts(self, hosts):
        def _sanitize_host(host):
            if netutils.is_valid_ipv6(host):
                host = '[%s]' % host
            return host
        return list(map(_sanitize_host, hosts)) 
开发者ID:openstack,项目名称:os-brick,代码行数:8,代码来源:rbd.py

示例8: parse_valid_host_port

# 需要导入模块: from oslo_utils import netutils [as 别名]
# 或者: from oslo_utils.netutils import is_valid_ipv6 [as 别名]
def parse_valid_host_port(host_port):
    """
    Given a "host:port" string, attempts to parse it as intelligently as
    possible to determine if it is valid. This includes IPv6 [host]:port form,
    IPv4 ip:port form, and hostname:port or fqdn:port form.

    Invalid inputs will raise a ValueError, while valid inputs will return
    a (host, port) tuple where the port will always be of type int.
    """

    try:
        try:
            host, port = netutils.parse_host_port(host_port)
        except Exception:
            raise ValueError(_('Host and port "%s" is not valid.') % host_port)

        if not netutils.is_valid_port(port):
            raise ValueError(_('Port "%s" is not valid.') % port)

        # First check for valid IPv6 and IPv4 addresses, then a generic
        # hostname. Failing those, if the host includes a period, then this
        # should pass a very generic FQDN check. The FQDN check for letters at
        # the tail end will weed out any hilariously absurd IPv4 addresses.

        if not (netutils.is_valid_ipv6(host) or netutils.is_valid_ipv4(host) or
                is_valid_hostname(host) or is_valid_fqdn(host)):
            raise ValueError(_('Host "%s" is not valid.') % host)

    except Exception as ex:
        raise ValueError(_('%s '
                           'Please specify a host:port pair, where host is an '
                           'IPv4 address, IPv6 address, hostname, or FQDN. If '
                           'using an IPv6 address, enclose it in brackets '
                           'separately from the port (i.e., '
                           '"[fe80::a:b:c]:9876").') % ex)

    return (host, int(port)) 
开发者ID:openstack,项目名称:searchlight,代码行数:39,代码来源:utils.py

示例9: _wrap_ipv6

# 需要导入模块: from oslo_utils import netutils [as 别名]
# 或者: from oslo_utils.netutils import is_valid_ipv6 [as 别名]
def _wrap_ipv6(ip):
    """Wrap a IP address in square brackets if IPv6

    """
    if netutils.is_valid_ipv6(ip):
        return "[%s]" % ip
    return ip 
开发者ID:openstack,项目名称:python-tripleoclient,代码行数:9,代码来源:undercloud_preflight.py

示例10: _get_soap_url

# 需要导入模块: from oslo_utils import netutils [as 别名]
# 或者: from oslo_utils.netutils import is_valid_ipv6 [as 别名]
def _get_soap_url(self, scheme, host, port):
        """Returns the IPv4/v6 compatible SOAP URL for the given host."""
        if netutils.is_valid_ipv6(host):
            return '%s://[%s]:%d' % (scheme, host, port)
        return '%s://%s:%d' % (scheme, host, port) 
开发者ID:openstack,项目名称:oslo.vmware,代码行数:7,代码来源:rw_handles.py

示例11: test_is_valid_ipv6

# 需要导入模块: from oslo_utils import netutils [as 别名]
# 或者: from oslo_utils.netutils import is_valid_ipv6 [as 别名]
def test_is_valid_ipv6(self):
        self.assertTrue(netutils.is_valid_ipv6('::1'))

        self.assertTrue(netutils.is_valid_ipv6('fe80::1%eth0'))

        self.assertFalse(netutils.is_valid_ip('fe%80::1%eth0'))

        self.assertFalse(netutils.is_valid_ipv6(
            '1fff::a88:85a3::172.31.128.1'))

        self.assertFalse(netutils.is_valid_ipv6('')) 
开发者ID:openstack,项目名称:oslo.utils,代码行数:13,代码来源:test_netutils.py

示例12: bind_tcp

# 需要导入模块: from oslo_utils import netutils [as 别名]
# 或者: from oslo_utils.netutils import is_valid_ipv6 [as 别名]
def bind_tcp(host, port, tcp_backlog, tcp_keepidle=None):
    """Bind to a TCP port and listen.
    Use reuseaddr, reuseport if available, keepalive if specified

    :param host: IPv4/v6 address or "". "" binds to every IPv4 interface.
    :type host: str
    :param port: TCP port
    :type port: int
    :param tcp_backlog: TCP listen backlog
    :type tcp_backlog: int
    :param tcp_keepidle: TCP keepalive interval
    :type tcp_keepidle: int
    :returns: socket
    """
    LOG.info('Opening TCP Listening Socket on %(host)s:%(port)d',
             {'host': host, 'port': port})
    family = socket.AF_INET6 if is_valid_ipv6(host) else socket.AF_INET
    sock_tcp = socket.socket(family, socket.SOCK_STREAM)
    sock_tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    sock_tcp.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)

    # NOTE: Linux supports socket.SO_REUSEPORT only in 3.9 and later releases.
    try:
        sock_tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
    except Exception:
        LOG.info('SO_REUSEPORT not available, ignoring.')

    # This option isn't available in the OS X version of eventlet
    if tcp_keepidle and hasattr(socket, 'TCP_KEEPIDLE'):
        sock_tcp.setsockopt(socket.IPPROTO_TCP,
                            socket.TCP_KEEPIDLE,
                            tcp_keepidle)

    sock_tcp.settimeout(1)
    sock_tcp.bind((host, port))
    if port == 0:
        newport = sock_tcp.getsockname()[1]
        LOG.info('Listening on TCP port %(port)d', {'port': newport})

    sock_tcp.listen(tcp_backlog)

    return sock_tcp 
开发者ID:openstack,项目名称:designate,代码行数:44,代码来源:utils.py


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