mirror of https://github.com/docker/docker-py.git
feat: introduce Platform class instead of JSON
This commit is contained in:
parent
2356a177c0
commit
958049e01d
|
@ -3,6 +3,7 @@ import os
|
|||
|
||||
from .. import auth, errors, utils
|
||||
from ..constants import DEFAULT_DATA_CHUNK_SIZE
|
||||
from ..types.image import Platform
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -494,7 +495,7 @@ class ImageApiMixin:
|
|||
raise errors.InvalidVersion(
|
||||
'platform was only introduced in API version 1.46'
|
||||
)
|
||||
params['platform'] = platform
|
||||
params['platform'] = Platform
|
||||
|
||||
response = self._post_json(
|
||||
u, None, headers=headers, stream=stream, params=params
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
from .base import DictType
|
||||
|
||||
|
||||
class Platform(DictType):
|
||||
def __init__(self, **kwargs):
|
||||
architecture = kwargs.get('architecture', kwargs.get('Architecture'))
|
||||
os = kwargs.get('os', kwargs.get('OS'))
|
||||
|
||||
if architecture is None and os is None:
|
||||
raise ValueError("At least one of 'architecture' or 'os' must be provided")
|
||||
|
||||
|
||||
super().__init__({
|
||||
'Architecture': architecture,
|
||||
'OS': os,
|
||||
'OSVersion': kwargs.get('os_version', kwargs.get('OSVersion')),
|
||||
'OSFeatures': kwargs.get('os_features', kwargs.get('OSFeatures')),
|
||||
'Variant': kwargs.get('variant', kwargs.get('Variant'))
|
||||
})
|
||||
|
||||
@property
|
||||
def architecture(self):
|
||||
return self['Architecture']
|
||||
|
||||
@property
|
||||
def os(self):
|
||||
return self['OS']
|
||||
|
||||
@architecture.setter
|
||||
def architecture(self, value):
|
||||
self['Architecture'] = value
|
||||
|
||||
@os.setter
|
||||
def os(self, value):
|
||||
self['OS'] = value
|
Loading…
Reference in New Issue