Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
docker-py
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
docker-py
Commits
d310d95f
Kaydet (Commit)
d310d95f
authored
Mar 14, 2018
tarafından
Joffrey F
Kaydeden (comit)
Joffrey F
Mar 29, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add test for container list with sparse=True
Signed-off-by:
Joffrey F
<
joffrey@docker.com
>
üst
726d7f31
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
9 deletions
+43
-9
containers.py
docker/models/containers.py
+21
-9
models_containers_test.py
tests/integration/models_containers_test.py
+22
-0
No files found.
docker/models/containers.py
Dosyayı görüntüle @
d310d95f
...
...
@@ -4,8 +4,10 @@ from collections import namedtuple
from
..api
import
APIClient
from
..constants
import
DEFAULT_DATA_CHUNK_SIZE
from
..errors
import
(
ContainerError
,
ImageNotFound
,
create_unexpected_kwargs_error
)
from
..errors
import
(
ContainerError
,
DockerException
,
ImageNotFound
,
create_unexpected_kwargs_error
)
from
..types
import
HostConfig
from
..utils
import
version_gte
from
.images
import
Image
...
...
@@ -27,7 +29,7 @@ class Container(Model):
"""
The image of the container.
"""
image_id
=
self
.
attrs
[
'Image'
]
image_id
=
self
.
attrs
.
get
(
'ImageID'
,
self
.
attrs
[
'Image'
])
if
image_id
is
None
:
return
None
return
self
.
client
.
images
.
get
(
image_id
.
split
(
':'
)[
1
])
...
...
@@ -37,15 +39,23 @@ class Container(Model):
"""
The labels of a container as dictionary.
"""
result
=
self
.
attrs
[
'Config'
]
.
get
(
'Labels'
)
return
result
or
{}
try
:
result
=
self
.
attrs
[
'Config'
]
.
get
(
'Labels'
)
return
result
or
{}
except
KeyError
:
raise
DockerException
(
'Label data is not available for sparse objects. Call reload()'
' to retrieve all information'
)
@property
def
status
(
self
):
"""
The status of the container. For example, ``running``, or ``exited``.
"""
return
self
.
attrs
[
'State'
][
'Status'
]
if
isinstance
(
self
.
attrs
[
'State'
],
dict
):
return
self
.
attrs
[
'State'
][
'Status'
]
return
self
.
attrs
[
'State'
]
def
attach
(
self
,
**
kwargs
):
"""
...
...
@@ -863,14 +873,16 @@ class ContainerCollection(Collection):
container. Give the container name or id.
- `since` (str): Only containers created after a particular
container. Give container name or id.
sparse (bool): Do not inspect containers. Returns partial
informations, but guaranteed not to block. Use reload() on
each container to get the full list of attributes.
A comprehensive list can be found in the documentation for
`docker ps
<https://docs.docker.com/engine/reference/commandline/ps>`_.
sparse (bool): Do not inspect containers. Returns partial
information, but guaranteed not to block. Use
:py:meth:`Container.reload` on resulting objects to retrieve
all attributes. Default: ``False``
Returns:
(list of :py:class:`Container`)
...
...
tests/integration/models_containers_test.py
Dosyayı görüntüle @
d310d95f
...
...
@@ -159,6 +159,28 @@ class ContainerCollectionTest(BaseIntegrationTest):
container
=
containers
[
0
]
assert
container
.
attrs
[
'Config'
][
'Image'
]
==
'alpine'
assert
container
.
status
==
'running'
assert
container
.
image
==
client
.
images
.
get
(
'alpine'
)
container
.
kill
()
container
.
remove
()
assert
container_id
not
in
[
c
.
id
for
c
in
client
.
containers
.
list
()]
def
test_list_sparse
(
self
):
client
=
docker
.
from_env
(
version
=
TEST_API_VERSION
)
container_id
=
client
.
containers
.
run
(
"alpine"
,
"sleep 300"
,
detach
=
True
)
.
id
self
.
tmp_containers
.
append
(
container_id
)
containers
=
[
c
for
c
in
client
.
containers
.
list
(
sparse
=
True
)
if
c
.
id
==
container_id
]
assert
len
(
containers
)
==
1
container
=
containers
[
0
]
assert
container
.
attrs
[
'Image'
]
==
'alpine'
assert
container
.
status
==
'running'
assert
container
.
image
==
client
.
images
.
get
(
'alpine'
)
with
pytest
.
raises
(
docker
.
errors
.
DockerException
):
container
.
labels
container
.
kill
()
container
.
remove
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment