diff options
| author | Sebastiano Mariani <smariani@vmware.com> | 2021-06-03 15:51:52 -0700 |
|---|---|---|
| committer | Sebastiano Mariani <smariani@vmware.com> | 2021-06-03 15:51:52 -0700 |
| commit | f42a81dca2aa7a152677ee1a7d5e14248e9a6e76 (patch) | |
| tree | 95dcee1ee7560de20899cf0fbff00a001177cdb8 | |
| parent | 96c12726fdb9b24e985b4de74d5c82145ccd8185 (diff) | |
| download | docker-py-f42a81dca2aa7a152677ee1a7d5e14248e9a6e76.tar.gz | |
Add the possibility to set a templating driver when creating a new Docker config
Signed-off-by: Sebastiano Mariani <smariani@vmware.com>
| -rw-r--r-- | docker/api/config.py | 9 | ||||
| -rw-r--r-- | tests/integration/api_config_test.py | 13 |
2 files changed, 20 insertions, 2 deletions
diff --git a/docker/api/config.py b/docker/api/config.py index 93e5168..303be68 100644 --- a/docker/api/config.py +++ b/docker/api/config.py @@ -6,8 +6,9 @@ from .. import utils class ConfigApiMixin(object): + # TODO: The templating field is only available starting from API v 1.37 @utils.minimum_version('1.30') - def create_config(self, name, data, labels=None): + def create_config(self, name, data, labels=None, templating=None): """ Create a config @@ -15,6 +16,9 @@ class ConfigApiMixin(object): name (string): Name of the config data (bytes): Config data to be stored labels (dict): A mapping of labels to assign to the config + templating (dict): dictionary containing the name of the + templating driver to be used expressed as + { name: <templating_driver_name>} Returns (dict): ID of the newly created config """ @@ -27,7 +31,8 @@ class ConfigApiMixin(object): body = { 'Data': data, 'Name': name, - 'Labels': labels + 'Labels': labels, + 'Templating': templating } url = self._url('/configs/create') diff --git a/tests/integration/api_config_test.py b/tests/integration/api_config_test.py index 0ffd767..7b7d9c1 100644 --- a/tests/integration/api_config_test.py +++ b/tests/integration/api_config_test.py @@ -70,3 +70,16 @@ class ConfigAPITest(BaseAPIIntegrationTest): data = self.client.configs(filters={'name': ['favorite_character']}) assert len(data) == 1 assert data[0]['ID'] == config_id['ID'] + + @requires_api_version('1.37') + def test_create_config_with_templating(self): + config_id = self.client.create_config( + 'favorite_character', 'sakuya izayoi', + templating={ 'name': 'golang'} + ) + self.tmp_configs.append(config_id) + assert 'ID' in config_id + data = self.client.inspect_config(config_id) + assert data['Spec']['Name'] == 'favorite_character' + assert 'Templating' in data['Spec'] + assert data['Spec']['Templating']['Name'] == 'golang' |
