@@ -59,14 +59,20 @@ def history(self):
59
59
"""
60
60
return self .client .api .history (self .id )
61
61
62
- def save (self , chunk_size = DEFAULT_DATA_CHUNK_SIZE ):
62
+ def save (self , chunk_size = DEFAULT_DATA_CHUNK_SIZE , named = False ):
63
63
"""
64
64
Get a tarball of an image. Similar to the ``docker save`` command.
65
65
66
66
Args:
67
67
chunk_size (int): The generator will return up to that much data
68
68
per iteration, but may return less. If ``None``, data will be
69
69
streamed as it is received. Default: 2 MB
70
+ named (str or bool): If ``False`` (default), the tarball will not
71
+ retain repository and tag information for this image. If set
72
+ to ``True``, the first tag in the :py:attr:`~tags` list will
73
+ be used to identify the image. Alternatively, any element of
74
+ the :py:attr:`~tags` list can be used as an argument to use
75
+ that specific tag as the saved identifier.
70
76
71
77
Returns:
72
78
(generator): A stream of raw archive data.
@@ -83,7 +89,17 @@ def save(self, chunk_size=DEFAULT_DATA_CHUNK_SIZE):
83
89
>>> f.write(chunk)
84
90
>>> f.close()
85
91
"""
86
- return self .client .api .get_image (self .id , chunk_size )
92
+ img = self .id
93
+ if named :
94
+ img = self .tags [0 ] if self .tags else img
95
+ if isinstance (named , six .string_types ):
96
+ if named not in self .tags :
97
+ raise InvalidArgument (
98
+ "{} is not a valid tag for this image" .format (named )
99
+ )
100
+ img = named
101
+
102
+ return self .client .api .get_image (img , chunk_size )
87
103
88
104
def tag (self , repository , tag = None , ** kwargs ):
89
105
"""
0 commit comments