Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
f4a4982
Shift test matrix forward
shin- Jun 22, 2017
f611eaf
dev version
shin- Jun 28, 2017
e134438
Merge pull request #1667 from docker/bump-2.5.0-dev
shin- Jun 28, 2017
a8722fb
split_port should not break when passed a non-string argument
shin- Jun 28, 2017
9d09a13
Merge pull request #1669 from shin-/1668-split-port
shin- Jun 28, 2017
48957e7
Compose 1.14.0 hack
shin- Jun 28, 2017
03b78b8
Merge pull request #1671 from shin-/1668-split-port-2
shin- Jun 28, 2017
6fe1c7f
Merge pull request #1664 from docker/jfile-17.06-rc
shin- Jul 3, 2017
c9960c7
Fix #1673 check resource error in container network API
matthewtberry Jul 14, 2017
d68996f
By not specifying a specific tag, the example would download every Ub…
usbrandon Jul 18, 2017
c2925a3
client.networks.create check_duplicates docs not reflective of behavior
dimaspivak Jul 31, 2017
d798afc
Generating regexp from .dockerignore file in a similar way as docker-ce.
Jul 3, 2017
bcfd6da
Temporarily - do not run py33 tests on travis
shin- Aug 1, 2017
8a6b168
Fix domainname documentation in create_container function
terminalmage Aug 7, 2017
1a923c5
Added wait to the Container class documentation.
AndreasBackx Aug 6, 2017
b8fd821
client.containers.run returns None if none of json-file or journald l…
bolshakov Jul 25, 2017
8bcf2f2
Improve ContainerError message compute
shin- Aug 7, 2017
369168e
Merge branch 'bolshakov-bugfix/run-container-with-syslog-driver'
shin- Aug 7, 2017
56dc7db
Return the result of the API when using remove_image and load_image
cecton Aug 1, 2017
5e4a69b
Return generator for output of load_image endpoint
shin- Jun 16, 2017
92a2e48
Leading slash in .dockerignore should be ignored
shin- Aug 15, 2017
3b95da3
Require "requests[security]" if the `[tls]` option is selected, which…
cyli Apr 14, 2017
c163375
If we're pinning exact versions of things for requirements.txt, pin
cyli May 22, 2017
35f29d0
Upgrade tox and virtualenv in appveyor to make sure we have the lates…
cyli Jun 17, 2017
e9fab14
Daemon expects full URL of hub in auth config dict in build payload
shin- Aug 15, 2017
18acd56
Handle untyped ContainerSpec dict in _check_api_features
shin- Aug 15, 2017
05e5db5
Use collection's get method inside ImageCollection's list method
adrianliaw May 6, 2017
e17a545
Allow detach and remove for api version >= 1.25 and use auto_remove w…
davidsteines Apr 4, 2017
b78fa64
Use better version comparison function
shin- Aug 16, 2017
67b58b8
Merge branch 'davidsteines-1477_detach_and_remove_together'
shin- Aug 16, 2017
fe2e120
Merge branch 'master' of github.com:docker/docker-py
shin- Aug 16, 2017
76eb029
Add support for the `squash` flag when building
gferon Jan 30, 2017
6f6c29c
Merge branch 'gferon-experimental-flags'
shin- Aug 16, 2017
13b9349
Fix handling of non-multiplexed (TTY) streams over upgraded sockets
shin- Aug 17, 2017
c55a330
Merge branch 'release' of github.com:docker/docker-py
shin- Aug 17, 2017
477f236
Bump 2.6.0-dev
shin- Aug 17, 2017
3df0653
Commit d798afca made changes for the handling of '**' patterns in
vmlintu-nosto Aug 18, 2017
8919514
Always send attach request as streaming
shin- Aug 21, 2017
3c9c8b1
Use unambiguous advertise-addr when initializing a swarm
shin- Aug 31, 2017
2671d87
Fix prune_images docstring
shin- Aug 31, 2017
37fbc8b
Do not interrupt streaming when encountering 0-length frames
shin- Aug 31, 2017
be3900b
Fix docs, incorrect param name
Brett55 Sep 13, 2017
ca435af
Adding swarm id_attribute to match docker output
SteggyLeggy Sep 18, 2017
ec9356d
Remove superfluous version validation
shin- Oct 2, 2017
8cb5b52
Fix simple documentation copy/paste error.
janLo Oct 17, 2017
877fc81
Add support for new types and options to docker.types.Mount
shin- Oct 24, 2017
5552dee
Add support for mounts in HostConfig
shin- Oct 24, 2017
0d21b5b
Pin flake8 version
shin- Oct 24, 2017
93f2ab1
Add support for extra_hosts option in build
shin- Oct 25, 2017
378bd76
Update test engine versions in Jenkinsfile
shin- Oct 25, 2017
10ea65f
Fix indentation in docstring
terminalmage Oct 26, 2017
601d6be
Add support for new ContainerSpec parameters
shin- Oct 26, 2017
856414b
Add support for configs management
shin- Oct 26, 2017
bb14838
More ContainerSpec tests
shin- Oct 26, 2017
76b138a
Improve docs for service list filters
baldoalessandro Nov 1, 2017
c0a0758
Add support for secret driver in create_secret
shin- Nov 2, 2017
b99f4f2
Doc fixes
shin- Nov 2, 2017
f8b5bc6
Prevent data loss when attaching to container
cjh1 Oct 5, 2017
1359eb1
Disable buffering based on presence of Connection Upgrade headers
shin- Nov 2, 2017
d5094a8
Fix build tests to not rely on internet connectivity
shin- Nov 2, 2017
ca7a613
Oops
shin- Nov 2, 2017
1ce93ac
Add support for scope filter in inspect_network
shin- Nov 2, 2017
11a2602
Update SwarmSpec to include new parameters
shin- Nov 3, 2017
1a4b181
Add support for insert_defaults in inspect_service
shin- Nov 7, 2017
05f40f0
explain the socket parameter of exec_run
monperrus Oct 2, 2017
f238fe5
Style fixes. Copied docs to APIClient as well
shin- Nov 7, 2017
700fbef
Fix broken unbuffered streaming with Py3
shin- Nov 9, 2017
21d2c65
Merge branch 'release' of github.com:docker/docker-py
shin- Nov 9, 2017
aafae3d
dev version
shin- Nov 9, 2017
2008f52
2.6.1 release
shin- Nov 9, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add support for configs management
Signed-off-by: Joffrey F <[email protected]>
  • Loading branch information
