本文整理汇总了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))
示例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
示例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
示例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
示例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
示例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)
示例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))
示例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))
示例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
示例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)
示例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(''))
示例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