Skip to content

Commit 269a15e

Browse files
authored
Merge pull request #1402 from docker/2.0.2-release
2.0.2 release
2 parents 206c184 + ab5a189 commit 269a15e

22 files changed

+291
-145
lines changed

docker/api/client.py

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,20 @@
1818
from .swarm import SwarmApiMixin
1919
from .volume import VolumeApiMixin
2020
from .. import auth
21-
from ..constants import (DEFAULT_TIMEOUT_SECONDS, DEFAULT_USER_AGENT,
22-
IS_WINDOWS_PLATFORM, DEFAULT_DOCKER_API_VERSION,
23-
STREAM_HEADER_SIZE_BYTES, DEFAULT_NUM_POOLS,
24-
MINIMUM_DOCKER_API_VERSION)
25-
from ..errors import (DockerException, TLSParameterError,
26-
create_api_error_from_http_exception)
21+
from ..constants import (
22+
DEFAULT_TIMEOUT_SECONDS, DEFAULT_USER_AGENT, IS_WINDOWS_PLATFORM,
23+
DEFAULT_DOCKER_API_VERSION, STREAM_HEADER_SIZE_BYTES, DEFAULT_NUM_POOLS,
24+
MINIMUM_DOCKER_API_VERSION
25+
)
26+
from ..errors import (
27+
DockerException, TLSParameterError,
28+
create_api_error_from_http_exception
29+
)
2730
from ..tls import TLSConfig
2831
from ..transport import SSLAdapter, UnixAdapter
2932
from ..utils import utils, check_resource, update_headers
3033
from ..utils.socket import frames_iter
34+
from ..utils.json_stream import json_stream
3135
try:
3236
from ..transport import NpipeAdapter
3337
except ImportError:
@@ -274,27 +278,20 @@ def _get_raw_response_socket(self, response):
274278

275279
def _stream_helper(self, response, decode=False):
276280
"""Generator for data coming from a chunked-encoded HTTP response."""
281+
277282
if response.raw._fp.chunked:
278-
reader = response.raw
279-
while not reader.closed:
280-
# this read call will block until we get a chunk
281-
data = reader.read(1)
282-
if not data:
283-
break
284-
if reader._fp.chunk_left:
285-
data += reader.read(reader._fp.chunk_left)
286-
if decode:
287-
if six.PY3:
288-
data = data.decode('utf-8')
289-
# remove the trailing newline
290-
data = data.strip()
291-
# split the data at any newlines
292-
data_list = data.split("\r\n")
293-
# load and yield each line seperately
294-
for data in data_list:
295-
data = json.loads(data)
296-
yield data
297-
else:
283+
if decode:
284+
for chunk in json_stream(self._stream_helper(response, False)):
285+
yield chunk
286+
else:
287+
reader = response.raw
288+
while not reader.closed:
289+
# this read call will block until we get a chunk
290+
data = reader.read(1)
291+
if not data:
292+
break
293+
if reader._fp.chunk_left:
294+
data += reader.read(reader._fp.chunk_left)
298295
yield data
299296
else:
300297
# Response isn't chunked, meaning we probably

