Skip to content

Add pagination method for NDM ListDevices. #2547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.6",
"regenerated": "2025-05-06 15:06:00.944093",
"spec_repo_commit": "d0ee626b"
"regenerated": "2025-05-06 16:27:14.423277",
"spec_repo_commit": "7ed109b2"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2025-05-06 15:06:00.959289",
"spec_repo_commit": "d0ee626b"
"regenerated": "2025-05-06 16:27:14.440050",
"spec_repo_commit": "7ed109b2"
}
}
}
22 changes: 6 additions & 16 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50924,22 +50924,8 @@ paths:
description: Get the list of devices.
operationId: ListDevices
parameters:
- description: The page number to fetch.
example: 0
in: query
name: page[number]
required: false
schema:
format: int64
type: integer
- description: The number of devices to return per page.
example: 10
in: query
name: page[size]
required: false
schema:
format: int64
type: integer
- $ref: '#/components/parameters/PageSize'
- $ref: '#/components/parameters/PageNumber'
- description: The field to sort the devices by.
example: status
in: query
Expand Down Expand Up @@ -50970,6 +50956,10 @@ paths:
summary: Get the list of devices
tags:
- Network Device Monitoring
x-pagination:
limitParam: page[size]
pageParam: page[number]
resultsPath: data
/api/v2/ndm/devices/{device_id}:
get:
description: Get the device details.
Expand Down
2 changes: 1 addition & 1 deletion examples/v2/network-device-monitoring/ListDevices.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
with ApiClient(configuration) as api_client:
api_instance = NetworkDeviceMonitoringApi(api_client)
response = api_instance.list_devices(
page_number=0,
page_size=1,
page_number=0,
filter_tag="device_namespace:default",
)

Expand Down
13 changes: 13 additions & 0 deletions examples/v2/network-device-monitoring/ListDevices_2712868412.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
Get the list of devices returns "OK" response with pagination
"""

from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.network_device_monitoring_api import NetworkDeviceMonitoringApi

configuration = Configuration()
with ApiClient(configuration) as api_client:
api_instance = NetworkDeviceMonitoringApi(api_client)
items = api_instance.list_devices_with_pagination()
for item in items:
print(item)
71 changes: 62 additions & 9 deletions src/datadog_api_client/v2/api/network_device_monitoring_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
# Copyright 2019-Present Datadog, Inc.
from __future__ import annotations

import collections
from typing import Any, Dict, Union

from datadog_api_client.api_client import ApiClient, Endpoint as _Endpoint
from datadog_api_client.configuration import Configuration
from datadog_api_client.model_utils import (
set_attribute_from_path,
get_attribute_from_path,
UnsetType,
unset,
)
from datadog_api_client.v2.model.list_devices_response import ListDevicesResponse
from datadog_api_client.v2.model.devices_list_data import DevicesListData
from datadog_api_client.v2.model.get_device_response import GetDeviceResponse
from datadog_api_client.v2.model.get_interfaces_response import GetInterfacesResponse
from datadog_api_client.v2.model.list_tags_response import ListTagsResponse
Expand Down Expand Up @@ -88,14 +92,14 @@ def __init__(self, api_client=None):
"version": "v2",
},
params_map={
"page_number": {
"page_size": {
"openapi_types": (int,),
"attribute": "page[number]",
"attribute": "page[size]",
"location": "query",
},
"page_size": {
"page_number": {
"openapi_types": (int,),
"attribute": "page[size]",
"attribute": "page[number]",
"location": "query",
},
"sort": {
Expand Down Expand Up @@ -208,39 +212,88 @@ def get_interfaces(
def list_devices(
self,
*,
page_number: Union[int, UnsetType] = unset,
page_size: Union[int, UnsetType] = unset,
page_number: Union[int, UnsetType] = unset,
sort: Union[str, UnsetType] = unset,
filter_tag: Union[str, UnsetType] = unset,
) -> ListDevicesResponse:
"""Get the list of devices.

Get the list of devices.

:param page_number: The page number to fetch.
:type page_number: int, optional
:param page_size: The number of devices to return per page.
:param page_size: Size for a given page. The maximum allowed value is 100.
:type page_size: int, optional
:param page_number: Specific page number to return.
:type page_number: int, optional
:param sort: The field to sort the devices by.
:type sort: str, optional
:param filter_tag: Filter devices by tag.
:type filter_tag: str, optional
:rtype: ListDevicesResponse
"""
kwargs: Dict[str, Any] = {}
if page_size is not unset:
kwargs["page_size"] = page_size

if page_number is not unset:
kwargs["page_number"] = page_number

if sort is not unset:
kwargs["sort"] = sort

if filter_tag is not unset:
kwargs["filter_tag"] = filter_tag

return self._list_devices_endpoint.call_with_http_info(**kwargs)

def list_devices_with_pagination(
self,
*,
page_size: Union[int, UnsetType] = unset,
page_number: Union[int, UnsetType] = unset,
sort: Union[str, UnsetType] = unset,
filter_tag: Union[str, UnsetType] = unset,
) -> collections.abc.Iterable[DevicesListData]:
"""Get the list of devices.

Provide a paginated version of :meth:`list_devices`, returning all items.

:param page_size: Size for a given page. The maximum allowed value is 100.
:type page_size: int, optional
:param page_number: Specific page number to return.
:type page_number: int, optional
:param sort: The field to sort the devices by.
:type sort: str, optional
:param filter_tag: Filter devices by tag.
:type filter_tag: str, optional

:return: A generator of paginated results.
:rtype: collections.abc.Iterable[DevicesListData]
"""
kwargs: Dict[str, Any] = {}
if page_size is not unset:
kwargs["page_size"] = page_size

if page_number is not unset:
kwargs["page_number"] = page_number

if sort is not unset:
kwargs["sort"] = sort

if filter_tag is not unset:
kwargs["filter_tag"] = filter_tag

return self._list_devices_endpoint.call_with_http_info(**kwargs)
local_page_size = get_attribute_from_path(kwargs, "page_size", 10)
endpoint = self._list_devices_endpoint
set_attribute_from_path(kwargs, "page_size", local_page_size, endpoint.params_map)
pagination = {
"limit_value": local_page_size,
"results_path": "data",
"page_param": "page_number",
"endpoint": endpoint,
"kwargs": kwargs,
}
return endpoint.call_with_http_info_paginated(pagination)

def list_device_user_tags(
self,
Expand Down
6 changes: 6 additions & 0 deletions tests/v2/features/network_device_monitoring.feature
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ Feature: Network Device Monitoring
And the response "data[0].attributes.interface_statuses.down" is equal to 13
And the response "meta.page.total_filtered_count" is equal to 1

@generated @skip @team:DataDog/network-device-monitoring @with-pagination
Scenario: Get the list of devices returns "OK" response with pagination
Given new "ListDevices" request
When the request with pagination is sent
Then the response status is 200 OK

@replay-only @team:DataDog/network-device-monitoring
Scenario: Get the list of interfaces of the device returns "OK" response
Given new "GetInterfaces" request
Expand Down