33# Copyright 2019-Present Datadog, Inc.
44from __future__ import annotations
55
6+ import collections
67from typing import Any , Dict , Union
78
89from datadog_api_client .api_client import ApiClient , Endpoint as _Endpoint
910from datadog_api_client .configuration import Configuration
1011from datadog_api_client .model_utils import (
12+ set_attribute_from_path ,
13+ get_attribute_from_path ,
1114 UnsetType ,
1215 unset ,
1316)
1417from datadog_api_client .v2 .model .list_downtimes_response import ListDowntimesResponse
18+ from datadog_api_client .v2 .model .downtime_response_data import DowntimeResponseData
1519from datadog_api_client .v2 .model .downtime_response import DowntimeResponse
1620from datadog_api_client .v2 .model .downtime_create_request import DowntimeCreateRequest
1721from datadog_api_client .v2 .model .downtime_update_request import DowntimeUpdateRequest
@@ -124,6 +128,16 @@ def __init__(self, api_client=None):
124128 "attribute" : "include" ,
125129 "location" : "query" ,
126130 },
131+ "page_offset" : {
132+ "openapi_types" : (int ,),
133+ "attribute" : "page[offset]" ,
134+ "location" : "query" ,
135+ },
136+ "page_limit" : {
137+ "openapi_types" : (int ,),
138+ "attribute" : "page[limit]" ,
139+ "location" : "query" ,
140+ },
127141 },
128142 headers_map = {
129143 "accept" : ["application/json" ],
@@ -244,6 +258,8 @@ def list_downtimes(
244258 * ,
245259 current_only : Union [bool , UnsetType ] = unset ,
246260 include : Union [str , UnsetType ] = unset ,
261+ page_offset : Union [int , UnsetType ] = unset ,
262+ page_limit : Union [int , UnsetType ] = unset ,
247263 ) -> ListDowntimesResponse :
248264 """Get all downtimes.
249265
@@ -254,6 +270,10 @@ def list_downtimes(
254270 :param include: Comma-separated list of resource paths for related resources to include in the response. Supported resource
255271 paths are ``created_by`` and ``monitor``.
256272 :type include: str, optional
273+ :param page_offset: Specific offset to use as the beginning of the returned page.
274+ :type page_offset: int, optional
275+ :param page_limit: Maximum number of downtimes in the response.
276+ :type page_limit: int, optional
257277 :rtype: ListDowntimesResponse
258278 """
259279 kwargs : Dict [str , Any ] = {}
@@ -263,8 +283,64 @@ def list_downtimes(
263283 if include is not unset :
264284 kwargs ["include" ] = include
265285
286+ if page_offset is not unset :
287+ kwargs ["page_offset" ] = page_offset
288+
289+ if page_limit is not unset :
290+ kwargs ["page_limit" ] = page_limit
291+
266292 return self ._list_downtimes_endpoint .call_with_http_info (** kwargs )
267293
294+ def list_downtimes_with_pagination (
295+ self ,
296+ * ,
297+ current_only : Union [bool , UnsetType ] = unset ,
298+ include : Union [str , UnsetType ] = unset ,
299+ page_offset : Union [int , UnsetType ] = unset ,
300+ page_limit : Union [int , UnsetType ] = unset ,
301+ ) -> collections .abc .Iterable [DowntimeResponseData ]:
302+ """Get all downtimes.
303+
304+ Provide a paginated version of :meth:`list_downtimes`, returning all items.
305+
306+ :param current_only: Only return downtimes that are active when the request is made.
307+ :type current_only: bool, optional
308+ :param include: Comma-separated list of resource paths for related resources to include in the response. Supported resource
309+ paths are ``created_by`` and ``monitor``.
310+ :type include: str, optional
311+ :param page_offset: Specific offset to use as the beginning of the returned page.
312+ :type page_offset: int, optional
313+ :param page_limit: Maximum number of downtimes in the response.
314+ :type page_limit: int, optional
315+
316+ :return: A generator of paginated results.
317+ :rtype: collections.abc.Iterable[DowntimeResponseData]
318+ """
319+ kwargs : Dict [str , Any ] = {}
320+ if current_only is not unset :
321+ kwargs ["current_only" ] = current_only
322+
323+ if include is not unset :
324+ kwargs ["include" ] = include
325+
326+ if page_offset is not unset :
327+ kwargs ["page_offset" ] = page_offset
328+
329+ if page_limit is not unset :
330+ kwargs ["page_limit" ] = page_limit
331+
332+ local_page_size = get_attribute_from_path (kwargs , "page_limit" , 30 )
333+ endpoint = self ._list_downtimes_endpoint
334+ set_attribute_from_path (kwargs , "page_limit" , local_page_size , endpoint .params_map )
335+ pagination = {
336+ "limit_value" : local_page_size ,
337+ "results_path" : "data" ,
338+ "page_offset_param" : "page_offset" ,
339+ "endpoint" : endpoint ,
340+ "kwargs" : kwargs ,
341+ }
342+ return endpoint .call_with_http_info_paginated (pagination )
343+
268344 def list_monitor_downtimes (
269345 self ,
270346 monitor_id : int ,
0 commit comments