Skip to content
Merged
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
37 changes: 37 additions & 0 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109793,6 +109793,7 @@ components:
example:
data:
attributes:
max_responders: 1
name: On-Call Schedule
time_zone: America/New_York
id: 3653d3c6-0c75-11ea-ad28-fb5701eabc7d
Expand Down Expand Up @@ -109874,6 +109875,7 @@ components:
start_day: monday
start_time: "09:00:00"
rotation_start: "2025-02-01T00:00:00Z"
max_responders: 1
name: On-Call Schedule
time_zone: America/New_York
relationships:
Expand Down Expand Up @@ -109909,6 +109911,15 @@ components:
items:
$ref: "#/components/schemas/ScheduleCreateRequestDataAttributesLayersItems"
type: array
max_responders:
description: |-
Maximum number of users who can be on call at the same time.
The value must be between 1 and the number of layers, and no greater than 10.
example: 1
format: int64
maximum: 10
minimum: 1
type: integer
name:
description: A human-readable name for the new schedule.
example: Team A On-Call
Expand Down Expand Up @@ -110002,6 +110013,15 @@ components:
ScheduleDataAttributes:
description: Provides core properties of a schedule object such as its name and time zone.
properties:
max_responders:
description: |-
Maximum number of users who can be on call at the same time.
The value is between 1 and the number of layers, and no greater than 10.
example: 1
format: int64
maximum: 10
minimum: 1
type: integer
name:
description: A short name for the schedule.
example: Primary On-Call
Expand Down Expand Up @@ -110484,6 +110504,7 @@ components:
start_day: monday
start_time: "09:00:00"
rotation_start: "2025-02-01T00:00:00Z"
max_responders: 1
name: On-Call Schedule Updated
time_zone: America/New_York
id: 3653d3c6-0c75-11ea-ad28-fb5701eabc7d
Expand Down Expand Up @@ -110526,6 +110547,15 @@ components:
items:
$ref: "#/components/schemas/ScheduleUpdateRequestDataAttributesLayersItems"
type: array
max_responders:
description: |-
Maximum number of users who can be on call at the same time.
The value must be between 1 and the number of layers, and no greater than 10.
example: 1
format: int64
maximum: 10
minimum: 1
type: integer
name:
description: A short name for the schedule.
example: Primary On-Call
Expand Down Expand Up @@ -110655,6 +110685,7 @@ components:
example:
data:
- attributes:
max_responders: 1
name: Primary On-Call
tags: []
time_zone: America/New_York
Expand Down Expand Up @@ -205307,6 +205338,7 @@ paths:
value:
data:
- attributes:
max_responders: 1
name: Primary On-Call
tags: []
time_zone: America/New_York
Expand Down Expand Up @@ -205385,6 +205417,7 @@ paths:
start_day: monday
start_time: 09:00:00
rotation_start: "2025-02-01T00:00:00Z"
max_responders: 1
name: On-Call Schedule
time_zone: America/New_York
relationships:
Expand All @@ -205405,6 +205438,7 @@ paths:
value:
data:
attributes:
max_responders: 1
name: On-Call Schedule
time_zone: America/New_York
id: 3653d3c6-0c75-11ea-ad28-fb5701eabc7d
Expand Down Expand Up @@ -205499,6 +205533,7 @@ paths:
value:
data:
attributes:
max_responders: 1
name: On-Call Schedule
time_zone: America/New_York
id: 3653d3c6-0c75-11ea-ad28-fb5701eabc7d
Expand Down Expand Up @@ -205573,6 +205608,7 @@ paths:
start_day: monday
start_time: 09:00:00
rotation_start: "2025-02-01T00:00:00Z"
max_responders: 1
name: On-Call Schedule Updated
time_zone: America/New_York
id: 3653d3c6-0c75-11ea-ad28-fb5701eabc7d
Expand All @@ -205594,6 +205630,7 @@ paths:
value:
data:
attributes:
max_responders: 1
name: On-Call Schedule
time_zone: America/New_York
id: 00000000-0000-0000-0000-000000000001
Expand Down
92 changes: 92 additions & 0 deletions examples/v2/on-call/CreateOnCallSchedule_2169247120.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
"""
Create additive On-Call schedule returns "Created" response
"""

from datetime import datetime
from dateutil.relativedelta import relativedelta
from os import environ
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.on_call_api import OnCallApi
from datadog_api_client.v2.model.data_relationships_teams import DataRelationshipsTeams
from datadog_api_client.v2.model.data_relationships_teams_data_items import DataRelationshipsTeamsDataItems
from datadog_api_client.v2.model.data_relationships_teams_data_items_type import DataRelationshipsTeamsDataItemsType
from datadog_api_client.v2.model.layer_attributes_interval import LayerAttributesInterval
from datadog_api_client.v2.model.schedule_create_request import ScheduleCreateRequest
from datadog_api_client.v2.model.schedule_create_request_data import ScheduleCreateRequestData
from datadog_api_client.v2.model.schedule_create_request_data_attributes import ScheduleCreateRequestDataAttributes
from datadog_api_client.v2.model.schedule_create_request_data_attributes_layers_items import (
ScheduleCreateRequestDataAttributesLayersItems,
)
from datadog_api_client.v2.model.schedule_create_request_data_relationships import (
ScheduleCreateRequestDataRelationships,
)
from datadog_api_client.v2.model.schedule_create_request_data_type import ScheduleCreateRequestDataType
from datadog_api_client.v2.model.schedule_request_data_attributes_layers_items_members_items import (
ScheduleRequestDataAttributesLayersItemsMembersItems,
)
from datadog_api_client.v2.model.schedule_request_data_attributes_layers_items_members_items_user import (
ScheduleRequestDataAttributesLayersItemsMembersItemsUser,
)
from datadog_api_client.v2.model.time_restriction import TimeRestriction
from datadog_api_client.v2.model.weekday import Weekday

