summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docker/api/__init__.py1
-rw-r--r--docker/api/volume.py48
-rw-r--r--docker/client.py3
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__()