MCPcopy Create free account
hub / github.com/saltstack/salt / ip_bracket

Function ip_bracket

salt/utils/network.py:2371–2380  ·  view source on GitHub ↗

Ensure IP addresses are URI-compatible - specifically, add brackets around IPv6 literals if they are not already present.

(addr, strip=False)

Source from the content-addressed store, hash-verified

2369
2370
2371def ip_bracket(addr, strip=False):
2372 """
2373 Ensure IP addresses are URI-compatible - specifically, add brackets
2374 around IPv6 literals if they are not already present.
2375 """
2376 addr = str(addr)
2377 addr = addr.lstrip("[")
2378 addr = addr.rstrip("]")
2379 addr = ipaddress.ip_address(addr)
2380 return ("[{}]" if addr.version == 6 and not strip else "{}").format(addr)

Callers 8

_get_master_uriFunction · 0.90
_get_bind_addrFunction · 0.90
getstreamMethod · 0.90
getstreamMethod · 0.90
getstreamMethod · 0.90
prepareMethod · 0.90
dns_checkFunction · 0.70
ipwrapFunction · 0.70

Calls 1

formatMethod · 0.80

Tested by

no test coverage detected