Skip to content

Commit f399cf1

Browse files
authored
Feature: Add include_deprecated filter to get_list and get_all on ImagesClient (#104)
Signed-off-by: Lukas Kämmerling <lukas.kaemmerling@hetzner-cloud.de>
1 parent d0cbec5 commit f399cf1

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
History
33
=======
44

5+
master (XXXX-XX-XX)
6+
-------------------
7+
8+
* Feature: Add `include_deprecated` filter to `get_list` and `get_all` on `ImagesClient`
9+
510
v1.9.1 (2020-08-11)
611
--------------------
712

hcloud/images/client.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ def get_list(self,
154154
sort=None, # type: Optional[List[str]]
155155
page=None, # type: Optional[int]
156156
per_page=None, # type: Optional[int]
157-
status=None # type: Optional[List[str]]
157+
status=None, # type: Optional[List[str]]
158+
include_deprecated=None # type: Optional[bool]
158159
):
159160
# type: (...) -> PageResults[List[BoundImage]]
160161
"""Get all images
@@ -171,6 +172,8 @@ def get_list(self,
171172
Can be used to filter images by their status. The response will only contain images matching the status.
172173
:param sort: List[str] (optional)
173174
Choices: id id:asc id:desc name name:asc name:desc created created:asc created:desc
175+
:param include_deprecated: bool (optional)
176+
Include deprecated images in the response. Default: False
174177
:param page: int (optional)
175178
Specifies the page to fetch
176179
:param per_page: int (optional)
@@ -194,7 +197,8 @@ def get_list(self,
194197
params['per_page'] = per_page
195198
if status is not None:
196199
params['status'] = per_page
197-
200+
if include_deprecated is not None:
201+
params['include_deprecated'] = include_deprecated
198202
response = self._client.request(url="/images", method="GET", params=params)
199203
images = [BoundImage(self, image_data) for image_data in response['images']]
200204

@@ -207,6 +211,7 @@ def get_all(self,
207211
type=None, # type: Optional[List[str]]
208212
sort=None, # type: Optional[List[str]]
209213
status=None, # type: Optional[List[str]]
214+
include_deprecated=None # type: Optional[bool]
210215
):
211216
# type: (...) -> List[BoundImage]
212217
"""Get all images
@@ -223,9 +228,11 @@ def get_all(self,
223228
Can be used to filter images by their status. The response will only contain images matching the status.
224229
:param sort: List[str] (optional)
225230
Choices: id name created (You can add one of ":asc", ":desc" to modify sort order. ( ":asc" is default))
231+
:param include_deprecated: bool (optional)
232+
Include deprecated images in the response. Default: False
226233
:return: List[:class:`BoundImage <hcloud.images.client.BoundImage>`]
227234
"""
228-
return super(ImagesClient, self).get_all(name=name, label_selector=label_selector, bound_to=bound_to, type=type, sort=sort, status=status)
235+
return super(ImagesClient, self).get_all(name=name, label_selector=label_selector, bound_to=bound_to, type=type, sort=sort, status=status, include_deprecated=include_deprecated)
229236

230237
def get_by_name(self, name):
231238
# type: (str) -> BoundImage

tests/unit/images/test_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def test_get_by_id(self, images_client, image_response):
136136
"per_page": 10
137137
},
138138
{'name': ""},
139+
{'include_deprecated': True},
139140
{}
140141
]
141142
)
@@ -170,6 +171,7 @@ def test_get_list(self, images_client, two_images_response, params):
170171
"bound_to": "1",
171172
"label_selector": "k==v",
172173
},
174+
{'include_deprecated': True},
173175
{}
174176
]
175177
)

0 commit comments

Comments
 (0)