diff options
author | Joffrey F <joffrey@docker.com> | 2015-09-10 17:22:57 -0700 |
---|---|---|
committer | Joffrey F <joffrey@docker.com> | 2015-09-15 20:01:55 +0200 |
commit | 46eb23b4f3fb0bf03a06b64e2872703659b0c006 (patch) | |
tree | 8a9454d2265cd22185ff0c6934fa722c76a7e307 | |
parent | bd6a79fe46da971d46a7722d4b07cbea7aee4cb5 (diff) | |
download | docker-py-46eb23b4f3fb0bf03a06b64e2872703659b0c006.tar.gz |
Basic volume API implementation.
Signed-off-by: Joffrey F <joffrey@docker.com>
-rw-r--r-- | docker/api/__init__.py | 1 | ||||
-rw-r--r-- | docker/api/volume.py | 48 | ||||
-rw-r--r-- | docker/client.py | 3 |
3 files changed, 51 insertions, 1 deletions
diff --git a/docker/api/__init__.py b/docker/api/__init__.py index 836f07e..3fb8120 100644 --- a/docker/api/__init__.py +++ b/docker/api/__init__.py @@ -4,3 +4,4 @@ from .container import ContainerApiMixin from .daemon import DaemonApiMixin from .exec_api import ExecApiMixin from .image import ImageApiMixin +from .volume import VolumeApiMixin
\ No newline at end of file diff --git a/docker/api/volume.py b/docker/api/volume.py new file mode 100644 index 0000000..4e005b8 --- /dev/null +++ b/docker/api/volume.py @@ -0,0 +1,48 @@ +import functools + +from .. import errors +from ..utils import utils + + +def check_api_version(f): + @functools.wraps(f) + def wrapped(self, *args, **kwargs): + if utils.compare_version('1.21', self._version) < 0: + raise errors.InvalidVersion( + 'The volume API is not available for API version < 1.21' + ) + return f(self, *args, **kwargs) + return wrapped + + +class VolumeApiMixin(object): + @check_api_version + def volumes(self, filters=None): + params = { + 'filter': utils.convert_filters(filters) if filters else None + } + url = self._url('/volumes') + return self._result(self._get(url, params=params), True) + + @check_api_version + def create_volume(self, name, driver=None, driver_opts=None): + url = self._url('/volumes') + if not isinstance(driver_opts, dict): + raise TypeError('driver_opts must be a dictionary') + + data = { + 'Name': name, + 'Driver': driver, + 'DriverOpts': driver_opts, + } + return self._result(self._post(url, data=data), True) + + @check_api_version + def inspect_volume(self, name): + url = self._url('/volumes/{0}', name) + return self._result(self._get(url), True) + + @check_api_version + def remove_volume(self, name): + url = self._url('/volumes/{0}', name) + return self._result(self._delete(url), True) diff --git a/docker/client.py b/docker/client.py index 2eb859c..58d0496 100644 --- a/docker/client.py +++ b/docker/client.py @@ -38,7 +38,8 @@ class Client( api.ContainerApiMixin, api.DaemonApiMixin, api.ExecApiMixin, - api.ImageApiMixin): + api.ImageApiMixin, + api.VolumeApiMixin): def __init__(self, base_url=None, version=None, timeout=constants.DEFAULT_TIMEOUT_SECONDS, tls=False): super(Client, self).__init__() |