|
1 | | -from datetime import datetime |
| 1 | +from datetime import datetime, timedelta |
2 | 2 | from kagglesdk.kaggle_object import * |
3 | 3 | from kagglesdk.kernels.types.kernels_enums import KernelExecutionType, KernelsListSortType, KernelsListViewType, KernelWorkerStatus |
4 | 4 | from typing import Optional, List |
5 | 5 |
|
| 6 | +class ApiAcceleratorQuota(KaggleObject): |
| 7 | + r""" |
| 8 | + Attributes: |
| 9 | + time_used (timedelta) |
| 10 | + Quota consumed in the current weekly window. |
| 11 | + time_reserved (timedelta) |
| 12 | + Quota reserved by currently-running sessions. |
| 13 | + total_time_allowed (timedelta) |
| 14 | + Quota the user is allowed in the current weekly window. |
| 15 | + minimum_time_allowed (timedelta) |
| 16 | + Minimum guaranteed weekly quota for the user. |
| 17 | + is_pay_to_scale_enabled (bool) |
| 18 | + has_ever_run (bool) |
| 19 | + True once the user has ever started a session with this accelerator. |
| 20 | + """ |
| 21 | + |
| 22 | + def __init__(self): |
| 23 | + self._time_used = None |
| 24 | + self._time_reserved = None |
| 25 | + self._total_time_allowed = None |
| 26 | + self._minimum_time_allowed = None |
| 27 | + self._is_pay_to_scale_enabled = False |
| 28 | + self._has_ever_run = False |
| 29 | + self._freeze() |
| 30 | + |
| 31 | + @property |
| 32 | + def time_used(self) -> timedelta: |
| 33 | + """Quota consumed in the current weekly window.""" |
| 34 | + return self._time_used |
| 35 | + |
| 36 | + @time_used.setter |
| 37 | + def time_used(self, time_used: timedelta): |
| 38 | + if time_used is None: |
| 39 | + del self.time_used |
| 40 | + return |
| 41 | + if not isinstance(time_used, timedelta): |
| 42 | + raise TypeError('time_used must be of type timedelta') |
| 43 | + self._time_used = time_used |
| 44 | + |
| 45 | + @property |
| 46 | + def time_reserved(self) -> timedelta: |
| 47 | + """Quota reserved by currently-running sessions.""" |
| 48 | + return self._time_reserved |
| 49 | + |
| 50 | + @time_reserved.setter |
| 51 | + def time_reserved(self, time_reserved: timedelta): |
| 52 | + if time_reserved is None: |
| 53 | + del self.time_reserved |
| 54 | + return |
| 55 | + if not isinstance(time_reserved, timedelta): |
| 56 | + raise TypeError('time_reserved must be of type timedelta') |
| 57 | + self._time_reserved = time_reserved |
| 58 | + |
| 59 | + @property |
| 60 | + def total_time_allowed(self) -> timedelta: |
| 61 | + """Quota the user is allowed in the current weekly window.""" |
| 62 | + return self._total_time_allowed |
| 63 | + |
| 64 | + @total_time_allowed.setter |
| 65 | + def total_time_allowed(self, total_time_allowed: timedelta): |
| 66 | + if total_time_allowed is None: |
| 67 | + del self.total_time_allowed |
| 68 | + return |
| 69 | + if not isinstance(total_time_allowed, timedelta): |
| 70 | + raise TypeError('total_time_allowed must be of type timedelta') |
| 71 | + self._total_time_allowed = total_time_allowed |
| 72 | + |
| 73 | + @property |
| 74 | + def minimum_time_allowed(self) -> timedelta: |
| 75 | + """Minimum guaranteed weekly quota for the user.""" |
| 76 | + return self._minimum_time_allowed |
| 77 | + |
| 78 | + @minimum_time_allowed.setter |
| 79 | + def minimum_time_allowed(self, minimum_time_allowed: timedelta): |
| 80 | + if minimum_time_allowed is None: |
| 81 | + del self.minimum_time_allowed |
| 82 | + return |
| 83 | + if not isinstance(minimum_time_allowed, timedelta): |
| 84 | + raise TypeError('minimum_time_allowed must be of type timedelta') |
| 85 | + self._minimum_time_allowed = minimum_time_allowed |
| 86 | + |
| 87 | + @property |
| 88 | + def is_pay_to_scale_enabled(self) -> bool: |
| 89 | + return self._is_pay_to_scale_enabled |
| 90 | + |
| 91 | + @is_pay_to_scale_enabled.setter |
| 92 | + def is_pay_to_scale_enabled(self, is_pay_to_scale_enabled: bool): |
| 93 | + if is_pay_to_scale_enabled is None: |
| 94 | + del self.is_pay_to_scale_enabled |
| 95 | + return |
| 96 | + if not isinstance(is_pay_to_scale_enabled, bool): |
| 97 | + raise TypeError('is_pay_to_scale_enabled must be of type bool') |
| 98 | + self._is_pay_to_scale_enabled = is_pay_to_scale_enabled |
| 99 | + |
| 100 | + @property |
| 101 | + def has_ever_run(self) -> bool: |
| 102 | + """True once the user has ever started a session with this accelerator.""" |
| 103 | + return self._has_ever_run |
| 104 | + |
| 105 | + @has_ever_run.setter |
| 106 | + def has_ever_run(self, has_ever_run: bool): |
| 107 | + if has_ever_run is None: |
| 108 | + del self.has_ever_run |
| 109 | + return |
| 110 | + if not isinstance(has_ever_run, bool): |
| 111 | + raise TypeError('has_ever_run must be of type bool') |
| 112 | + self._has_ever_run = has_ever_run |
| 113 | + |
| 114 | + |
6 | 115 | class ApiCancelKernelSessionRequest(KaggleObject): |
7 | 116 | r""" |
8 | 117 | Attributes: |
@@ -399,6 +508,84 @@ def endpoint_path(): |
399 | 508 | return '/api/v1/kernels/output/download_zip/{kernel_session_id}' |
400 | 509 |
|
401 | 510 |
|
| 511 | +class ApiGetAcceleratorQuotaStatisticsRequest(KaggleObject): |
| 512 | + r""" |
| 513 | + """ |
| 514 | + |
| 515 | + pass |
| 516 | + def endpoint(self): |
| 517 | + path = '/api/v1/kernels/quota' |
| 518 | + return path.format_map(self.to_field_map(self)) |
| 519 | + |
| 520 | + |
| 521 | +class ApiGetAcceleratorQuotaStatisticsResponse(KaggleObject): |
| 522 | + r""" |
| 523 | + Attributes: |
| 524 | + quota_refresh_time (datetime) |
| 525 | + Time at which the weekly quota window resets. |
| 526 | + gpu_quota (ApiAcceleratorQuota) |
| 527 | + tpu_quota (ApiAcceleratorQuota) |
| 528 | + """ |
| 529 | + |
| 530 | + def __init__(self): |
| 531 | + self._quota_refresh_time = None |
| 532 | + self._gpu_quota = None |
| 533 | + self._tpu_quota = None |
| 534 | + self._freeze() |
| 535 | + |
| 536 | + @property |
| 537 | + def quota_refresh_time(self) -> datetime: |
| 538 | + """Time at which the weekly quota window resets.""" |
| 539 | + return self._quota_refresh_time |
| 540 | + |
| 541 | + @quota_refresh_time.setter |
| 542 | + def quota_refresh_time(self, quota_refresh_time: datetime): |
| 543 | + if quota_refresh_time is None: |
| 544 | + del self.quota_refresh_time |
| 545 | + return |
| 546 | + if not isinstance(quota_refresh_time, datetime): |
| 547 | + raise TypeError('quota_refresh_time must be of type datetime') |
| 548 | + self._quota_refresh_time = quota_refresh_time |
| 549 | + |
| 550 | + @property |
| 551 | + def gpu_quota(self) -> Optional['ApiAcceleratorQuota']: |
| 552 | + return self._gpu_quota |
| 553 | + |
| 554 | + @gpu_quota.setter |
| 555 | + def gpu_quota(self, gpu_quota: Optional['ApiAcceleratorQuota']): |
| 556 | + if gpu_quota is None: |
| 557 | + del self.gpu_quota |
| 558 | + return |
| 559 | + if not isinstance(gpu_quota, ApiAcceleratorQuota): |
| 560 | + raise TypeError('gpu_quota must be of type ApiAcceleratorQuota') |
| 561 | + self._gpu_quota = gpu_quota |
| 562 | + |
| 563 | + @property |
| 564 | + def tpu_quota(self) -> Optional['ApiAcceleratorQuota']: |
| 565 | + return self._tpu_quota |
| 566 | + |
| 567 | + @tpu_quota.setter |
| 568 | + def tpu_quota(self, tpu_quota: Optional['ApiAcceleratorQuota']): |
| 569 | + if tpu_quota is None: |
| 570 | + del self.tpu_quota |
| 571 | + return |
| 572 | + if not isinstance(tpu_quota, ApiAcceleratorQuota): |
| 573 | + raise TypeError('tpu_quota must be of type ApiAcceleratorQuota') |
| 574 | + self._tpu_quota = tpu_quota |
| 575 | + |
| 576 | + @property |
| 577 | + def quotaRefreshTime(self): |
| 578 | + return self.quota_refresh_time |
| 579 | + |
| 580 | + @property |
| 581 | + def gpuQuota(self): |
| 582 | + return self.gpu_quota |
| 583 | + |
| 584 | + @property |
| 585 | + def tpuQuota(self): |
| 586 | + return self.tpu_quota |
| 587 | + |
| 588 | + |
402 | 589 | class ApiGetKernelRequest(KaggleObject): |
403 | 590 | r""" |
404 | 591 | Attributes: |
@@ -2328,6 +2515,15 @@ def kernelId(self): |
2328 | 2515 | return self.kernel_id |
2329 | 2516 |
|
2330 | 2517 |
|
| 2518 | +ApiAcceleratorQuota._fields = [ |
| 2519 | + FieldMetadata("timeUsed", "time_used", "_time_used", timedelta, None, TimeDeltaSerializer()), |
| 2520 | + FieldMetadata("timeReserved", "time_reserved", "_time_reserved", timedelta, None, TimeDeltaSerializer()), |
| 2521 | + FieldMetadata("totalTimeAllowed", "total_time_allowed", "_total_time_allowed", timedelta, None, TimeDeltaSerializer()), |
| 2522 | + FieldMetadata("minimumTimeAllowed", "minimum_time_allowed", "_minimum_time_allowed", timedelta, None, TimeDeltaSerializer()), |
| 2523 | + FieldMetadata("isPayToScaleEnabled", "is_pay_to_scale_enabled", "_is_pay_to_scale_enabled", bool, False, PredefinedSerializer()), |
| 2524 | + FieldMetadata("hasEverRun", "has_ever_run", "_has_ever_run", bool, False, PredefinedSerializer()), |
| 2525 | +] |
| 2526 | + |
2331 | 2527 | ApiCancelKernelSessionRequest._fields = [ |
2332 | 2528 | FieldMetadata("kernelSessionId", "kernel_session_id", "_kernel_session_id", int, 0, PredefinedSerializer()), |
2333 | 2529 | ] |
@@ -2365,6 +2561,14 @@ def kernelId(self): |
2365 | 2561 | FieldMetadata("kernelSessionId", "kernel_session_id", "_kernel_session_id", int, 0, PredefinedSerializer()), |
2366 | 2562 | ] |
2367 | 2563 |
|
| 2564 | +ApiGetAcceleratorQuotaStatisticsRequest._fields = [] |
| 2565 | + |
| 2566 | +ApiGetAcceleratorQuotaStatisticsResponse._fields = [ |
| 2567 | + FieldMetadata("quotaRefreshTime", "quota_refresh_time", "_quota_refresh_time", datetime, None, DateTimeSerializer()), |
| 2568 | + FieldMetadata("gpuQuota", "gpu_quota", "_gpu_quota", ApiAcceleratorQuota, None, KaggleObjectSerializer()), |
| 2569 | + FieldMetadata("tpuQuota", "tpu_quota", "_tpu_quota", ApiAcceleratorQuota, None, KaggleObjectSerializer()), |
| 2570 | +] |
| 2571 | + |
2368 | 2572 | ApiGetKernelRequest._fields = [ |
2369 | 2573 | FieldMetadata("userName", "user_name", "_user_name", str, "", PredefinedSerializer()), |
2370 | 2574 | FieldMetadata("kernelSlug", "kernel_slug", "_kernel_slug", str, "", PredefinedSerializer()), |
|
0 commit comments