docker/api/container.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,13 @@ def create_container(self, image, command=None, hostname=None, user=None,
388388
environment (dict or list): A dictionary or a list of strings in
389389
the following format ``["PASSWORD=xxx"]`` or
390390
``{"PASSWORD": "xxx"}``.
391-
dns (list): DNS name servers. Deprecated since API version 1.10.
392-
Use ``host_config`` instead.
393-
dns_opt (list): Additional options to be added to the container's
394-
``resolv.conf`` file
391+
dns (:py:class:`list`): DNS name servers. Deprecated since API
392+
version 1.10. Use ``host_config`` instead.
393+
dns_opt (:py:class:`list`): Additional options to be added to the
394+
container's ``resolv.conf`` file
395395
volumes (str or list):
396-
volumes_from (list): List of container names or Ids to get
397-
volumes from.
396+
volumes_from (:py:class:`list`): List of container names or Ids to
397+
get volumes from.
398398
network_disabled (bool): Disable networking
399399
name (str): A name for the container
400400
entrypoint (str or list): An entrypoint
@@ -478,19 +478,19 @@ def create_host_config(self, *args, **kwargs):
478478
device_write_bps: Limit write rate (bytes per second) from a
479479
device.
480480
device_write_iops: Limit write rate (IO per second) from a device.
481-
devices (list): Expose host devices to the container, as a list
482-
of strings in the form
481+
devices (:py:class:`list`): Expose host devices to the container,
482+
as a list of strings in the form
483483
``<path_on_host>:<path_in_container>:<cgroup_permissions>``.
484484
485485
For example, ``/dev/sda:/dev/xvda:rwm`` allows the container
486486
to have read-write access to the host's ``/dev/sda`` via a
487487
node named ``/dev/xvda`` inside the container.
488-
dns (list): Set custom DNS servers.
489-
dns_search (list): DNS search domains.
488+
dns (:py:class:`list`): Set custom DNS servers.
489+
dns_search (:py:class:`list`): DNS search domains.
490490
extra_hosts (dict): Addtional hostnames to resolve inside the
491491
container, as a mapping of hostname to IP address.
492-
group_add (list): List of additional group names and/or IDs that
493-
the container process will run as.
492+
group_add (:py:class:`list`): List of additional group names and/or
493+
IDs that the container process will run as.
494494
ipc_mode (str): Set the IPC mode for the container.
495495
isolation (str): Isolation technology to use. Default: `None`.
496496
links (dict or list of tuples): Either a dictionary mapping name
@@ -539,8 +539,8 @@ def create_host_config(self, *args, **kwargs):
539539
- ``Name`` One of ``on-failure``, or ``always``.
540540
- ``MaximumRetryCount`` Number of times to restart the
541541
container on failure.
542-
security_opt (list): A list of string values to customize labels
543-
for MLS systems, such as SELinux.
542+
security_opt (:py:class:`list`): A list of string values to
543+
customize labels for MLS systems, such as SELinux.
544544
shm_size (str or int): Size of /dev/shm (e.g. ``1G``).
545545
sysctls (dict): Kernel parameters to set in the container.
546546
tmpfs (dict): Temporary filesystems to mount, as a dictionary
@@ -555,13 +555,13 @@ def create_host_config(self, *args, **kwargs):
555555
'/mnt/vol1': 'size=3G,uid=1000'
556556
}
557557
558-
ulimits (list): Ulimits to set inside the container, as a list of
559-
dicts.
558+
ulimits (:py:class:`list`): Ulimits to set inside the container,
559+
as a list of dicts.
560560
userns_mode (str): Sets the user namespace mode for the container
561561
when user namespace remapping option is enabled. Supported
562562
values are: ``host``
563-
volumes_from (list): List of container names or IDs to get
564-
volumes from.
563+
volumes_from (:py:class:`list`): List of container names or IDs to
564+
get volumes from.
565565
566566
567567
Returns:
@@ -618,17 +618,17 @@ def create_endpoint_config(self, *args, **kwargs):
618618
:py:meth:`create_networking_config`.
619619
620620
Args:
621-
aliases (list): A list of aliases for this endpoint. Names in
622-
that list can be used within the network to reach the
621+
aliases (:py:class:`list`): A list of aliases for this endpoint.
622+
Names in that list can be used within the network to reach the
623+
container. Defaults to ``None``.
624+
links (:py:class:`list`): A list of links for this endpoint.
625+
Containers declared in this list will be linked to this
623626
container. Defaults to ``None``.
624-
links (list): A list of links for this endpoint. Containers
625-
declared in this list will be linked to this container.
626-
Defaults to ``None``.
627627
ipv4_address (str): The IP address of this container on the
628628
network, using the IPv4 protocol. Defaults to ``None``.
629629
ipv6_address (str): The IP address of this container on the
630630
network, using the IPv6 protocol. Defaults to ``None``.
631-
link_local_ips (list): A list of link-local (IPv4/IPv6)
631+
link_local_ips (:py:class:`list`): A list of link-local (IPv4/IPv6)
632632
addresses.
633633
634634
Returns:

docker/api/network.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
import json
2-
31
from ..errors import InvalidVersion
42
from ..utils import check_resource, minimum_version
53
from ..utils import version_lt
4+
from .. import utils
65

76

87
class NetworkApiMixin(object):
98
@minimum_version('1.21')
10-
def networks(self, names=None, ids=None):
9+
def networks(self, names=None, ids=None, filters=None):
1110
"""
1211
List networks. Similar to the ``docker networks ls`` command.
1312
1413
Args:
15-
names (list): List of names to filter by
16-
ids (list): List of ids to filter by
14+
names (:py:class:`list`): List of names to filter by
15+
ids (:py:class:`list`): List of ids to filter by
16+
filters (dict): Filters to be processed on the network list.
17+
Available filters:
18+
- ``driver=[<driver-name>]`` Matches a network's driver.
19+
- ``label=[<key>]`` or ``label=[<key>=<value>]``.
20+
- ``type=["custom"|"builtin"]`` Filters networks by type.
1721
1822
Returns:
1923
(dict): List of network objects.
@@ -23,14 +27,13 @@ def networks(self, names=None, ids=None):
2327
If the server returns an error.
2428
"""
2529

26-
filters = {}
30+
if filters is None:
31+
filters = {}
2732
if names:
2833
filters['name'] = names
2934
if ids:
3035
filters['id'] = ids
31-
32-
params = {'filters': json.dumps(filters)}
33-
36+
params = {'filters': utils.convert_filters(filters)}
3437
url = self._url("/networks")
3538
res = self._get(url, params=params)
3639
return self._result(res, json=True)
@@ -166,17 +169,18 @@ def connect_container_to_network(self, container, net_id,
166169
Args:
167170
container (str): container-id/name to be connected to the network
168171
net_id (str): network id
169-
aliases (list): A list of aliases for this endpoint. Names in that
170-
list can be used within the network to reach the container.
171-
Defaults to ``None``.
172-
links (list): A list of links for this endpoint. Containers
173-
declared in this list will be linkedto this container.
174-
Defaults to ``None``.
172+
aliases (:py:class:`list`): A list of aliases for this endpoint.
173+
Names in that list can be used within the network to reach the
174+
container. Defaults to ``None``.
175+
links (:py:class:`list`): A list of links for this endpoint.
176+
Containers declared in this list will be linked to this
177+
container. Defaults to ``None``.
175178
ipv4_address (str): The IP address of this container on the
176179
network, using the IPv4 protocol. Defaults to ``None``.
177180
ipv6_address (str): The IP address of this container on the
178181
network, using the IPv6 protocol. Defaults to ``None``.
179-
link_local_ips (list): A list of link-local (IPv4/IPv6) addresses.
182+
link_local_ips (:py:class:`list`): A list of link-local
183+
(IPv4/IPv6) addresses.
180184
"""
181185
data = {
182186
"Container": container,

docker/api/service.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import warnings
22
from .. import auth, errors, utils
3+
from ..types import ServiceMode
34

45

56
class ServiceApiMixin(object):
@@ -13,18 +14,18 @@ def create_service(
1314
Create a service.
1415
1516
Args:
16-
task_template (dict): Specification of the task to start as part
17-
of the new service.
17+
task_template (TaskTemplate): Specification of the task to start as
18+
part of the new service.
1819
name (string): User-defined name for the service. Optional.
1920
labels (dict): A map of labels to associate with the service.
2021
Optional.
21-
mode (string): Scheduling mode for the service (``replicated`` or
22-
``global``). Defaults to ``replicated``.
23-
update_config (dict): Specification for the update strategy of the
24-
service. Default: ``None``
25-
networks (list): List of network names or IDs to attach the
26-
service to. Default: ``None``.
27-
endpoint_config (dict): Properties that can be configured to
22+
mode (ServiceMode): Scheduling mode for the service (replicated
23+
or global). Defaults to replicated.
24+
update_config (UpdateConfig): Specification for the update strategy
25+
of the service. Default: ``None``
26+
networks (:py:class:`list`): List of network names or IDs to attach
27+
the service to. Default: ``None``.
28+
endpoint_spec (EndpointSpec): Properties that can be configured to
2829
access and load balance a service. Default: ``None``.
2930
3031
Returns:
@@ -49,6 +50,9 @@ def create_service(
4950
raise errors.DockerException(
5051
'Missing mandatory Image key in ContainerSpec'
5152
)
53+
if mode and not isinstance(mode, dict):
54+
mode = ServiceMode(mode)
55+
5256
registry, repo_name = auth.resolve_repository_name(image)
5357
auth_header = auth.get_config_header(self, registry)
5458
if auth_header:
@@ -159,7 +163,7 @@ def tasks(self, filters=None):
159163
``label`` and ``desired-state``.
160164
161165
Returns:
162-
(list): List of task dictionaries.
166+
(:py:class:`list`): List of task dictionaries.
163167
164168
Raises:
165169
:py:class:`docker.errors.APIError`
@@ -186,20 +190,18 @@ def update_service(self, service, version, task_template=None, name=None,
186190
ID).
187191
version (int): The version number of the service object being
188192
updated. This is required to avoid conflicting writes.
189-
task_template (dict): Specification of the updated task to start
190-
as part of the service. See the [TaskTemplate
191-
class](#TaskTemplate) for details.
193+
task_template (TaskTemplate): Specification of the updated task to
194+
start as part of the service.
192195
name (string): New name for the service. Optional.
193196
labels (dict): A map of labels to associate with the service.
194197
Optional.
195-
mode (string): Scheduling mode for the service (``replicated`` or
196-
``global``). Defaults to ``replicated``.
197-
update_config (dict): Specification for the update strategy of the
198-
service. See the [UpdateConfig class](#UpdateConfig) for
199-
details. Default: ``None``.
200-
networks (list): List of network names or IDs to attach the
201-
service to. Default: ``None``.
202-
endpoint_config (dict): Properties that can be configured to
198+
mode (ServiceMode): Scheduling mode for the service (replicated
199+
or global). Defaults to replicated.
200+
update_config (UpdateConfig): Specification for the update strategy
201+
of the service. Default: ``None``.
202+
networks (:py:class:`list`): List of network names or IDs to attach
203+
the service to. Default: ``None``.
204+
endpoint_spec (EndpointSpec): Properties that can be configured to
203205
access and load balance a service. Default: ``None``.
204206
205207
Returns:
@@ -224,6 +226,8 @@ def update_service(self, service, version, task_template=None, name=None,
224226
if labels is not None:
225227
data['Labels'] = labels
226228
if mode is not None:
229+
if not isinstance(mode, dict):
230+
mode = ServiceMode(mode)
227231
data['Mode'] = mode
228232
if task_template is not None:
229233
image = task_template.get('ContainerSpec', {}).get('Image', None)

docker/api/swarm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ def join_swarm(self, remote_addrs, join_token, listen_addr=None,
143143
Make this Engine join a swarm that has already been created.
144144
145145
Args:
146-
remote_addrs (list): Addresses of one or more manager nodes already
147-
participating in the Swarm to join.
146+
remote_addrs (:py:class:`list`): Addresses of one or more manager
147+
nodes already participating in the Swarm to join.
148148
join_token (string): Secret token for joining this Swarm.
149149
listen_addr (string): Listen address used for inter-manager
150150
communication if the node gets promoted to manager, as well as

0 commit comments

Comments
 (0)