Support the new PublishAllPorts flag.

This commit is contained in:
Jessica Gadling 2013-11-08 21:06:43 +00:00
parent 1345da7972
commit 70a5c9b0ca
2 changed files with 12 additions and 6 deletions

View File

@ -470,7 +470,8 @@ class Client(requests.Session):
return self._result(self.get(self._url("/images/search"),
params={'term': term}), True)
def start(self, container, binds=None, port_bindings=None, lxc_conf=None):
def start(self, container, binds=None, port_bindings=None, lxc_conf=None,
publish_all_ports=False):
if isinstance(container, dict):
container = container.get('Id')
@ -492,6 +493,8 @@ class Client(requests.Session):
if port_bindings:
start_config['PortBindings'] = port_bindings
start_config['PublishAllPorts'] = publish_all_ports
url = self._url("/containers/{0}/start".format(container))
res = self._post_json(url, start_config)
self._raise_for_status(res)

View File

@ -231,7 +231,7 @@ class DockerClientTest(unittest.TestCase):
fake_request.assert_called_with(
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/start',
'{}',
'{"PublishAllPorts": false}',
headers={'Content-Type': 'application/json'}
)
@ -248,7 +248,8 @@ class DockerClientTest(unittest.TestCase):
'containers/3cc2351ab11b/start')
self.assertEqual(
json.loads(args[0][1]),
{"LxcConf": [{"Value": "lxc.conf.value", "Key": "lxc.conf.k"}]}
{"LxcConf": [{"Value": "lxc.conf.value", "Key": "lxc.conf.k"}],
"PublishAllPorts": False}
)
self.assertEqual(args[1]['headers'],
{'Content-Type': 'application/json'})
@ -266,7 +267,8 @@ class DockerClientTest(unittest.TestCase):
'containers/3cc2351ab11b/start')
self.assertEqual(
json.loads(args[0][1]),
{"LxcConf": [{"Value": "lxc.conf.value", "Key": "lxc.conf.k"}]}
{"LxcConf": [{"Value": "lxc.conf.value", "Key": "lxc.conf.k"}],
"PublishAllPorts": False}
)
self.assertEqual(args[1]['headers'],
{'Content-Type': 'application/json'})
@ -282,7 +284,7 @@ class DockerClientTest(unittest.TestCase):
fake_request.assert_called_with(
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/start',
'{"Binds": ["/tmp:/mnt"]}',
'{"Binds": ["/tmp:/mnt"], "PublishAllPorts": false}',
headers={'Content-Type': 'application/json'}
)
@ -293,7 +295,8 @@ class DockerClientTest(unittest.TestCase):
self.fail('Command should not raise exception: {0}'.format(e))
fake_request.assert_called_with(
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/start',
'{}', headers={'Content-Type': 'application/json'}
'{"PublishAllPorts": false}',
headers={'Content-Type': 'application/json'}
)
def test_wait(self):