IPV6 interface binding

This commit is contained in:
Chibisov Gennady 2017-02-09 14:59:45 +03:00
parent 60952b34bf
commit 4ce0d43223
2 changed files with 19 additions and 0 deletions

View File

@ -185,6 +185,7 @@ def build_endpoint_description_strings(
"""
socket_descriptions = []
if host and port:
host = host.strip('[]').replace(':', '\:')
socket_descriptions.append('tcp:port=%d:interface=%s' % (int(port), host))
elif any([host, port]):
raise ValueError('TCP binding requires both port and host kwargs.')

View File

@ -28,6 +28,16 @@ class TestEndpointDescriptions(TestCase):
['tcp:port=8000:interface=127.0.0.1']
)
self.assertEqual(
build(port=8000, host='[200a::1]'),
['tcp:port=8000:interface=200a\:\:1']
)
self.assertEqual(
build(port=8000, host='200a::1'),
['tcp:port=8000:interface=200a\:\:1']
)
# incomplete port/host kwargs raise errors
self.assertRaises(
ValueError,
@ -123,6 +133,14 @@ class TestCLIInterface(TestCase):
'-b 10.0.0.1',
['tcp:port=8000:interface=10.0.0.1']
)
self.checkCLI(
'-b 200a::1',
['tcp:port=8000:interface=200a\:\:1']
)
self.checkCLI(
'-b [200a::1]',
['tcp:port=8000:interface=200a\:\:1']
)
self.checkCLI(
'-p 8080 -b example.com',
['tcp:port=8080:interface=example.com']