Add the possibility to set a templating driver when creating a new Docker config

Signed-off-by: Sebastiano Mariani <smariani@vmware.com>
This commit is contained in:
Sebastiano Mariani 2021-06-03 15:51:52 -07:00
parent 96c12726fd
commit f42a81dca2
2 changed files with 20 additions and 2 deletions

View File

@ -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')

View File

@ -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'