mirror of https://github.com/docker/docker-py.git
Merge pull request #153 from bfirsh/links-as-tuples
Allow links to specified as (name, alias) tuples
This commit is contained in:
commit
7f826e7e93
|
@ -206,6 +206,11 @@ container ports to the host. See "Port bindings" below for more
|
|||
information. `lxc_conf` allows to pass LXC configuration options using a
|
||||
dictionary. `privileged` starts the container in privileged mode.
|
||||
|
||||
[Links](http://docs.docker.io/en/latest/use/working_with_links_names/)
|
||||
can be specified with the `links` argument. They can either be
|
||||
specified as a dictionary mapping name to alias or as a list of
|
||||
`(name, alias)` tuples.
|
||||
|
||||
```python
|
||||
c.stop(container, timeout=10)
|
||||
```
|
||||
|
|
|
@ -705,8 +705,11 @@ class Client(requests.Session):
|
|||
start_config['PublishAllPorts'] = publish_all_ports
|
||||
|
||||
if links:
|
||||
if isinstance(links, dict):
|
||||
links = six.iteritems(links)
|
||||
|
||||
formatted_links = [
|
||||
'{0}:{1}'.format(k, v) for k, v in sorted(six.iteritems(links))
|
||||
'{0}:{1}'.format(k, v) for k, v in sorted(links)
|
||||
]
|
||||
|
||||
start_config['Links'] = formatted_links
|
||||
|
|
|
@ -525,6 +525,31 @@ class DockerClientTest(unittest.TestCase):
|
|||
{'Content-Type': 'application/json'}
|
||||
)
|
||||
|
||||
def test_start_container_with_links_as_list_of_tuples(self):
|
||||
# one link
|
||||
try:
|
||||
link_path = 'path'
|
||||
alias = 'alias'
|
||||
self.client.start(fake_api.FAKE_CONTAINER_ID,
|
||||
links=[(link_path, alias)])
|
||||
except Exception as e:
|
||||
self.fail('Command should not raise exception: {0}'.format(e))
|
||||
|
||||
args = fake_request.call_args
|
||||
self.assertEqual(
|
||||
args[0][0],
|
||||
'unix://var/run/docker.sock/v1.6/containers/3cc2351ab11b/start'
|
||||
)
|
||||
self.assertEqual(
|
||||
json.loads(args[1]['data']),
|
||||
{"PublishAllPorts": False, "Privileged": False,
|
||||
"Links": ["path:alias"]}
|
||||
)
|
||||
self.assertEqual(
|
||||
args[1]['headers'],
|
||||
{'Content-Type': 'application/json'}
|
||||
)
|
||||
|
||||
def test_start_container_privileged(self):
|
||||
try:
|
||||
self.client.start(fake_api.FAKE_CONTAINER_ID, privileged=True)
|
||||
|
|
Loading…
Reference in New Issue