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
388f291b
Kaydet (Commit)
388f291b
authored
Ock 26, 2018
tarafından
Joffrey F
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Update save / export methods to return data generators
Signed-off-by:
Joffrey F
<
joffrey@docker.com
>
üst
deb8222d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
20 deletions
+53
-20
container.py
docker/api/container.py
+3
-4
image.py
docker/api/image.py
+6
-7
images.py
docker/models/images.py
+5
-7
api_image_test.py
tests/integration/api_image_test.py
+23
-1
models_images_test.py
tests/integration/models_images_test.py
+16
-1
No files found.
docker/api/container.py
Dosyayı görüntüle @
388f291b
...
...
@@ -698,7 +698,7 @@ class ContainerApiMixin(object):
container (str): The container to export
Returns:
(
str): The filesystem tar archive
(
generator): The archived filesystem data stream
Raises:
:py:class:`docker.errors.APIError`
...
...
@@ -707,8 +707,7 @@ class ContainerApiMixin(object):
res
=
self
.
_get
(
self
.
_url
(
"/containers/{0}/export"
,
container
),
stream
=
True
)
self
.
_raise_for_status
(
res
)
return
res
.
raw
return
self
.
_stream_raw_result
(
res
)
@utils.check_resource
(
'container'
)
@utils.minimum_version
(
'1.20'
)
...
...
@@ -737,7 +736,7 @@ class ContainerApiMixin(object):
self
.
_raise_for_status
(
res
)
encoded_stat
=
res
.
headers
.
get
(
'x-docker-container-path-stat'
)
return
(
res
.
raw
,
self
.
_stream_raw_result
(
res
)
,
utils
.
decode_json_header
(
encoded_stat
)
if
encoded_stat
else
None
)
...
...
docker/api/image.py
Dosyayı görüntüle @
388f291b
...
...
@@ -21,8 +21,7 @@ class ImageApiMixin(object):
image (str): Image name to get
Returns:
(urllib3.response.HTTPResponse object): The response from the
daemon.
(generator): A stream of raw archive data.
Raises:
:py:class:`docker.errors.APIError`
...
...
@@ -30,14 +29,14 @@ class ImageApiMixin(object):
Example:
>>> image = cli.get_image("fedora:latest")
>>> f = open('/tmp/fedora-latest.tar', 'w')
>>> f.write(image.data)
>>> image = cli.get_image("busybox:latest")
>>> f = open('/tmp/busybox-latest.tar', 'w')
>>> for chunk in image:
>>> f.write(chunk)
>>> f.close()
"""
res
=
self
.
_get
(
self
.
_url
(
"/images/{0}/get"
,
image
),
stream
=
True
)
self
.
_raise_for_status
(
res
)
return
res
.
raw
return
self
.
_stream_raw_result
(
res
)
@utils.check_resource
(
'image'
)
def
history
(
self
,
image
):
...
...
docker/models/images.py
Dosyayı görüntüle @
388f291b
...
...
@@ -61,8 +61,7 @@ class Image(Model):
Get a tarball of an image. Similar to the ``docker save`` command.
Returns:
(urllib3.response.HTTPResponse object): The response from the
daemon.
(generator): A stream of raw archive data.
Raises:
:py:class:`docker.errors.APIError`
...
...
@@ -70,11 +69,10 @@ class Image(Model):
Example:
>>> image = cli.images.get("fedora:latest")
>>> resp = image.save()
>>> f = open('/tmp/fedora-latest.tar', 'w')
>>> for chunk in resp.stream():
>>> f.write(chunk)
>>> image = cli.get_image("busybox:latest")
>>> f = open('/tmp/busybox-latest.tar', 'w')
>>> for chunk in image:
>>> f.write(chunk)
>>> f.close()
"""
return
self
.
client
.
api
.
get_image
(
self
.
id
)
...
...
tests/integration/api_image_test.py
Dosyayı görüntüle @
388f291b
...
...
@@ -329,7 +329,7 @@ class PruneImagesTest(BaseAPIIntegrationTest):
img_id
=
self
.
client
.
inspect_image
(
'hello-world'
)[
'Id'
]
result
=
self
.
client
.
prune_images
()
assert
img_id
not
in
[
img
.
get
(
'Deleted'
)
for
img
in
result
[
'ImagesDeleted'
]
img
.
get
(
'Deleted'
)
for
img
in
result
.
get
(
'ImagesDeleted'
)
or
[
]
]
result
=
self
.
client
.
prune_images
({
'dangling'
:
False
})
assert
result
[
'SpaceReclaimed'
]
>
0
...
...
@@ -339,3 +339,25 @@ class PruneImagesTest(BaseAPIIntegrationTest):
assert
img_id
in
[
img
.
get
(
'Deleted'
)
for
img
in
result
[
'ImagesDeleted'
]
]
class
SaveLoadImagesTest
(
BaseAPIIntegrationTest
):
@requires_api_version
(
'1.23'
)
def
test_get_image_load_image
(
self
):
with
tempfile
.
TemporaryFile
()
as
f
:
stream
=
self
.
client
.
get_image
(
BUSYBOX
)
for
chunk
in
stream
:
f
.
write
(
chunk
)
f
.
seek
(
0
)
result
=
self
.
client
.
load_image
(
f
.
read
())
success
=
False
result_line
=
'Loaded image: {}
\n
'
.
format
(
BUSYBOX
)
for
data
in
result
:
print
(
data
)
if
'stream'
in
data
:
if
data
[
'stream'
]
==
result_line
:
success
=
True
break
assert
success
is
True
tests/integration/models_images_test.py
Dosyayı görüntüle @
388f291b
import
io
import
tempfile
import
docker
import
pytest
from
.base
import
BaseIntegrationTest
,
TEST_API_VERSION
from
.base
import
BaseIntegrationTest
,
BUSYBOX
,
TEST_API_VERSION
class
ImageCollectionTest
(
BaseIntegrationTest
):
...
...
@@ -76,6 +77,20 @@ class ImageCollectionTest(BaseIntegrationTest):
with
pytest
.
raises
(
docker
.
errors
.
ImageLoadError
):
client
.
images
.
load
(
'abc'
)
def
test_save_and_load
(
self
):
client
=
docker
.
from_env
(
version
=
TEST_API_VERSION
)
image
=
client
.
images
.
get
(
BUSYBOX
)
with
tempfile
.
TemporaryFile
()
as
f
:
stream
=
image
.
save
()
for
chunk
in
stream
:
f
.
write
(
chunk
)
f
.
seek
(
0
)
result
=
client
.
images
.
load
(
f
.
read
())
assert
len
(
result
)
==
1
assert
result
[
0
]
.
id
==
image
.
id
class
ImageTest
(
BaseIntegrationTest
):
...
...
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