# there is a valid "user" in the system
USER_DATA_ID = environ["USER_DATA_ID"]

# there is a valid "dd_team" in the system
DD_TEAM_DATA_ID = environ["DD_TEAM_DATA_ID"]

body = ScheduleCreateRequest(
data=ScheduleCreateRequestData(
attributes=ScheduleCreateRequestDataAttributes(
max_responders=1,
layers=[
ScheduleCreateRequestDataAttributesLayersItems(
effective_date=(datetime.now() + relativedelta(days=-10)),
end_date=(datetime.now() + relativedelta(days=10)),
interval=LayerAttributesInterval(
days=1,
),
members=[
ScheduleRequestDataAttributesLayersItemsMembersItems(
user=ScheduleRequestDataAttributesLayersItemsMembersItemsUser(
id=USER_DATA_ID,
),
),
],
name="Layer 1",
restrictions=[
TimeRestriction(
end_day=Weekday.FRIDAY,
end_time="17:00:00",
start_day=Weekday.MONDAY,
start_time="09:00:00",
),
],
rotation_start=(datetime.now() + relativedelta(days=-5)),
),
],
name="Example-On-Call",
time_zone="America/New_York",
),
relationships=ScheduleCreateRequestDataRelationships(
teams=DataRelationshipsTeams(
data=[
DataRelationshipsTeamsDataItems(
id=DD_TEAM_DATA_ID,
type=DataRelationshipsTeamsDataItemsType.TEAMS,
),
],
),
),
type=ScheduleCreateRequestDataType.SCHEDULES,
),
)

configuration = Configuration()
configuration.access_token = environ["DD_BEARER_TOKEN"]
with ApiClient(configuration) as api_client:
api_instance = OnCallApi(api_client)
response = api_instance.create_on_call_schedule(body=body)

print(response)
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
# Copyright 2019-Present Datadog, Inc.
from __future__ import annotations

from typing import List, TYPE_CHECKING
from typing import List, Union, TYPE_CHECKING

from datadog_api_client.model_utils import (
ModelNormal,
cached_property,
unset,
UnsetType,
)


Expand All @@ -18,6 +20,13 @@


class ScheduleCreateRequestDataAttributes(ModelNormal):
validations = {
"max_responders": {
"inclusive_maximum": 10,
"inclusive_minimum": 1,
},
}

@cached_property
def openapi_types(_):
from datadog_api_client.v2.model.schedule_create_request_data_attributes_layers_items import (
Expand All @@ -26,31 +35,44 @@ def openapi_types(_):

return {
"layers": ([ScheduleCreateRequestDataAttributesLayersItems],),
"max_responders": (int,),
"name": (str,),
"time_zone": (str,),
}

attribute_map = {
"layers": "layers",
"max_responders": "max_responders",
"name": "name",
"time_zone": "time_zone",
}

def __init__(
self_, layers: List[ScheduleCreateRequestDataAttributesLayersItems], name: str, time_zone: str, **kwargs
self_,
layers: List[ScheduleCreateRequestDataAttributesLayersItems],
name: str,
time_zone: str,
max_responders: Union[int, UnsetType] = unset,
**kwargs,
):
"""
Describes the main attributes for creating a new schedule, including name, layers, and time zone.

:param layers: The layers of On-Call coverage that define rotation intervals and restrictions.
:type layers: [ScheduleCreateRequestDataAttributesLayersItems]

:param max_responders: Maximum number of users who can be on call at the same time.
The value must be between 1 and the number of layers, and no greater than 10.
:type max_responders: int, optional

:param name: A human-readable name for the new schedule.
:type name: str

:param time_zone: The time zone in which the schedule is defined.
:type time_zone: str
"""
if max_responders is not unset:
kwargs["max_responders"] = max_responders
super().__init__(kwargs)

self_.layers = layers
Expand Down
16 changes: 16 additions & 0 deletions src/datadog_api_client/v2/model/schedule_data_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,32 @@


class ScheduleDataAttributes(ModelNormal):
validations = {
"max_responders": {
"inclusive_maximum": 10,
"inclusive_minimum": 1,
},
}

@cached_property
def openapi_types(_):
return {
"max_responders": (int,),
"name": (str,),
"tags": ([str],),
"time_zone": (str,),
}

attribute_map = {
"max_responders": "max_responders",
"name": "name",
"tags": "tags",
"time_zone": "time_zone",
}

def __init__(
self_,
max_responders: Union[int, UnsetType] = unset,
name: Union[str, UnsetType] = unset,
tags: Union[List[str], UnsetType] = unset,
time_zone: Union[str, UnsetType] = unset,
Expand All @@ -38,6 +48,10 @@ def __init__(
"""
Provides core properties of a schedule object such as its name and time zone.

:param max_responders: Maximum number of users who can be on call at the same time.
The value is between 1 and the number of layers, and no greater than 10.
:type max_responders: int, optional

:param name: A short name for the schedule.
:type name: str, optional

Expand All @@ -47,6 +61,8 @@ def __init__(
:param time_zone: The time zone in which this schedule operates.
:type time_zone: str, optional
"""
if max_responders is not unset:
kwargs["max_responders"] = max_responders
if name is not unset:
kwargs["name"] = name
if tags is not unset:
Expand Down
Loading
Loading