Skip to content

Commit 99b392a

Browse files
committed
feat(booking): wip booking
1 parent 40baa9a commit 99b392a

File tree

7 files changed

+188
-2
lines changed

7 files changed

+188
-2
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,7 @@ install-test:
4040

4141
.PHONY: test
4242
test:
43-
pytest -s --showprogress -vv tests/
43+
pytest -s --showprogress -vv tests/
44+
45+
.PHONY: all
46+
all: v1alpha1

openapi/scaleway.qaas.v1alpha1.Api.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,11 +863,30 @@ components:
863863
can be booked in the future. (in seconds)
864864
example: 2.5s
865865
nullable: true
866+
min_planification_duration:
867+
type: string
868+
description: Minimum planification time before a platform can be booked.
869+
(in seconds)
870+
example: 2.5s
871+
nullable: true
872+
max_booking_per_week:
873+
type: integer
874+
description: Maximum amount of booking allowed for one organization
875+
per week.
876+
format: uint32
877+
max_booking_per_day:
878+
type: integer
879+
description: Maximum amount of booking allowed for one organization
880+
per day.
881+
format: uint32
866882
x-properties-order:
867883
- min_duration
868884
- max_duration
869885
- max_cancellation_duration
870886
- max_planification_duration
887+
- min_planification_duration
888+
- max_booking_per_week
889+
- max_booking_per_day
871890
description:
872891
type: string
873892
description: English description of the platform.

scaleway_qaas_client/v1alpha1/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,9 @@
6565
from .quantum_as_a_service_api_client.models import (
6666
ScalewayQaasV1Alpha1SessionStatus as QaaSSessionStatus,
6767
)
68+
from quantum_as_a_service_api_client.models import (
69+
ScalewayQaasV1Alpha1PlatformBookingRequirement as QaaSBookingRequirements,
70+
)
71+
from quantum_as_a_service_api_client.models import (
72+
ScalewayQaasV1Alpha1Booking as QaaSBooking,
73+
)

scaleway_qaas_client/v1alpha1/client.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@
8989
from scaleway_qaas_client.v1alpha1.quantum_as_a_service_api_client.api.sessions.terminate_session import (
9090
sync_detailed as _terminate_session_sync,
9191
)
92+
from scaleway_qaas_client.v1alpha1.quantum_as_a_service_api_client.api.bookings.get_booking import (
93+
sync_detailed as _get_booking_sync,
94+
)
95+
from scaleway_qaas_client.v1alpha1.quantum_as_a_service_api_client.api.bookings.list_bookings import (
96+
sync_detailed as _list_bookings_sync,
97+
)
9298
from scaleway_qaas_client.v1alpha1.quantum_as_a_service_api_client.client import (
9399
AuthenticatedClient,
94100
)
@@ -100,12 +106,14 @@
100106
CreateModelBody,
101107
CreateProcessBody,
102108
CreateSessionBody,
109+
CreateSessionBodyBookingDemand,
103110
ListPlatformsPlatformTechnology,
104111
ListPlatformsPlatformType,
105112
ScalewayQaasV1Alpha1Application,
106113
ScalewayQaasV1Alpha1Job,
107114
ScalewayQaasV1Alpha1JobResult,
108115
ScalewayQaasV1Alpha1Model,
116+
ScalewayQaasV1Alpha1Booking,
109117
ScalewayQaasV1Alpha1Platform,
110118
ScalewayQaasV1Alpha1Process,
111119
ScalewayQaasV1Alpha1ProcessResult,
@@ -239,6 +247,9 @@ def create_session(
239247
name: Optional[str] = None,
240248
model_id: Optional[str] = None,
241249
parameters: Optional[Union[Dict, List, str]] = None,
250+
booking_demand_started_at: Optional[str] = None,
251+
booking_demand_finished_at: Optional[str] = None,
252+
booking_demand_description: Optional[str] = None,
242253
) -> ScalewayQaasV1Alpha1Session:
243254
"""Create a session
244255
@@ -261,6 +272,16 @@ def create_session(
261272
ScalewayQaasV1Alpha1Session
262273
"""
263274