shin- committed Oct 27, 2017
commit 856414bf85fc1cde5c186547807c9633ca14cef4
2 changes: 2 additions & 0 deletions docker/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import websocket

from .build import BuildApiMixin
from .config import ConfigApiMixin
from .container import ContainerApiMixin
from .daemon import DaemonApiMixin
from .exec_api import ExecApiMixin
Expand Down Expand Up @@ -43,6 +44,7 @@
class APIClient(
requests.Session,
BuildApiMixin,
ConfigApiMixin,
ContainerApiMixin,
DaemonApiMixin,
ExecApiMixin,
Expand Down
91 changes: 91 additions & 0 deletions docker/api/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import base64

import six

from .. import utils


class ConfigApiMixin(object):
@utils.minimum_version('1.25')
def create_config(self, name, data, labels=None):
"""
Create a config

Args:
name (string): Name of the config
data (bytes): Config data to be stored
labels (dict): A mapping of labels to assign to the config

Returns (dict): ID of the newly created config
"""
if not isinstance(data, bytes):
data = data.encode('utf-8')

data = base64.b64encode(data)
if six.PY3:
data = data.decode('ascii')
body = {
'Data': data,
'Name': name,
'Labels': labels
}

url = self._url('/configs/create')
return self._result(
self._post_json(url, data=body), True
)

@utils.minimum_version('1.25')
@utils.check_resource('id')
def inspect_config(self, id):
"""
Retrieve config metadata

Args:
id (string): Full ID of the config to remove

Returns (dict): A dictionary of metadata

Raises:
:py:class:`docker.errors.NotFound`
if no config with that ID exists
"""
url = self._url('/configs/{0}', id)
return self._result(self._get(url), True)

@utils.minimum_version('1.25')
@utils.check_resource('id')
def remove_config(self, id):
"""
Remove a config

Args:
id (string): Full ID of the config to remove

Returns (boolean): True if successful

Raises:
:py:class:`docker.errors.NotFound`
if no config with that ID exists
"""
url = self._url('/configs/{0}', id)
res = self._delete(url)
self._raise_for_status(res)
return True

@utils.minimum_version('1.25')
def configs(self, filters=None):
"""
List configs

Args:
filters (dict): A map of filters to process on the configs
list. Available filters: ``names``

Returns (list): A list of configs
"""
url = self._url('/configs')
params = {}
if filters:
params['filters'] = utils.convert_filters(filters)
return self._result(self._get(url, params=params), True)
9 changes: 9 additions & 0 deletions docker/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .api.client import APIClient
from .constants import DEFAULT_TIMEOUT_SECONDS
from .models.configs import ConfigCollection
from .models.containers import ContainerCollection
from .models.images import ImageCollection
from .models.networks import NetworkCollection
Expand Down Expand Up @@ -80,6 +81,14 @@ def from_env(cls, **kwargs):
**kwargs_from_env(**kwargs))

# Resources
@property
def configs(self):
"""
An object for managing configs on the server. See the
:doc:`configs documentation <configs>` for full details.
"""
return ConfigCollection(client=self)

