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
bedabbfa
Kaydet (Commit)
bedabbfa
authored
Mar 27, 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 methods for /distribution/<name>/json endpoint
Signed-off-by:
Joffrey F
<
joffrey@docker.com
>
üst
f39c0dc1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
155 additions
and
1 deletion
+155
-1
image.py
docker/api/image.py
+21
-0
images.py
docker/models/images.py
+106
-1
images.rst
docs/images.rst
+19
-0
api_image_test.py
tests/integration/api_image_test.py
+9
-0
No files found.
docker/api/image.py
Dosyayı görüntüle @
bedabbfa
...
...
@@ -245,6 +245,27 @@ class ImageApiMixin(object):
self
.
_get
(
self
.
_url
(
"/images/{0}/json"
,
image
)),
True
)
@utils.minimum_version
(
'1.30'
)
@utils.check_resource
(
'image'
)
def
inspect_distribution
(
self
,
image
):
"""
Get image digest and platform information by contacting the registry.
Args:
image (str): The image name to inspect
Returns:
(dict): A dict containing distribution data
Raises:
:py:class:`docker.errors.APIError`
If the server returns an error.
"""
return
self
.
_result
(
self
.
_get
(
self
.
_url
(
"/distribution/{0}/json"
,
image
)),
True
)
def
load_image
(
self
,
data
,
quiet
=
None
):
"""
Load an image that was previously saved using
...
...
docker/models/images.py
Dosyayı görüntüle @
bedabbfa
...
...
@@ -5,7 +5,7 @@ import six
from
..api
import
APIClient
from
..constants
import
DEFAULT_DATA_CHUNK_SIZE
from
..errors
import
BuildError
,
ImageLoadError
from
..errors
import
BuildError
,
ImageLoadError
,
InvalidArgument
from
..utils
import
parse_repository_tag
from
..utils.json_stream
import
json_stream
from
.resource
import
Collection
,
Model
...
...
@@ -105,6 +105,81 @@ class Image(Model):
return
self
.
client
.
api
.
tag
(
self
.
id
,
repository
,
tag
=
tag
,
**
kwargs
)
class
RegistryData
(
Model
):
"""
Image metadata stored on the registry, including available platforms.
"""
def
__init__
(
self
,
image_name
,
*
args
,
**
kwargs
):
super
(
RegistryData
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
image_name
=
image_name
@property
def
id
(
self
):
"""
The ID of the object.
"""
return
self
.
attrs
[
'Descriptor'
][
'digest'
]
@property
def
short_id
(
self
):
"""
The ID of the image truncated to 10 characters, plus the ``sha256:``
prefix.
"""
return
self
.
id
[:
17
]
def
pull
(
self
,
platform
=
None
):
"""
Pull the image digest.
Args:
platform (str): The platform to pull the image for.
Default: ``None``
Returns:
(:py:class:`Image`): A reference to the pulled image.
"""
repository
,
_
=
parse_repository_tag
(
self
.
image_name
)
return
self
.
collection
.
pull
(
repository
,
tag
=
self
.
id
,
platform
=
platform
)
def
has_platform
(
self
,
platform
):
"""
Check whether the given platform identifier is available for this
digest.
Args:
platform (str or dict): A string using the ``os[/arch[/variant]]``
format, or a platform dictionary.
Returns:
(bool): ``True`` if the platform is recognized as available,
``False`` otherwise.
Raises:
:py:class:`docker.errors.InvalidArgument`
If the platform argument is not a valid descriptor.
"""
if
platform
and
not
isinstance
(
platform
,
dict
):
parts
=
platform
.
split
(
'/'
)
if
len
(
parts
)
>
3
or
len
(
parts
)
<
1
:
raise
InvalidArgument
(
'"{0}" is not a valid platform descriptor'
.
format
(
platform
)
)
platform
=
{
'os'
:
parts
[
0
]}
if
len
(
parts
)
>
2
:
platform
[
'variant'
]
=
parts
[
2
]
if
len
(
parts
)
>
1
:
platform
[
'architecture'
]
=
parts
[
1
]
return
normalize_platform
(
platform
,
self
.
client
.
version
()
)
in
self
.
attrs
[
'Platforms'
]
def
reload
(
self
):
self
.
attrs
=
self
.
client
.
api
.
inspect_distribution
(
self
.
image_name
)
reload
.
__doc__
=
Model
.
reload
.
__doc__
class
ImageCollection
(
Collection
):
model
=
Image
...
...
@@ -219,6 +294,26 @@ class ImageCollection(Collection):
"""
return
self
.
prepare_model
(
self
.
client
.
api
.
inspect_image
(
name
))
def
get_registry_data
(
self
,
name
):
"""
Gets the registry data for an image.
Args:
name (str): The name of the image.
Returns:
(:py:class:`RegistryData`): The data object.
Raises:
:py:class:`docker.errors.APIError`
If the server returns an error.
"""
return
RegistryData
(
image_name
=
name
,
attrs
=
self
.
client
.
api
.
inspect_distribution
(
name
),
client
=
self
.
client
,
collection
=
self
,
)
def
list
(
self
,
name
=
None
,
all
=
False
,
filters
=
None
):
"""
List images on the server.
...
...
@@ -336,3 +431,13 @@ class ImageCollection(Collection):
def
prune
(
self
,
filters
=
None
):
return
self
.
client
.
api
.
prune_images
(
filters
=
filters
)
prune
.
__doc__
=
APIClient
.
prune_images
.
__doc__
def
normalize_platform
(
platform
,
engine_info
):
if
platform
is
None
:
platform
=
{}
if
'os'
not
in
platform
:
platform
[
'os'
]
=
engine_info
[
'Os'
]
if
'architecture'
not
in
platform
:
platform
[
'architecture'
]
=
engine_info
[
'Arch'
]
return
platform
docs/images.rst
Dosyayı görüntüle @
bedabbfa
...
...
@@ -12,6 +12,7 @@ Methods available on ``client.images``:
.. automethod:: build
.. automethod:: get
.. automethod:: get_registry_data
.. automethod:: list(**kwargs)
.. automethod:: load
.. automethod:: prune
...
...
@@ -41,3 +42,21 @@ Image objects
.. automethod:: reload
.. automethod:: save
.. automethod:: tag
RegistryData objects
--------------------
.. autoclass:: RegistryData()
.. py:attribute:: attrs
The raw representation of this object from the server.
.. autoattribute:: id
.. autoattribute:: short_id
.. automethod:: has_platform
.. automethod:: pull
.. automethod:: reload
tests/integration/api_image_test.py
Dosyayı görüntüle @
bedabbfa
...
...
@@ -357,3 +357,12 @@ class SaveLoadImagesTest(BaseAPIIntegrationTest):
success
=
True
break
assert
success
is
True
@requires_api_version
(
'1.30'
)
class
InspectDistributionTest
(
BaseAPIIntegrationTest
):
def
test_inspect_distribution
(
self
):
data
=
self
.
client
.
inspect_distribution
(
'busybox:latest'
)
assert
data
is
not
None
assert
'Platforms'
in
data
assert
{
'os'
:
'linux'
,
'architecture'
:
'amd64'
}
in
data
[
'Platforms'
]
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