Merge pull request #153 from bfirsh/links-as-tuples

Allow links to specified as (name, alias) tuples
This commit is contained in:
Joffrey F 2014-01-27 09:42:23 -08:00
commit 7f826e7e93
3 changed files with 34 additions and 1 deletions

View File

@ -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)
```

View File

@ -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

View File

@ -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)