Commit Graph

27 Commits

Author SHA1 Message Date
Khushiyant b8a6987cd5
fix: keyerror when creating new config (#3200)
Closes #3110.

---------

Signed-off-by: Khushiyant <khushiyant2002@gmail.com>
2024-01-03 18:44:53 +00:00
Aarni Koskela c68d532f54 Fix duplicate dict key literal (ruff F601)
Signed-off-by: Aarni Koskela <akx@iki.fi>
2023-08-15 13:36:53 +03:00
Aarni Koskela ec58856ee3 Clean up unnecessary noqa comments
Signed-off-by: Aarni Koskela <akx@iki.fi>
2023-08-15 13:36:53 +03:00
Aarni Koskela 8a3402c049 Replace string formatting with f-strings
Signed-off-by: Aarni Koskela <akx@iki.fi>
2023-08-15 13:36:53 +03:00
Ben Fasoli 23cf16f03a
client: use 12 character short IDs (#2862)
Use 12 characters for Docker resource IDs for
consistency with the Docker CLI.

Signed-off-by: Ben Fasoli <benfasoli@gmail.com>
2022-07-29 09:06:22 -04:00
Anthony Sottile 5fcc293ba2 use python3.6+ constructs
Signed-off-by: Anthony Sottile <asottile@umich.edu>
2021-07-05 18:30:07 -04:00
Felipe Ruhland d4310b2db0 Fix `KeyError` when creating a new secret
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>
2021-03-24 18:03:54 +01:00
aiordache c7c5b551fc set engine version for unit tests to avoid querying the engine
Signed-off-by: aiordache <anca.iordache@docker.com>
2020-08-20 15:29:24 +02:00
Matthieu Nottale 15c26e7057 Workaround requests resolving our unix socket URL on macosx.
Signed-off-by: Matthieu Nottale <matthieu.nottale@docker.com>
2018-02-26 14:47:26 +01:00
Joffrey F df8422d079 Refuse API version < 1.21 ; Remove associated code paths
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-01-31 14:42:01 -08:00
Joffrey F ac68a36a89
Merge pull request #1727 from mbelang/join-swarn-default-listen-address
Add join_swarm default listen address
2017-12-18 17:16:41 -08:00
Joffrey F 7107e265b1 Do not interrupt streaming when encountering 0-length frames
Signed-off-by: Joffrey F <joffrey@docker.com>
2017-11-07 15:18:26 -08:00
Maxime Belanger 7fa2cb7be3 Add join_swarm default listen address
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>
2017-08-29 08:38:16 -04:00
Artem Bolshakov 62fda980e4 client.containers.run returns None if none of json-file or journald logging drivers used
Signed-off-by: Artem Bolshakov <either.free@gmail.com>
2017-08-17 13:38:40 -07:00
Artem Bolshakov b8fd821336 client.containers.run returns None if none of json-file or journald logging drivers used
Signed-off-by: Artem Bolshakov <either.free@gmail.com>
2017-08-07 12:02:02 -07:00
Frank Sachsenheim b585ec59a8 Adds a 'labels' property to the image model
Signed-off-by: Frank Sachsenheim <funkyfuture@riseup.net>
2017-04-15 15:46:52 +02:00
Frank Sachsenheim 1cd56b9f0c Adds a 'labels' property to the container model
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>
2017-04-15 15:46:52 +02:00
徐俊杰 b9c48dca2c Scope is added in volume after docker 1.12
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>
2016-12-08 10:31:44 +08:00
Ben Firshman 1984f68730
Add new user-focused API
See #1086

Signed-off-by: Ben Firshman <ben@firshman.co.uk>
2016-11-22 17:05:43 +00:00
Joffrey F f745c8e7c5 Merge pull request #1230 from LabattFoodService/updateNode
enable setting of node labels #1225
2016-11-07 10:47:55 -08:00
Joffrey F cec3fe7c31 Update tests to avoid failures on Windows platforms
Signed-off-by: Joffrey F <joffrey@docker.com>
2016-10-14 16:02:28 -07:00
Nathan Shirlberg 6ef14932d0 enable setting of node labels #1225
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>
2016-09-27 11:26:26 -05:00
Ben Firshman 0cdf737625
Fix unit test which doesn't do anything
It also overrode the fake API inspect endpoint with a broken
response.

Signed-off-by: Ben Firshman <ben@firshman.co.uk>
2016-09-07 11:40:19 +02:00
Ben Firshman 3769c089e8
Fix licenses
* Complete main LICENSE
* Remove unnecessary licenses from individual files

Signed-off-by: Ben Firshman <ben@firshman.co.uk>
2016-09-05 17:48:09 +02:00
Tomas Tomecek 8f8a3d0ed2 volumes,create: support adding labels
Fixes #1102

Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>
2016-07-13 08:41:45 +02:00
Joffrey F a710fbf60a Unit test for Client.update_container method
Signed-off-by: Joffrey F <joffrey@docker.com>
2016-02-23 16:18:36 -08:00
Joffrey F 93a296fb04 Reorganize test directories
More clearly separate unit and integration tests
Allow splitting into multiple files
Cleaner

Signed-off-by: Joffrey F <joffrey@docker.com>
2015-10-21 16:02:09 -07:00