Skip to content

Commit 19a5dfa

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add pagination method for NDM ListDevices. (#2547)
Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent 6c98d87 commit 19a5dfa

File tree

6 files changed

+92
-30
lines changed

6 files changed

+92
-30
lines changed

.apigentools-info

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.6.6",
7-
"regenerated": "2025-05-06 19:21:56.672730",
8-
"spec_repo_commit": "1faa96a2"
7+
"regenerated": "2025-05-07 17:07:24.917132",
8+
"spec_repo_commit": "a1235a0d"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.6",
12-
"regenerated": "2025-05-06 19:21:56.688887",
13-
"spec_repo_commit": "1faa96a2"
12+
"regenerated": "2025-05-07 17:07:24.932247",
13+
"spec_repo_commit": "a1235a0d"
1414
}
1515
}
1616
}

.generator/schemas/v2/openapi.yaml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50925,22 +50925,8 @@ paths:
5092550925
description: Get the list of devices.
5092650926
operationId: ListDevices
5092750927
parameters:
50928-
- description: The page number to fetch.
50929-
example: 0
50930-
in: query
50931-
name: page[number]
50932-
required: false
50933-
schema:
50934-
format: int64
50935-
type: integer
50936-
- description: The number of devices to return per page.
50937-
example: 10
50938-
in: query
50939-
name: page[size]
50940-
required: false
50941-
schema:
50942-
format: int64
50943-
type: integer
50928+
- $ref: '#/components/parameters/PageSize'
50929+
- $ref: '#/components/parameters/PageNumber'
5094450930
- description: The field to sort the devices by.
5094550931
example: status
5094650932
in: query
@@ -50971,6 +50957,10 @@ paths:
5097150957
summary: Get the list of devices
5097250958
tags:
5097350959
- Network Device Monitoring
50960+
x-pagination:
50961+
limitParam: page[size]
50962+
pageParam: page[number]
50963+
resultsPath: data
5097450964
/api/v2/ndm/devices/{device_id}:
5097550965
get:
5097650966
description: Get the device details.

examples/v2/network-device-monitoring/ListDevices.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
with ApiClient(configuration) as api_client:
1010
api_instance = NetworkDeviceMonitoringApi(api_client)
1111
response = api_instance.list_devices(
12-
page_number=0,
1312
page_size=1,
13+
page_number=0,
1414
filter_tag="device_namespace:default",
1515
)
1616

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
Get the list of devices returns "OK" response with pagination
3+
"""
4+
5+
from datadog_api_client import ApiClient, Configuration
6+
from datadog_api_client.v2.api.network_device_monitoring_api import NetworkDeviceMonitoringApi
7+
8+
configuration = Configuration()
9+
with ApiClient(configuration) as api_client:
10+
api_instance = NetworkDeviceMonitoringApi(api_client)
11+
items = api_instance.list_devices_with_pagination()
12+
for item in items:
13+
print(item)

src/datadog_api_client/v2/api/network_device_monitoring_api.py

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
# Copyright 2019-Present Datadog, Inc.
44
from __future__ import annotations
55

6+
import collections
67
from typing import Any, Dict, Union
78

89
from datadog_api_client.api_client import ApiClient, Endpoint as _Endpoint
910
from datadog_api_client.configuration import Configuration
1011
from datadog_api_client.model_utils import (
12+
set_attribute_from_path,
13+
get_attribute_from_path,
1114
UnsetType,
1215
unset,
1316
)
1417
from datadog_api_client.v2.model.list_devices_response import ListDevicesResponse
18+
from datadog_api_client.v2.model.devices_list_data import DevicesListData
1519
from datadog_api_client.v2.model.get_device_response import GetDeviceResponse
1620
from datadog_api_client.v2.model.get_interfaces_response import GetInterfacesResponse
1721
from datadog_api_client.v2.model.list_tags_response import ListTagsResponse
@@ -88,14 +92,14 @@ def __init__(self, api_client=None):
8892
"version": "v2",
8993
},
9094
params_map={
91-
"page_number": {
95+
"page_size": {
9296
"openapi_types": (int,),
93-
"attribute": "page[number]",
97+
"attribute": "page[size]",
9498
"location": "query",
9599
},
96-
"page_size": {
100+
"page_number": {
97101
"openapi_types": (int,),
98-
"attribute": "page[size]",
102+
"attribute": "page[number]",
99103
"location": "query",
100104
},
101105
"sort": {
@@ -208,39 +212,88 @@ def get_interfaces(
208212
def list_devices(
209213
self,
210214
*,
211-
page_number: Union[int, UnsetType] = unset,
212215
page_size: Union[int, UnsetType] = unset,
216+
page_number: Union[int, UnsetType] = unset,
213217
sort: Union[str, UnsetType] = unset,
214218
filter_tag: Union[str, UnsetType] = unset,
215219
) -> ListDevicesResponse:
216220
"""Get the list of devices.
217221
218222
Get the list of devices.
219223
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.
223225
:type page_size: int, optional
226+
:param page_number: Specific page number to return.
227+
:type page_number: int, optional
224228
:param sort: The field to sort the devices by.
225229
:type sort: str, optional
226230
:param filter_tag: Filter devices by tag.
227231
:type filter_tag: str, optional
228232
:rtype: ListDevicesResponse
229233
"""
230234
kwargs: Dict[str, Any] = {}
235+
if page_size is not unset:
236+
kwargs["page_size"] = page_size
237+
231238
if page_number is not unset:
232239
kwargs["page_number"] = page_number
233240

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] = {}
234274
if page_size is not unset:
235275
kwargs["page_size"] = page_size
236276

277+
if page_number is not unset:
278+
kwargs["page_number"] = page_number
279+
237280
if sort is not unset:
238281
kwargs["sort"] = sort
239282

240283
if filter_tag is not unset:
241284
kwargs["filter_tag"] = filter_tag
242285

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)
244297

245298
def list_device_user_tags(
246299
self,

tests/v2/features/network_device_monitoring.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ Feature: Network Device Monitoring
7575
And the response "data[0].attributes.interface_statuses.down" is equal to 13
7676
And the response "meta.page.total_filtered_count" is equal to 1
7777

78+
@generated @skip @team:DataDog/network-device-monitoring @with-pagination
79+
Scenario: Get the list of devices returns "OK" response with pagination
80+
Given new "ListDevices" request
81+
When the request with pagination is sent
82+
Then the response status is 200 OK
83+
7884
@replay-only @team:DataDog/network-device-monitoring
7985
Scenario: Get the list of interfaces of the device returns "OK" response
8086
Given new "GetInterfaces" request

0 commit comments

Comments
 (0)