本文整理汇总了Python中oslo_utils.netutils.parse_host_port方法的典型用法代码示例。如果您正苦于以下问题:Python netutils.parse_host_port方法的具体用法?Python netutils.parse_host_port怎么用?Python netutils.parse_host_port使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oslo_utils.netutils
的用法示例。
在下文中一共展示了netutils.parse_host_port方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from oslo_utils import netutils [as 别名]
# 或者: from oslo_utils.netutils import parse_host_port [as 别名]
def __init__(self, app, name, listen, max_url_len=None):
super(WSGIService, self).__init__(name)
self.app = app
self.name = name
self.listen = listen
self.servers = []
for address in self.listen:
host, port = netutils.parse_host_port(address)
server = wsgi.Server(
CONF, name, app,
host=host,
port=port,
pool_size=CONF['service:api'].threads,
use_ssl=sslutils.is_enabled(CONF),
max_url_len=max_url_len
)
self.servers.append(server)
示例2: __init__
# 需要导入模块: from oslo_utils import netutils [as 别名]
# 或者: from oslo_utils.netutils import parse_host_port [as 别名]
def __init__(self, app, name, listen, max_url_len=None):
super(WSGIService, self).__init__(CONF.senlin_api.threads)
self.app = app
self.name = name
self.listen = listen
self.servers = []
for address in self.listen:
host, port = netutils.parse_host_port(address)
server = wsgi.Server(
CONF, name, app,
host=host,
port=port,
pool_size=CONF.senlin_api.threads,
use_ssl=sslutils.is_enabled(CONF),
max_url_len=max_url_len
)
self.servers.append(server)
示例3: test_parse_host_port
# 需要导入模块: from oslo_utils import netutils [as 别名]
# 或者: from oslo_utils.netutils import parse_host_port [as 别名]
def test_parse_host_port(self):
self.assertEqual(('server01', 80),
netutils.parse_host_port('server01:80'))
self.assertEqual(('server01', None),
netutils.parse_host_port('server01'))
self.assertEqual(('server01', 1234),
netutils.parse_host_port('server01',
default_port=1234))
self.assertEqual(('::1', 80),
netutils.parse_host_port('[::1]:80'))
self.assertEqual(('::1', None),
netutils.parse_host_port('[::1]'))
self.assertEqual(('::1', 1234),
netutils.parse_host_port('[::1]',
default_port=1234))
self.assertEqual(('2001:db8:85a3::8a2e:370:7334', 1234),
netutils.parse_host_port(
'2001:db8:85a3::8a2e:370:7334',
default_port=1234))
示例4: start
# 需要导入模块: from oslo_utils import netutils [as 别名]
# 或者: from oslo_utils.netutils import parse_host_port [as 别名]
def start(self):
self._running.set()
addresses = map(
netutils.parse_host_port,
set(self.listen)
)
for address in addresses:
self._start(address[0], address[1])
示例5: parse_valid_host_port
# 需要导入模块: from oslo_utils import netutils [as 别名]
# 或者: from oslo_utils.netutils import parse_host_port [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))
示例6: __call__
# 需要导入模块: from oslo_utils import netutils [as 别名]
# 或者: from oslo_utils.netutils import parse_host_port [as 别名]
def __call__(self, value):
addr, port = netutils.parse_host_port(value)
# NOTE(gmann): parse_host_port() return port as None if no port is
# supplied in value so setting port as string for correct
# parsing and error otherwise it will not be parsed for NoneType.
port = 'None' if port is None else port
addr = self.validate_addr(addr)
port = self._validate_port(port)
if not addr and not port:
raise ValueError('%s is not valid ip with optional port')
return '%s:%d' % (addr, port)
示例7: __call__
# 需要导入模块: from oslo_utils import netutils [as 别名]
# 或者: from oslo_utils.netutils import parse_host_port [as 别名]
def __call__(self, value):
addr, port = netutils.parse_host_port(value)
addr = self._validate_addr(addr)
port = self._validate_port(port)
LOG.debug('addr: %s port: %s' % (addr, port))
if addr and port:
return '%s:%d' % (addr, port)
raise ValueError('%s is not valid host address with optional port')