|
3 | 3 | # Copyright 2019-Present Datadog, Inc. |
4 | 4 | from __future__ import annotations |
5 | 5 |
|
| 6 | +import collections |
6 | 7 | from typing import Any, Dict, Union |
7 | 8 |
|
8 | 9 | from datadog_api_client.api_client import ApiClient, Endpoint as _Endpoint |
9 | 10 | from datadog_api_client.configuration import Configuration |
10 | 11 | from datadog_api_client.model_utils import ( |
| 12 | + set_attribute_from_path, |
| 13 | + get_attribute_from_path, |
11 | 14 | UnsetType, |
12 | 15 | unset, |
13 | 16 | ) |
14 | 17 | from datadog_api_client.v2.model.list_devices_response import ListDevicesResponse |
| 18 | +from datadog_api_client.v2.model.devices_list_data import DevicesListData |
15 | 19 | from datadog_api_client.v2.model.get_device_response import GetDeviceResponse |
16 | 20 | from datadog_api_client.v2.model.get_interfaces_response import GetInterfacesResponse |
17 | 21 | from datadog_api_client.v2.model.list_tags_response import ListTagsResponse |
@@ -88,14 +92,14 @@ def __init__(self, api_client=None): |
88 | 92 | "version": "v2", |
89 | 93 | }, |
90 | 94 | params_map={ |
91 | | - "page_number": { |
| 95 | + "page_size": { |
92 | 96 | "openapi_types": (int,), |
93 | | - "attribute": "page[number]", |
| 97 | + "attribute": "page[size]", |
94 | 98 | "location": "query", |
95 | 99 | }, |
96 | | - "page_size": { |
| 100 | + "page_number": { |
97 | 101 | "openapi_types": (int,), |
98 | | - "attribute": "page[size]", |
| 102 | + "attribute": "page[number]", |
99 | 103 | "location": "query", |
100 | 104 | }, |
101 | 105 | "sort": { |
@@ -208,39 +212,88 @@ def get_interfaces( |
208 | 212 | def list_devices( |
209 | 213 | self, |
210 | 214 | *, |
211 | | - page_number: Union[int, UnsetType] = unset, |
212 | 215 | page_size: Union[int, UnsetType] = unset, |
| 216 | + page_number: Union[int, UnsetType] = unset, |
213 | 217 | sort: Union[str, UnsetType] = unset, |
214 | 218 | filter_tag: Union[str, UnsetType] = unset, |
215 | 219 | ) -> ListDevicesResponse: |
216 | 220 | """Get the list of devices. |
217 | 221 |
|
218 | 222 | Get the list of devices. |
219 | 223 |
|
220 | | - :param page_number: The page number to fetch. |
221 | | - :type page_number: int, optional |
222 | | - :param page_size: The number of devices to return per page. |
| 224 | + :param page_size: Size for a given page. The maximum allowed value is 100. |
223 | 225 | :type page_size: int, optional |
| 226 | + :param page_number: Specific page number to return. |
| 227 | + :type page_number: int, optional |
224 | 228 | :param sort: The field to sort the devices by. |
225 | 229 | :type sort: str, optional |
226 | 230 | :param filter_tag: Filter devices by tag. |
227 | 231 | :type filter_tag: str, optional |
228 | 232 | :rtype: ListDevicesResponse |
229 | 233 | """ |
230 | 234 | kwargs: Dict[str, Any] = {} |
| 235 | + if page_size is not unset: |
| 236 | + kwargs["page_size"] = page_size |
| 237 | + |
231 | 238 | if page_number is not unset: |
232 | 239 | kwargs["page_number"] = page_number |
233 | 240 |
|
| 241 | + if sort is not unset: |
| 242 | + kwargs["sort"] = sort |
| 243 | + |
| 244 | + if filter_tag is not unset: |
| 245 | + kwargs["filter_tag"] = filter_tag |
| 246 | + |
| 247 | + return self._list_devices_endpoint.call_with_http_info(**kwargs) |
| 248 | + |
| 249 | + def list_devices_with_pagination( |
| 250 | + self, |
| 251 | + *, |
| 252 | + page_size: Union[int, UnsetType] = unset, |
| 253 | + page_number: Union[int, UnsetType] = unset, |
| 254 | + sort: Union[str, UnsetType] = unset, |
| 255 | + filter_tag: Union[str, UnsetType] = unset, |
| 256 | + ) -> collections.abc.Iterable[DevicesListData]: |
| 257 | + """Get the list of devices. |
| 258 | +
|
| 259 | + Provide a paginated version of :meth:`list_devices`, returning all items. |
| 260 | +
|
| 261 | + :param page_size: Size for a given page. The maximum allowed value is 100. |
| 262 | + :type page_size: int, optional |
| 263 | + :param page_number: Specific page number to return. |
| 264 | + :type page_number: int, optional |
| 265 | + :param sort: The field to sort the devices by. |
| 266 | + :type sort: str, optional |
| 267 | + :param filter_tag: Filter devices by tag. |
| 268 | + :type filter_tag: str, optional |
| 269 | +
|
| 270 | + :return: A generator of paginated results. |
| 271 | + :rtype: collections.abc.Iterable[DevicesListData] |
| 272 | + """ |
| 273 | + kwargs: Dict[str, Any] = {} |
234 | 274 | if page_size is not unset: |
235 | 275 | kwargs["page_size"] = page_size |
236 | 276 |
|
| 277 | + if page_number is not unset: |
| 278 | + kwargs["page_number"] = page_number |
| 279 | + |
237 | 280 | if sort is not unset: |
238 | 281 | kwargs["sort"] = sort |
239 | 282 |
|
240 | 283 | if filter_tag is not unset: |
241 | 284 | kwargs["filter_tag"] = filter_tag |
242 | 285 |
|
243 | | - return self._list_devices_endpoint.call_with_http_info(**kwargs) |
| 286 | + local_page_size = get_attribute_from_path(kwargs, "page_size", 10) |
| 287 | + endpoint = self._list_devices_endpoint |
| 288 | + set_attribute_from_path(kwargs, "page_size", local_page_size, endpoint.params_map) |
| 289 | + pagination = { |
| 290 | + "limit_value": local_page_size, |
| 291 | + "results_path": "data", |
| 292 | + "page_param": "page_number", |
| 293 | + "endpoint": endpoint, |
| 294 | + "kwargs": kwargs, |
| 295 | + } |
| 296 | + return endpoint.call_with_http_info_paginated(pagination) |
244 | 297 |
|
245 | 298 | def list_device_user_tags( |
246 | 299 | self, |
|
0 commit comments