@property
def containers(self):
"""
Expand Down
69 changes: 69 additions & 0 deletions docker/models/configs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from ..api import APIClient
from .resource import Model, Collection


class Config(Model):
"""A config."""
id_attribute = 'ID'

def __repr__(self):
return "<%s: '%s'>" % (self.__class__.__name__, self.name)

@property
def name(self):
return self.attrs['Spec']['Name']

def remove(self):
"""
Remove this config.

Raises:
:py:class:`docker.errors.APIError`
If config failed to remove.
"""
return self.client.api.remove_config(self.id)


class ConfigCollection(Collection):
"""Configs on the Docker server."""
model = Config

def create(self, **kwargs):
obj = self.client.api.create_config(**kwargs)
return self.prepare_model(obj)
create.__doc__ = APIClient.create_config.__doc__

def get(self, config_id):
"""
Get a config.

Args:
config_id (str): Config ID.

Returns:
(:py:class:`Config`): The config.

Raises:
:py:class:`docker.errors.NotFound`
If the config does not exist.
:py:class:`docker.errors.APIError`
If the server returns an error.
"""
return self.prepare_model(self.client.api.inspect_config(config_id))

def list(self, **kwargs):
"""
List configs. Similar to the ``docker config ls`` command.

Args:
filters (dict): Server-side list filtering options.

Returns:
(list of :py:class:`Config`): The configs.

Raises:
:py:class:`docker.errors.APIError`
If the server returns an error.
"""
resp = self.client.api.configs(**kwargs)
return [self.prepare_model(obj) for obj in resp]
10 changes: 10 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ It's possible to use :py:class:`APIClient` directly. Some basic things (e.g. run

.. autoclass:: docker.api.client.APIClient

Configs
-------

.. py:module:: docker.api.config

.. rst-class:: hide-signature
.. autoclass:: ConfigApiMixin
:members:
:undoc-members:

Containers
----------

Expand Down
1 change: 1 addition & 0 deletions docs/client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Client reference

.. autoclass:: DockerClient()

.. autoattribute:: configs
.. autoattribute:: containers
.. autoattribute:: images
.. autoattribute:: networks
Expand Down
30 changes: 30 additions & 0 deletions docs/configs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Configs
=======

.. py:module:: docker.models.configs

Manage configs on the server.

Methods available on ``client.configs``:

.. rst-class:: hide-signature
.. py:class:: ConfigCollection

.. automethod:: create
.. automethod:: get
.. automethod:: list


Config objects
--------------

.. autoclass:: Config()

.. autoattribute:: id
.. autoattribute:: name
.. py:attribute:: attrs

The raw representation of this object from the server.

.. automethod:: reload
.. automethod:: remove
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ That's just a taste of what you can do with the Docker SDK for Python. For more,
:maxdepth: 2

client
configs
containers
images
networks
Expand Down
69 changes: 69 additions & 0 deletions tests/integration/api_config_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*-

import docker
import pytest

from ..helpers import force_leave_swarm, requires_api_version
from .base import BaseAPIIntegrationTest


@requires_api_version('1.30')
class ConfigAPITest(BaseAPIIntegrationTest):
def setUp(self):
super(ConfigAPITest, self).setUp()
self.init_swarm()

def tearDown(self):
super(ConfigAPITest, self).tearDown()
force_leave_swarm(self.client)

def test_create_config(self):
config_id = self.client.create_config(
'favorite_character', 'sakuya izayoi'
)
self.tmp_configs.append(config_id)
assert 'ID' in config_id
data = self.client.inspect_config(config_id)
assert data['Spec']['Name'] == 'favorite_character'

def test_create_config_unicode_data(self):
config_id = self.client.create_config(
'favorite_character', u'いざよいさくや'
)
self.tmp_configs.append(config_id)
assert 'ID' in config_id
data = self.client.inspect_config(config_id)
assert data['Spec']['Name'] == 'favorite_character'

def test_inspect_config(self):
config_name = 'favorite_character'
config_id = self.client.create_config(
config_name, 'sakuya izayoi'
)
self.tmp_configs.append(config_id)
data = self.client.inspect_config(config_id)
assert data['Spec']['Name'] == config_name
assert 'ID' in data
assert 'Version' in data

def test_remove_config(self):
config_name = 'favorite_character'
config_id = self.client.create_config(
config_name, 'sakuya izayoi'
)
self.tmp_configs.append(config_id)

assert self.client.remove_config(config_id)
with pytest.raises(docker.errors.NotFound):
self.client.inspect_config(config_id)

def test_list_configs(self):
config_name = 'favorite_character'
config_id = self.client.create_config(
config_name, 'sakuya izayoi'
)
self.tmp_configs.append(config_id)

data = self.client.configs(filters={'name': ['favorite_character']})
assert len(data) == 1
assert data[0]['ID'] == config_id['ID']
Loading