netutils

Network-related utilities and helper functions.

oslo.utils.netutils.parse_host_port(address, default_port=None)

Interpret a string as a host:port pair.

An IPv6 address MUST be escaped if accompanied by a port, because otherwise ambiguity ensues: 2001:db8:85a3::8a2e:370:7334 means both [2001:db8:85a3::8a2e:370:7334] and [2001:db8:85a3::8a2e:370]:7334.

>>> parse_host_port('server01:80')
('server01', 80)
>>> parse_host_port('server01')
('server01', None)
>>> parse_host_port('server01', default_port=1234)
('server01', 1234)
>>> parse_host_port('[::1]:80')
('::1', 80)
>>> parse_host_port('[::1]')
('::1', None)
>>> parse_host_port('[::1]', default_port=1234)
('::1', 1234)
>>> parse_host_port('2001:db8:85a3::8a2e:370:7334', default_port=1234)
('2001:db8:85a3::8a2e:370:7334', 1234)
>>> parse_host_port(None)
(None, None)
oslo.utils.netutils.set_tcp_keepalive(sock, tcp_keepalive=True, tcp_keepidle=None, tcp_keepalive_interval=None, tcp_keepalive_count=None)

Set values for tcp keepalive parameters

This function configures tcp keepalive parameters if users wish to do so.

Parameters:
  • tcp_keepalive – Boolean, turn on or off tcp_keepalive. If users are not sure, this should be True, and default values will be used.
  • tcp_keepidle – time to wait before starting to send keepalive probes
  • tcp_keepalive_interval – time between successive probes, once the initial wait time is over
  • tcp_keepalive_count – number of probes to send before the connection is killed
oslo.utils.netutils.urlsplit(url, scheme='', allow_fragments=True)

Parse a URL using urlparse.urlsplit(), splitting query and fragments. This function papers over Python issue9374 when needed.

The parameters are the same as urlparse.urlsplit.

Previous topic

importutils

Next topic

strutils

This Page