275+
if not booking_demand_started_at and booking_demand_finished_at:
276+
raise Exception(
277+
"booking_demand_started_at and booking_demand_finished_at must be set"
278+
)
279+
280+
if booking_demand_started_at and not booking_demand_finished_at:
281+
raise Exception(
282+
"booking_demand_started_at and booking_demand_finished_at must be set"
283+
)
284+
264285
if not platform_id:
265286
raise Exception("create_session: platform_id cannot be None")
266287

@@ -277,6 +298,15 @@ def create_session(
277298
if isinstance(max_idle_duration, str):
278299
max_idle_duration = f"{timeparse(max_idle_duration)}s"
279300

301+
booking_demand = UNSET
302+
303+
if booking_demand_started_at and booking_demand_finished_at:
304+
booking_demand = CreateSessionBodyBookingDemand(
305+
started_at=booking_demand_started_at,
306+
finished_at=booking_demand_finished_at,
307+
description=booking_demand_description,
308+
)
309+
280310
response = _create_session_sync(
281311
client=self.__client,
282312
body=CreateSessionBody(
@@ -288,6 +318,7 @@ def create_session(
288318
max_idle_duration=max_idle_duration,
289319
model_id=model_id,
290320
parameters=parameters,
321+
booking_demand=booking_demand,
291322
),
292323
)
293324

@@ -890,3 +921,85 @@ def list_models(self) -> List[ScalewayQaasV1Alpha1Model]:
890921
_raise_on_error(response)
891922

892923
return response.parsed.models
924+
925+
def get_booking(self, booking_id: str) -> ScalewayQaasV1Alpha1Booking:
926+
"""Get booking information
927+
928+
Retrieve information about the provided **booking ID**, such as description, status and progress
929+
message.
930+
931+
Args:
932+
booking_id (str): Unique ID of the booking.
933+
934+
Raises:
935+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
936+
httpx.TimeoutException: If the request takes longer than Client.timeout.
937+
938+
Returns:
939+
Response[ScalewayQaasV1Alpha1Booking]
940+
"""
941+
942+
if not booking_id:
943+
raise Exception("get_booking: booking_id cannot be None")
944+
945+
response = _get_booking_sync(client=self.__client, booking_id=booking_id)
946+
947+
_raise_on_error(response)
948+
949+
return response.parsed
950+
951+
def list_platform_bookings(
952+
self, platform_id: str
953+
) -> List[ScalewayQaasV1Alpha1Booking]:
954+
"""List all bookings according of the target platform
955+
956+
Retrieve information about all bookings of the provided ** platform ID**.
957+
958+
Args:
959+
platform_id (Union[Unset, str]): List bookings attached to this platform ID.
960+
961+
Raises:
962+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
963+
httpx.TimeoutException: If the request takes longer than Client.timeout.
964+
965+
Returns:
966+
Response[ScalewayQaasV1Alpha1ListBookingsResponse]
967+
"""
968+
969+
response = _list_bookings_sync(client=self.__client, platform_id=platform_id)
970+
971+
_raise_on_error(response)
972+
973+
return response.parsed.bookings
974+
975+
def list_bookings(
976+
self, platform_id: Optional[str] = None
977+
) -> List[ScalewayQaasV1Alpha1Booking]:
978+
"""List all bookings according the filter of the current project.
979+
980+
Retrieve information about all bookings of the project ID.
981+
982+
Args:
983+
platform_id (Union[Unset, str]): Will list only bookings attached to this platform ID.
984+
985+
Raises:
986+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
987+
httpx.TimeoutException: If the request takes longer than Client.timeout.
988+
989+
Returns:
990+
Response[ScalewayQaasV1Alpha1ListBookingsResponse]
991+
"""
992+
if platform_id:
993+
response = _list_bookings_sync(
994+
client=self.__client,
995+
platform_id=platform_id,
996+
project_id=self.__project_id,
997+
)
998+
else:
999+
response = _list_bookings_sync(
1000+
client=self.__client, project_id=self.__project_id
1001+
)
1002+
1003+
_raise_on_error(response)
1004+
1005+
return response.parsed.bookings

scaleway_qaas_client/v1alpha1/quantum_as_a_service_api_client/models/scaleway_qaas_v1_alpha_1_platform_booking_requirement.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,19 @@ class ScalewayQaasV1Alpha1PlatformBookingRequirement:
2222
before the beginning of the session. (in seconds) Example: 2.5s.
2323
max_planification_duration (Union[None, Unset, str]): Allowed planification time from now where the platform can
2424
be booked in the future. (in seconds) Example: 2.5s.
25+
min_planification_duration (Union[None, Unset, str]): Minimum planification time before a platform can be
26+
booked. (in seconds) Example: 2.5s.
27+
max_booking_per_week (Union[Unset, int]): Maximum amount of booking allowed for one organization per week.
28+
max_booking_per_day (Union[Unset, int]): Maximum amount of booking allowed for one organization per day.
2529
"""
2630

2731
min_duration: Union[None, Unset, str] = UNSET
2832
max_duration: Union[None, Unset, str] = UNSET
2933
max_cancellation_duration: Union[None, Unset, str] = UNSET
3034
max_planification_duration: Union[None, Unset, str] = UNSET
35+
min_planification_duration: Union[None, Unset, str] = UNSET
36+
max_booking_per_week: Union[Unset, int] = UNSET
37+
max_booking_per_day: Union[Unset, int] = UNSET
3138
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
3239

3340
def to_dict(self) -> dict[str, Any]:
@@ -55,6 +62,16 @@ def to_dict(self) -> dict[str, Any]:
5562
else:
5663
max_planification_duration = self.max_planification_duration
5764

65+
min_planification_duration: Union[None, Unset, str]
66+
if isinstance(self.min_planification_duration, Unset):
67+
min_planification_duration = UNSET
68+
else:
69+
min_planification_duration = self.min_planification_duration
70+
71+
max_booking_per_week = self.max_booking_per_week
72+
73+
max_booking_per_day = self.max_booking_per_day
74+
5875
field_dict: dict[str, Any] = {}
5976
field_dict.update(self.additional_properties)
6077
field_dict.update({})
@@ -66,6 +83,12 @@ def to_dict(self) -> dict[str, Any]:
6683
field_dict["max_cancellation_duration"] = max_cancellation_duration
6784
if max_planification_duration is not UNSET:
6885
field_dict["max_planification_duration"] = max_planification_duration
86+
if min_planification_duration is not UNSET:
87+
field_dict["min_planification_duration"] = min_planification_duration
88+
if max_booking_per_week is not UNSET:
89+
field_dict["max_booking_per_week"] = max_booking_per_week
90+
if max_booking_per_day is not UNSET:
91+
field_dict["max_booking_per_day"] = max_booking_per_day
6992

7093
return field_dict
7194

@@ -113,11 +136,29 @@ def _parse_max_planification_duration(data: object) -> Union[None, Unset, str]:
113136
d.pop("max_planification_duration", UNSET)
114137
)
115138

139+
def _parse_min_planification_duration(data: object) -> Union[None, Unset, str]:
140+
if data is None:
141+
return data
142+
if isinstance(data, Unset):
143+
return data
144+
return cast(Union[None, Unset, str], data)
145+
146+
min_planification_duration = _parse_min_planification_duration(
147+
d.pop("min_planification_duration", UNSET)
148+
)
149+
150+
max_booking_per_week = d.pop("max_booking_per_week", UNSET)
151+
152+
max_booking_per_day = d.pop("max_booking_per_day", UNSET)
153+
116154
scaleway_qaas_v1_alpha_1_platform_booking_requirement = cls(
117155
min_duration=min_duration,
118156
max_duration=max_duration,
119157
max_cancellation_duration=max_cancellation_duration,
120158
max_planification_duration=max_planification_duration,
159+
min_planification_duration=min_planification_duration,
160+
max_booking_per_week=max_booking_per_week,
161+
max_booking_per_day=max_booking_per_day,
121162
)
122163

123164
scaleway_qaas_v1_alpha_1_platform_booking_requirement.additional_properties = d

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
setup(
2424
name="scaleway_qaas_client",
25-
version="0.1.22",
25+
version="0.1.23",
2626
project_urls={
2727
"Documentation": "https://www.scaleway.com/en/quantum-as-a-service/",
2828
"Source": "https://github.com/scaleway/scaleway-qaas-client-pythom",

tests/test_api.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ def test_create_delete_session():
152152
client.delete_session(session.id)
153153

154154

155+
def test_platform_bookings():
156+
client = _get_client()
157+
158+
155159
def test_create_session_same_deduplication_id():
156160
client = _get_client()
157161

0 commit comments

Comments
 (0)