How to reproduce the issue:
```py
>>> import docker
>>> cli = docker.from_env()
>>> cli.secrets.create(name="any_name", data="1")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/docker-py/docker/models/secrets.py", line 10, in __repr__
return "<%s: '%s'>" % (self.__class__.__name__, self.name)
File "/home/docker-py/docker/models/secrets.py", line 14, in name
return self.attrs['Spec']['Name']
KeyError: 'Spec'
```
The exception raises because create secrets API `/secrets/create` only
return the `id` attribute:
https://docs.docker.com/engine/api/v1.41/#operation/SecretCreate
The secret model is created using just the `id` attribute and fails
when looking for Spec.Name attribute.
```py
def __repr__(self):
return "<%s: '%s'>" % (self.__class__.__name__, self.name)
```
```py
@property
def name(self):
return self.attrs['Spec']['Name']
```
I came up with a ugly solution but will prevent the problem to happen
again:
```py
def create(self, **kwargs):
obj = self.client.api.create_secret(**kwargs)
+ obj.setdefault("Spec", {})["Name"] = kwargs.get("name")
return self.prepare_model(obj)
```
After the API call, I added the name attribute to the right place to be
used on the property name.
```py
>>> import docker
>>> cli = docker.from_env()
>>> cli.secrets.create(name="any_name", data="1")
<Secret: 'any_name'>
```
It isn't the most elegant solution, but it will do the trick.
I had a previous PR #2517 when I propose using the `id` attribute
instead of `name` on the `__repr__` method, but I think this one will be better.
That fixes#2025
Signed-off-by: Felipe Ruhland <felipe.ruhland@gmail.com>
Since the docker CLI adds a default listen address (0.0.0.0:2377)
when joining a node to the swarm, the docker-py api will support
the same behavior to easy configuration.
Signed-off-by: Maxime Belanger <maxime.b.belanger@gmail.com>
The Docker API seems to respond with a 'null' value for the 'Labels'
attribute from containers that were created with older Docker versions.
An empty dictionary is returned in this case.
Signed-off-by: Frank Sachsenheim <funkyfuture@riseup.net>
Signed-off-by: pacoxu <paco.xu@daocloud.io>
add ut test for volume scope and no specified name create
Signed-off-by: Paco Xu <paco.xu@daocloud.io>
try to fix ut failure of volume creation
Signed-off-by: Paco Xu <paco.xu@daocloud.io>
try to fix ut failure of volume creation
Signed-off-by: Paco Xu <paco.xu@daocloud.io>
Scope is added in volume after docker 1.12
Signed-off-by: pacoxu <paco.xu@daocloud.io>
Scope is added in volume after docker 1.12
Signed-off-by: pacoxu <paco.xu@daocloud.io>
Added update_node function to enable setting labels on nodes. This
exposes the Update a Node function from the Docker API and should
enable promoting/demoting manager nodes inside a swarm.
Signed-off-by: Nathan Shirlberg <nshirlberg@labattfood.com>