當前位置: 首頁>>代碼示例>>Python>>正文


Python netutils.parse_host_port方法代碼示例

本文整理匯總了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) 
開發者ID:openstack,項目名稱:designate,代碼行數:23,代碼來源:service.py

示例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) 
開發者ID:openstack,項目名稱:senlin,代碼行數:23,代碼來源:service.py

示例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)) 
開發者ID:openstack,項目名稱:oslo.utils,代碼行數:21,代碼來源:test_netutils.py

示例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]) 
開發者ID:openstack,項目名稱:designate,代碼行數:12,代碼來源:service.py

示例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)) 
開發者ID:openstack,項目名稱:searchlight,代碼行數:39,代碼來源:utils.py

示例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) 
開發者ID:openstack,項目名稱:monasca-api,代碼行數:13,代碼來源:types.py

示例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') 
開發者ID:openstack,項目名稱:monasca-notification,代碼行數:12,代碼來源:types.py


注:本文中的oslo_utils.netutils.parse_host_port方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。