summaryrefslogtreecommitdiff
path: root/docker/api
diff options
context:
space:
mode:
authorOndřej Nový <onovy@debian.org>2016-09-08 14:22:11 +0200
committerOndřej Nový <onovy@debian.org>2016-09-08 14:22:11 +0200
commit49556cb01423a89a6d2ce7a58b1f5cb64dde0ff3 (patch)
tree72b2266d0cfa008857d957de8c12a646d8c9e96e /docker/api
parent63875477fa2e0a529fcf52e36a3f9cb3db861000 (diff)
Import python-docker_1.9.0.orig.tar.gz
Diffstat (limited to 'docker/api')
-rw-r--r--docker/api/build.py11
-rw-r--r--docker/api/container.py46
-rw-r--r--docker/api/daemon.py4
-rw-r--r--docker/api/image.py8
-rw-r--r--docker/api/network.py25
5 files changed, 75 insertions, 19 deletions
diff --git a/docker/api/build.py b/docker/api/build.py
index 6bfaba1..971a50e 100644
--- a/docker/api/build.py
+++ b/docker/api/build.py
@@ -17,11 +17,15 @@ class BuildApiMixin(object):
nocache=False, rm=False, stream=False, timeout=None,
custom_context=False, encoding=None, pull=False,
forcerm=False, dockerfile=None, container_limits=None,
- decode=False, buildargs=None):
+ decode=False, buildargs=None, gzip=False):
remote = context = headers = None
container_limits = container_limits or {}
if path is None and fileobj is None:
raise TypeError("Either path or fileobj needs to be provided.")
+ if gzip and encoding is not None:
+ raise errors.DockerException(
+ 'Can not use custom encoding if gzip is enabled'
+ )
for key in container_limits.keys():
if key not in constants.CONTAINER_LIMITS_KEYS:
@@ -46,7 +50,10 @@ class BuildApiMixin(object):
if os.path.exists(dockerignore):
with open(dockerignore, 'r') as f:
exclude = list(filter(bool, f.read().splitlines()))
- context = utils.tar(path, exclude=exclude, dockerfile=dockerfile)
+ context = utils.tar(
+ path, exclude=exclude, dockerfile=dockerfile, gzip=gzip
+ )
+ encoding = 'gzip' if gzip else encoding
if utils.compare_version('1.8', self._version) >= 0:
stream = True
diff --git a/docker/api/container.py b/docker/api/container.py
index ceac173..9cc14db 100644
--- a/docker/api/container.py
+++ b/docker/api/container.py
@@ -40,13 +40,14 @@ class ContainerApiMixin(object):
@utils.check_resource
def commit(self, container, repository=None, tag=None, message=None,
- author=None, conf=None):
+ author=None, changes=None, conf=None):
params = {
'container': container,
'repo': repository,
'tag': tag,
'comment': message,
- 'author': author
+ 'author': author,
+ 'changes': changes
}
u = self._url("/commit")
return self._result(self._post_json(u, data=conf, params=params),
@@ -186,6 +187,8 @@ class ContainerApiMixin(object):
url = self._url("/containers/{0}/kill", container)
params = {}
if signal is not None:
+ if not isinstance(signal, six.string_types):
+ signal = int(signal)
params['signal'] = signal
res = self._post(url, params=params)
@@ -193,12 +196,14 @@ class ContainerApiMixin(object):
@utils.check_resource
def logs(self, container, stdout=True, stderr=True, stream=False,
- timestamps=False, tail='all', since=None):
+ timestamps=False, tail='all', since=None, follow=None):
if utils.compare_version('1.11', self._version) >= 0:
+ if follow is None:
+ follow = stream
params = {'stderr': stderr and 1 or 0,
'stdout': stdout and 1 or 0,
'timestamps': timestamps and 1 or 0,
- 'follow': stream and 1 or 0,
+ 'follow': follow and 1 or 0,
}
if utils.compare_version('1.13', self._version) >= 0:
if tail != 'all' and (not isinstance(tail, int) or tail < 0):
@@ -396,6 +401,39 @@ class ContainerApiMixin(object):
res = self._post(url)
self._raise_for_status(res)
+ @utils.minimum_version('1.22')
+ @utils.check_resource
+ def update_container(
+ self, container, blkio_weight=None, cpu_period=None, cpu_quota=None,
+ cpu_shares=None, cpuset_cpus=None, cpuset_mems=None, mem_limit=None,
+ mem_reservation=None, memswap_limit=None, kernel_memory=None
+ ):
+ url = self._url('/containers/{0}/update', container)
+ data = {}
+ if blkio_weight:
+ data['BlkioWeight'] = blkio_weight
+ if cpu_period:
+ data['CpuPeriod'] = cpu_period
+ if cpu_shares:
+ data['CpuShares'] = cpu_shares
+ if cpu_quota:
+ data['CpuQuota'] = cpu_quota
+ if cpuset_cpus:
+ data['CpusetCpus'] = cpuset_cpus
+ if cpuset_mems:
+ data['CpusetMems'] = cpuset_mems
+ if mem_limit:
+ data['Memory'] = utils.parse_bytes(mem_limit)
+ if mem_reservation:
+ data['MemoryReservation'] = utils.parse_bytes(mem_reservation)
+ if memswap_limit:
+ data['MemorySwap'] = utils.parse_bytes(memswap_limit)
+ if kernel_memory:
+ data['KernelMemory'] = utils.parse_bytes(kernel_memory)
+
+ res = self._post_json(url, data=data)
+ return self._result(res, True)
+
@utils.check_resource
def wait(self, container, timeout=None):
url = self._url("/containers/{0}/wait", container)
diff --git a/docker/api/daemon.py b/docker/api/daemon.py
index a149e5e..9ebe73c 100644
--- a/docker/api/daemon.py
+++ b/docker/api/daemon.py
@@ -49,8 +49,6 @@ class DaemonApiMixin(object):
elif not self._auth_configs:
self._auth_configs = auth.load_config()
- registry = registry or auth.INDEX_URL
-
authcfg = auth.resolve_authconfig(self._auth_configs, registry)
# If we found an existing auth config for this registry and username
# combination, we can return it immediately unless reauth is requested.
@@ -67,7 +65,7 @@ class DaemonApiMixin(object):
response = self._post_json(self._url('/auth'), data=req_data)
if response.status_code == 200:
- self._auth_configs[registry] = req_data
+ self._auth_configs[registry or auth.INDEX_NAME] = req_data
return self._result(response, json=True)
def ping(self):
diff --git a/docker/api/image.py b/docker/api/image.py
index 8493b38..3e66347 100644
--- a/docker/api/image.py
+++ b/docker/api/image.py
@@ -148,7 +148,7 @@ class ImageApiMixin(object):
self._raise_for_status(res)
def pull(self, repository, tag=None, stream=False,
- insecure_registry=False, auth_config=None):
+ insecure_registry=False, auth_config=None, decode=False):
if insecure_registry:
warnings.warn(
INSECURE_REGISTRY_DEPRECATION_WARNING.format('pull()'),
@@ -200,12 +200,12 @@ class ImageApiMixin(object):
self._raise_for_status(response)
if stream:
- return self._stream_helper(response)
+ return self._stream_helper(response, decode=decode)
return self._result(response)
def push(self, repository, tag=None, stream=False,
- insecure_registry=False):
+ insecure_registry=False, decode=False):
if insecure_registry:
warnings.warn(
INSECURE_REGISTRY_DEPRECATION_WARNING.format('push()'),
@@ -241,7 +241,7 @@ class ImageApiMixin(object):
self._raise_for_status(response)
if stream:
- return self._stream_helper(response)
+ return self._stream_helper(response, decode=decode)
return self._result(response)
diff --git a/docker/api/network.py b/docker/api/network.py
index d9a6128..a35f0a4 100644
--- a/docker/api/network.py
+++ b/docker/api/network.py
@@ -1,6 +1,8 @@
import json
-from ..utils import check_resource, minimum_version, normalize_links
+from ..errors import InvalidVersion
+from ..utils import check_resource, minimum_version
+from ..utils import version_lt
class NetworkApiMixin(object):
@@ -19,7 +21,8 @@ class NetworkApiMixin(object):
return self._result(res, json=True)
@minimum_version('1.21')
- def create_network(self, name, driver=None, options=None, ipam=None):
+ def create_network(self, name, driver=None, options=None, ipam=None,
+ check_duplicate=None, internal=False):
if options is not None and not isinstance(options, dict):
raise TypeError('options must be a dictionary')
@@ -28,7 +31,15 @@ class NetworkApiMixin(object):
'Driver': driver,
'Options': options,
'IPAM': ipam,
+ 'CheckDuplicate': check_duplicate
}
+
+ if internal:
+ if version_lt(self._version, '1.22'):
+ raise InvalidVersion('Internal networks are not '
+ 'supported in API version < 1.22')
+ data['Internal'] = True
+
url = self._url("/networks/create")
res = self._post_json(url, data=data)
return self._result(res, json=True)
@@ -48,14 +59,16 @@ class NetworkApiMixin(object):
@check_resource
@minimum_version('1.21')
def connect_container_to_network(self, container, net_id,
+ ipv4_address=None, ipv6_address=None,
aliases=None, links=None):
data = {
"Container": container,
- "EndpointConfig": {
- "Aliases": aliases,
- "Links": normalize_links(links) if links else None,
- },
+ "EndpointConfig": self.create_endpoint_config(
+ aliases=aliases, links=links, ipv4_address=ipv4_address,
+ ipv6_address=ipv6_address
+ ),
}
+
url = self._url("/networks/{0}/connect", net_id)
res = self._post_json(url, data=data)
self._raise_for_status(res)