Merge pull request #200 from ticosax/move-dns-and-volumes-from

From api 1.10 dns and volumes_from should be passed to start()
This commit is contained in:
Joffrey F 2014-04-28 20:49:45 +02:00
commit 3ff1f1ed4b
2 changed files with 40 additions and 2 deletions

View File

@ -71,6 +71,11 @@ to those for the `docker run` command except it doesn't support the
attach options (`-a`). See "Port bindings" and "Using volumes" below for
more information on how to create port bindings and volume mappings.
`volumes_from` and `dns` arguments raise TypeError exception if they are used
against v1.10 of docker remote API. Those arguments should be passed to
`start()` instead.
```python
c.diff(container)
```
@ -201,7 +206,8 @@ Identical to the `docker search` command.
```python
c.start(container, binds=None, port_bindings=None, lxc_conf=None,
publish_all_ports=False, links=None, privileged=False)
publish_all_ports=False, links=None, privileged=False,
dns=None, volumes_from=None)
```
Similar to the `docker start` command, but doesn't support attach
@ -218,6 +224,9 @@ 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.
`dns` and `volumes_from` are only available if they are used with version v1.10
of docker remote API. Otherwise they are ignored.
```python
c.stop(container, timeout=10)
```

View File

@ -16,6 +16,7 @@ import json
import re
import shlex
import struct
import warnings
import requests
import requests.exceptions
@ -141,6 +142,14 @@ class Client(requests.Session):
attach_stdin = True
stdin_once = True
if utils.compare_version('1.10', self._version) >= 0:
message = ('{0!r} parameter has no effect on create_container().'
' It has been moved to start()')
if dns is not None:
raise errors.DockerException(message.format('dns'))
if volumes_from is not None:
raise errors.DockerException(message.format('volumes_from'))
return {
'Hostname': hostname,
'Domainname': domainname,
@ -669,7 +678,8 @@ class Client(requests.Session):
True)
def start(self, container, binds=None, port_bindings=None, lxc_conf=None,
publish_all_ports=False, links=None, privileged=False):
publish_all_ports=False, links=None, privileged=False,
dns=None, volumes_from=None):
if isinstance(container, dict):
container = container.get('Id')
@ -711,6 +721,25 @@ class Client(requests.Session):
start_config['Privileged'] = privileged
if utils.compare_version('1.10', self._version) >= 0:
if dns is not None:
start_config['Dns'] = dns
if volumes_from is not None:
if isinstance(volumes_from, six.string_types):
volumes_from = volumes_from.split(',')
start_config['VolumesFrom'] = volumes_from
else:
warning_message = ('{0!r} parameter is discarded. It is only'
' available for API version greater or equal'
' than 1.10')
if dns is not None:
warnings.warn(warning_message.format('dns'),
DeprecationWarning)
if volumes_from is not None:
warnings.warn(warning_message.format('volumes_from'),
DeprecationWarning)
url = self._url("/containers/{0}/start".format(container))
res = self._post_json(url, data=start_config)
self._raise_for_status(res)