Skip to content

Commit be8d0c2

Browse files
feat(edge_services): add GetCurrentBilling endpoint (#686)
Co-authored-by: Laure-di <62625835+Laure-di@users.noreply.github.com>
1 parent 3734642 commit be8d0c2

File tree

8 files changed

+346
-48
lines changed

8 files changed

+346
-48
lines changed

scaleway-async/scaleway_async/edge_services/v1alpha1/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
from .types import DeletePipelineRequest
5151
from .types import DeleteTLSStageRequest
5252
from .types import GetBackendStageRequest
53+
from .types import GetBillingRequest
54+
from .types import GetBillingResponse
5355
from .types import GetCacheStageRequest
5456
from .types import GetCurrentPlanRequest
5557
from .types import GetDNSStageRequest
@@ -129,6 +131,8 @@
129131
"DeletePipelineRequest",
130132
"DeleteTLSStageRequest",
131133
"GetBackendStageRequest",
134+
"GetBillingRequest",
135+
"GetBillingResponse",
132136
"GetCacheStageRequest",
133137
"GetCurrentPlanRequest",
134138
"GetDNSStageRequest",

scaleway-async/scaleway_async/edge_services/v1alpha1/api.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
CreatePurgeRequestRequest,
3535
CreateTLSStageRequest,
3636
DNSStage,
37+
GetBillingResponse,
3738
ListBackendStagesResponse,
3839
ListCacheStagesResponse,
3940
ListDNSStagesResponse,
@@ -71,6 +72,7 @@
7172
unmarshal_CheckDomainResponse,
7273
unmarshal_CheckLbOriginResponse,
7374
unmarshal_CheckPEMChainResponse,
75+
unmarshal_GetBillingResponse,
7476
unmarshal_ListBackendStagesResponse,
7577
unmarshal_ListCacheStagesResponse,
7678
unmarshal_ListDNSStagesResponse,
@@ -1710,3 +1712,31 @@ async def delete_current_plan(
17101712
)
17111713

17121714
self._throw_on_error(res)
1715+
1716+
async def get_billing(
1717+
self,
1718+
*,
1719+
project_id: Optional[str] = None,
1720+
) -> GetBillingResponse:
1721+
"""
1722+
Gives information on current edge-services subscription plan and used resources with associated price.
1723+
:param project_id:
1724+
:return: :class:`GetBillingResponse <GetBillingResponse>`
1725+
1726+
Usage:
1727+
::
1728+
1729+
result = await api.get_billing()
1730+
"""
1731+
1732+
param_project_id = validate_path_param(
1733+
"project_id", project_id or self.client.default_project_id
1734+
)
1735+
1736+
res = self._request(
1737+
"GET",
1738+
f"/edge-services/v1alpha1/billing/{param_project_id}",
1739+
)
1740+
1741+
self._throw_on_error(res)
1742+
return unmarshal_GetBillingResponse(res.json())

scaleway-async/scaleway_async/edge_services/v1alpha1/marshalling.py

Lines changed: 81 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
from dateutil import parser
66

77
from scaleway_core.profile import ProfileDefaults
8+
from scaleway_core.bridge import (
9+
unmarshal_Money,
10+
)
811
from scaleway_core.utils import (
912
OneOfPossibility,
1013
resolve_one_of,
@@ -24,11 +27,12 @@
2427
CheckDomainResponse,
2528
CheckLbOriginResponse,
2629
CheckPEMChainResponse,
30+
PlanDetails,
31+
GetBillingResponse,
2732
ListBackendStagesResponse,
2833
ListCacheStagesResponse,
2934
ListDNSStagesResponse,
3035
ListPipelinesResponse,
31-
PlanDetails,
3236
ListPlansResponse,
3337
ListPurgeRequestsResponse,
3438
ListTLSStagesResponse,
@@ -563,6 +567,82 @@ def unmarshal_CheckPEMChainResponse(data: Any) -> CheckPEMChainResponse:
563567
return CheckPEMChainResponse(**args)
564568

565569

570+
def unmarshal_PlanDetails(data: Any) -> PlanDetails:
571+
if not isinstance(data, dict):
572+
raise TypeError(
573+
"Unmarshalling the type 'PlanDetails' failed as data isn't a dictionary."
574+
)
575+
576+
args: Dict[str, Any] = {}
577+
578+
field = data.get("plan_name", None)
579+
if field is not None:
580+
args["plan_name"] = field
581+
582+
field = data.get("package_gb", None)
583+
if field is not None:
584+
args["package_gb"] = field
585+
586+
field = data.get("pipeline_limit", None)
587+
if field is not None:
588+
args["pipeline_limit"] = field
589+
590+
return PlanDetails(**args)
591+
592+
593+
def unmarshal_GetBillingResponse(data: Any) -> GetBillingResponse:
594+
if not isinstance(data, dict):
595+
raise TypeError(
596+
"Unmarshalling the type 'GetBillingResponse' failed as data isn't a dictionary."
597+
)
598+
599+
args: Dict[str, Any] = {}
600+
601+
field = data.get("pipeline_number", None)
602+
if field is not None:
603+
args["pipeline_number"] = field
604+
605+
field = data.get("current_plan_cache_usage", None)
606+
if field is not None:
607+
args["current_plan_cache_usage"] = field
608+
609+
field = data.get("extra_cache_usage", None)
610+
if field is not None:
611+
args["extra_cache_usage"] = field
612+
613+
field = data.get("current_plan", None)
614+
if field is not None:
615+
args["current_plan"] = unmarshal_PlanDetails(field)
616+
else:
617+
args["current_plan"] = None
618+
619+
field = data.get("plan_cost", None)
620+
if field is not None:
621+
args["plan_cost"] = unmarshal_Money(field)
622+
else:
623+
args["plan_cost"] = None
624+
625+
field = data.get("extra_pipelines_cost", None)
626+
if field is not None:
627+
args["extra_pipelines_cost"] = unmarshal_Money(field)
628+
else:
629+
args["extra_pipelines_cost"] = None
630+
631+
field = data.get("extra_cache_cost", None)
632+
if field is not None:
633+
args["extra_cache_cost"] = unmarshal_Money(field)
634+
else:
635+
args["extra_cache_cost"] = None
636+
637+
field = data.get("total_cost", None)
638+
if field is not None:
639+
args["total_cost"] = unmarshal_Money(field)
640+
else:
641+
args["total_cost"] = None
642+
643+
return GetBillingResponse(**args)
644+
645+
566646
def unmarshal_ListBackendStagesResponse(data: Any) -> ListBackendStagesResponse:
567647
if not isinstance(data, dict):
568648
raise TypeError(
@@ -647,29 +727,6 @@ def unmarshal_ListPipelinesResponse(data: Any) -> ListPipelinesResponse:
647727
return ListPipelinesResponse(**args)
648728

649729

650-
def unmarshal_PlanDetails(data: Any) -> PlanDetails:
651-
if not isinstance(data, dict):
652-
raise TypeError(
653-
"Unmarshalling the type 'PlanDetails' failed as data isn't a dictionary."
654-
)
655-
656-
args: Dict[str, Any] = {}
657-
658-
field = data.get("plan_name", None)
659-
if field is not None:
660-
args["plan_name"] = field
661-
662-
field = data.get("package_gb", None)
663-
if field is not None:
664-
args["package_gb"] = field
665-
666-
field = data.get("pipeline_limit", None)
667-
if field is not None:
668-
args["pipeline_limit"] = field
669-
670-
return PlanDetails(**args)
671-
672-
673730
def unmarshal_ListPlansResponse(data: Any) -> ListPlansResponse:
674731
if not isinstance(data, dict):
675732
raise TypeError(

scaleway-async/scaleway_async/edge_services/v1alpha1/types.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing import List, Optional
99

1010
from scaleway_core.bridge import (
11+
Money,
1112
Region,
1213
Zone,
1314
)
@@ -472,10 +473,19 @@ class CheckPEMChainRequestSecretChain:
472473
@dataclass
473474
class PlanDetails:
474475
plan_name: PlanName
476+
"""
477+
Subscription plan name.
478+
"""
475479

476480
package_gb: int
481+
"""
482+
Amount of egress data from cache included in subscription plan.
483+
"""
477484

478485
pipeline_limit: int
486+
"""
487+
Number of pipeline included in subscription plan.
488+
"""
479489

480490

481491
@dataclass
@@ -713,6 +723,54 @@ class GetBackendStageRequest:
713723
"""
714724

715725

726+
@dataclass
727+
class GetBillingRequest:
728+
project_id: Optional[str]
729+
730+
731+
@dataclass
732+
class GetBillingResponse:
733+
pipeline_number: int
734+
"""
735+
Total number of pipeline currently configured.
736+
"""
737+
738+
current_plan_cache_usage: int
739+
"""
740+
Total amount of data egressed from cache in current subscription plan.
741+
"""
742+
743+
extra_cache_usage: int
744+
"""
745+
Total amount of data egressed from cache not included in the plans.
746+
"""
747+
748+
current_plan: Optional[PlanDetails]
749+
"""
750+
Information on the current edge-service subscription plan.
751+
"""
752+
753+
plan_cost: Optional[Money]
754+
"""
755+
Price of the current subscription plan.
756+
"""
757+
758+
extra_pipelines_cost: Optional[Money]
759+
"""
760+
Cost to date of the pipelines not included in the plans.
761+
"""
762+
763+
extra_cache_cost: Optional[Money]
764+
"""
765+
Cost to date of the data egressed from cache not included in the plans.
766+
"""
767+
768+
total_cost: Optional[Money]
769+
"""
770+
Total cost to date of edge-service product for the month including current plan, previous plans, extra pipelines and extra egress cache data.
771+
"""
772+
773+
716774
@dataclass
717775
class GetCacheStageRequest:
718776
cache_stage_id: str

scaleway/scaleway/edge_services/v1alpha1/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
from .types import DeletePipelineRequest
5151
from .types import DeleteTLSStageRequest
5252
from .types import GetBackendStageRequest
53+
from .types import GetBillingRequest
54+
from .types import GetBillingResponse
5355
from .types import GetCacheStageRequest
5456
from .types import GetCurrentPlanRequest
5557
from .types import GetDNSStageRequest
@@ -129,6 +131,8 @@
129131
"DeletePipelineRequest",
130132
"DeleteTLSStageRequest",
131133
"GetBackendStageRequest",
134+
"GetBillingRequest",
135+
"GetBillingResponse",
132136
"GetCacheStageRequest",
133137
"GetCurrentPlanRequest",
134138
"GetDNSStageRequest",

scaleway/scaleway/edge_services/v1alpha1/api.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
CreatePurgeRequestRequest,
3535
CreateTLSStageRequest,
3636
DNSStage,
37+
GetBillingResponse,
3738
ListBackendStagesResponse,
3839
ListCacheStagesResponse,
3940
ListDNSStagesResponse,
@@ -71,6 +72,7 @@
7172
unmarshal_CheckDomainResponse,
7273
unmarshal_CheckLbOriginResponse,
7374
unmarshal_CheckPEMChainResponse,
75+
unmarshal_GetBillingResponse,
7476
unmarshal_ListBackendStagesResponse,
7577
unmarshal_ListCacheStagesResponse,
7678
unmarshal_ListDNSStagesResponse,
@@ -1706,3 +1708,31 @@ def delete_current_plan(
17061708
)
17071709

17081710
self._throw_on_error(res)
1711+
1712+
def get_billing(
1713+
self,
1714+
*,
1715+
project_id: Optional[str] = None,
1716+
) -> GetBillingResponse:
1717+
"""
1718+
Gives information on current edge-services subscription plan and used resources with associated price.
1719+
:param project_id:
1720+
:return: :class:`GetBillingResponse <GetBillingResponse>`
1721+
1722+
Usage:
1723+
::
1724+
1725+
result = api.get_billing()
1726+
"""
1727+
1728+
param_project_id = validate_path_param(
1729+
"project_id", project_id or self.client.default_project_id
1730+
)
1731+
1732+
res = self._request(
1733+
"GET",
1734+
f"/edge-services/v1alpha1/billing/{param_project_id}",
1735+
)
1736+
1737+
self._throw_on_error(res)
1738+
return unmarshal_GetBillingResponse(res.json())

0 commit comments

Comments
 (0)