Skip to content

Commit 860d513

Browse files
authored
feat(webhosting): add hosting resource summary (#751)
1 parent bfff0e2 commit 860d513

File tree

8 files changed

+206
-0
lines changed

8 files changed

+206
-0
lines changed

scaleway-async/scaleway_async/webhosting/v1/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from .types import HostingApiCreateSessionRequest
4949
from .types import HostingApiDeleteHostingRequest
5050
from .types import HostingApiGetHostingRequest
51+
from .types import HostingApiGetResourceSummaryRequest
5152
from .types import HostingApiListHostingsRequest
5253
from .types import HostingApiResetHostingPasswordRequest
5354
from .types import HostingApiUpdateHostingRequest
@@ -65,6 +66,7 @@
6566
from .types import MailAccountApiRemoveMailAccountRequest
6667
from .types import OfferApiListOffersRequest
6768
from .types import ResetHostingPasswordResponse
69+
from .types import ResourceSummary
6870
from .types import Session
6971
from .types import WebsiteApiListWebsitesRequest
7072
from .api import WebhostingV1ControlPanelAPI
@@ -124,6 +126,7 @@
124126
"HostingApiCreateSessionRequest",
125127
"HostingApiDeleteHostingRequest",
126128
"HostingApiGetHostingRequest",
129+
"HostingApiGetResourceSummaryRequest",
127130
"HostingApiListHostingsRequest",
128131
"HostingApiResetHostingPasswordRequest",
129132
"HostingApiUpdateHostingRequest",
@@ -141,6 +144,7 @@
141144
"MailAccountApiRemoveMailAccountRequest",
142145
"OfferApiListOffersRequest",
143146
"ResetHostingPasswordResponse",
147+
"ResourceSummary",
144148
"Session",
145149
"WebsiteApiListWebsitesRequest",
146150
"WebhostingV1ControlPanelAPI",

scaleway-async/scaleway_async/webhosting/v1/api.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
Offer,
5454
OfferOptionRequest,
5555
ResetHostingPasswordResponse,
56+
ResourceSummary,
5657
Session,
5758
Website,
5859
)
@@ -74,6 +75,7 @@
7475
unmarshal_ListOffersResponse,
7576
unmarshal_ListWebsitesResponse,
7677
unmarshal_ResetHostingPasswordResponse,
78+
unmarshal_ResourceSummary,
7779
unmarshal_Session,
7880
marshal_DatabaseApiAssignDatabaseUserRequest,
7981
marshal_DatabaseApiChangeDatabaseUserPasswordRequest,
@@ -1228,6 +1230,39 @@ async def reset_hosting_password(
12281230
self._throw_on_error(res)
12291231
return unmarshal_ResetHostingPasswordResponse(res.json())
12301232

1233+
async def get_resource_summary(
1234+
self,
1235+
*,
1236+
hosting_id: str,
1237+
region: Optional[Region] = None,
1238+
) -> ResourceSummary:
1239+
"""
1240+
Get the total counts of websites, databases, email accounts, and FTP accounts of a Web Hosting plan.
1241+
:param hosting_id: Hosting ID.
1242+
:param region: Region to target. If none is passed will use default region from the config.
1243+
:return: :class:`ResourceSummary <ResourceSummary>`
1244+
1245+
Usage:
1246+
::
1247+
1248+
result = await api.get_resource_summary(
1249+
hosting_id="example",
1250+
)
1251+
"""
1252+
1253+
param_region = validate_path_param(
1254+
"region", region or self.client.default_region
1255+
)
1256+
param_hosting_id = validate_path_param("hosting_id", hosting_id)
1257+
1258+
res = self._request(
1259+
"GET",
1260+
f"/webhosting/v1/regions/{param_region}/hostings/{param_hosting_id}/resource-summary",
1261+
)
1262+
1263+
self._throw_on_error(res)
1264+
return unmarshal_ResourceSummary(res.json())
1265+
12311266

12321267
class WebhostingV1FtpAccountAPI(API):
12331268
"""

scaleway-async/scaleway_async/webhosting/v1/marshalling.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
Website,
3131
ListWebsitesResponse,
3232
ResetHostingPasswordResponse,
33+
ResourceSummary,
3334
Session,
3435
DatabaseApiAssignDatabaseUserRequest,
3536
DatabaseApiChangeDatabaseUserPasswordRequest,
@@ -642,6 +643,33 @@ def unmarshal_ResetHostingPasswordResponse(data: Any) -> ResetHostingPasswordRes
642643
return ResetHostingPasswordResponse(**args)
643644

644645

646+
def unmarshal_ResourceSummary(data: Any) -> ResourceSummary:
647+
if not isinstance(data, dict):
648+
raise TypeError(
649+
"Unmarshalling the type 'ResourceSummary' failed as data isn't a dictionary."
650+
)
651+
652+
args: Dict[str, Any] = {}
653+
654+
field = data.get("databases_count", None)
655+
if field is not None:
656+
args["databases_count"] = field
657+
658+
field = data.get("mail_accounts_count", None)
659+
if field is not None:
660+
args["mail_accounts_count"] = field
661+
662+
field = data.get("ftp_accounts_count", None)
663+
if field is not None:
664+
args["ftp_accounts_count"] = field
665+
666+
field = data.get("websites_count", None)
667+
if field is not None:
668+
args["websites_count"] = field
669+
670+
return ResourceSummary(**args)
671+
672+
645673
def unmarshal_Session(data: Any) -> Session:
646674
if not isinstance(data, dict):
647675
raise TypeError(

scaleway-async/scaleway_async/webhosting/v1/types.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,19 @@ class HostingApiGetHostingRequest:
963963
"""
964964

965965

966+
@dataclass
967+
class HostingApiGetResourceSummaryRequest:
968+
hosting_id: str
969+
"""
970+
Hosting ID.
971+
"""
972+
973+
region: Optional[Region]
974+
"""
975+
Region to target. If none is passed will use default region from the config.
976+
"""
977+
978+
966979
@dataclass
967980
class HostingApiListHostingsRequest:
968981
region: Optional[Region]
@@ -1324,6 +1337,29 @@ class ResetHostingPasswordResponse:
13241337
"""
13251338

13261339

1340+
@dataclass
1341+
class ResourceSummary:
1342+
databases_count: int
1343+
"""
1344+
Total number of active databases in the Web Hosting plan.
1345+
"""
1346+
1347+
mail_accounts_count: int
1348+
"""
1349+
Total number of active email accounts in the Web Hosting plan.
1350+
"""
1351+
1352+
ftp_accounts_count: int
1353+
"""
1354+
Total number of active FTP accounts in the Web Hosting plan.
1355+
"""
1356+
1357+
websites_count: int
1358+
"""
1359+
Total number of active domains in the the Web Hosting plan.
1360+
"""
1361+
1362+
13271363
@dataclass
13281364
class Session:
13291365
url: str

scaleway/scaleway/webhosting/v1/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from .types import HostingApiCreateSessionRequest
4949
from .types import HostingApiDeleteHostingRequest
5050
from .types import HostingApiGetHostingRequest
51+
from .types import HostingApiGetResourceSummaryRequest
5152
from .types import HostingApiListHostingsRequest
5253
from .types import HostingApiResetHostingPasswordRequest
5354
from .types import HostingApiUpdateHostingRequest
@@ -65,6 +66,7 @@
6566
from .types import MailAccountApiRemoveMailAccountRequest
6667
from .types import OfferApiListOffersRequest
6768
from .types import ResetHostingPasswordResponse
69+
from .types import ResourceSummary
6870
from .types import Session
6971
from .types import WebsiteApiListWebsitesRequest
7072
from .api import WebhostingV1ControlPanelAPI
@@ -124,6 +126,7 @@
124126
"HostingApiCreateSessionRequest",
125127
"HostingApiDeleteHostingRequest",
126128
"HostingApiGetHostingRequest",
129+
"HostingApiGetResourceSummaryRequest",
127130
"HostingApiListHostingsRequest",
128131
"HostingApiResetHostingPasswordRequest",
129132
"HostingApiUpdateHostingRequest",
@@ -141,6 +144,7 @@
141144
"MailAccountApiRemoveMailAccountRequest",
142145
"OfferApiListOffersRequest",
143146
"ResetHostingPasswordResponse",
147+
"ResourceSummary",
144148
"Session",
145149
"WebsiteApiListWebsitesRequest",
146150
"WebhostingV1ControlPanelAPI",

scaleway/scaleway/webhosting/v1/api.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
Offer,
5454
OfferOptionRequest,
5555
ResetHostingPasswordResponse,
56+
ResourceSummary,
5657
Session,
5758
Website,
5859
)
@@ -74,6 +75,7 @@
7475
unmarshal_ListOffersResponse,
7576
unmarshal_ListWebsitesResponse,
7677
unmarshal_ResetHostingPasswordResponse,
78+
unmarshal_ResourceSummary,
7779
unmarshal_Session,
7880
marshal_DatabaseApiAssignDatabaseUserRequest,
7981
marshal_DatabaseApiChangeDatabaseUserPasswordRequest,
@@ -1228,6 +1230,39 @@ def reset_hosting_password(
12281230
self._throw_on_error(res)
12291231
return unmarshal_ResetHostingPasswordResponse(res.json())
12301232

1233+
def get_resource_summary(
1234+
self,
1235+
*,
1236+
hosting_id: str,
1237+
region: Optional[Region] = None,
1238+
) -> ResourceSummary:
1239+
"""
1240+
Get the total counts of websites, databases, email accounts, and FTP accounts of a Web Hosting plan.
1241+
:param hosting_id: Hosting ID.
1242+
:param region: Region to target. If none is passed will use default region from the config.
1243+
:return: :class:`ResourceSummary <ResourceSummary>`
1244+
1245+
Usage:
1246+
::
1247+
1248+
result = api.get_resource_summary(
1249+
hosting_id="example",
1250+
)
1251+
"""
1252+
1253+
param_region = validate_path_param(
1254+
"region", region or self.client.default_region
1255+
)
1256+
param_hosting_id = validate_path_param("hosting_id", hosting_id)
1257+
1258+
res = self._request(
1259+
"GET",
1260+
f"/webhosting/v1/regions/{param_region}/hostings/{param_hosting_id}/resource-summary",
1261+
)
1262+
1263+
self._throw_on_error(res)
1264+
return unmarshal_ResourceSummary(res.json())
1265+
12311266

12321267
class WebhostingV1FtpAccountAPI(API):
12331268
"""

scaleway/scaleway/webhosting/v1/marshalling.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
Website,
3131
ListWebsitesResponse,
3232
ResetHostingPasswordResponse,
33+
ResourceSummary,
3334
Session,
3435
DatabaseApiAssignDatabaseUserRequest,
3536
DatabaseApiChangeDatabaseUserPasswordRequest,
@@ -642,6 +643,33 @@ def unmarshal_ResetHostingPasswordResponse(data: Any) -> ResetHostingPasswordRes
642643
return ResetHostingPasswordResponse(**args)
643644

644645

646+
def unmarshal_ResourceSummary(data: Any) -> ResourceSummary:
647+
if not isinstance(data, dict):
648+
raise TypeError(
649+
"Unmarshalling the type 'ResourceSummary' failed as data isn't a dictionary."
650+
)
651+
652+
args: Dict[str, Any] = {}
653+
654+
field = data.get("databases_count", None)
655+
if field is not None:
656+
args["databases_count"] = field
657+
658+
field = data.get("mail_accounts_count", None)
659+
if field is not None:
660+
args["mail_accounts_count"] = field
661+
662+
field = data.get("ftp_accounts_count", None)
663+
if field is not None:
664+
args["ftp_accounts_count"] = field
665+
666+
field = data.get("websites_count", None)
667+
if field is not None:
668+
args["websites_count"] = field
669+
670+
return ResourceSummary(**args)
671+
672+
645673
def unmarshal_Session(data: Any) -> Session:
646674
if not isinstance(data, dict):
647675
raise TypeError(

scaleway/scaleway/webhosting/v1/types.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,19 @@ class HostingApiGetHostingRequest:
963963
"""
964964

965965

966+
@dataclass
967+
class HostingApiGetResourceSummaryRequest:
968+
hosting_id: str
969+
"""
970+
Hosting ID.
971+
"""
972+
973+
region: Optional[Region]
974+
"""
975+
Region to target. If none is passed will use default region from the config.
976+
"""
977+
978+
966979
@dataclass
967980
class HostingApiListHostingsRequest:
968981
region: Optional[Region]
@@ -1324,6 +1337,29 @@ class ResetHostingPasswordResponse:
13241337
"""
13251338

13261339

1340+
@dataclass
1341+
class ResourceSummary:
1342+
databases_count: int
1343+
"""
1344+
Total number of active databases in the Web Hosting plan.
1345+
"""
1346+
1347+
mail_accounts_count: int
1348+
"""
1349+
Total number of active email accounts in the Web Hosting plan.
1350+
"""
1351+
1352+
ftp_accounts_count: int
1353+
"""
1354+
Total number of active FTP accounts in the Web Hosting plan.
1355+
"""
1356+
1357+
websites_count: int
1358+
"""
1359+
Total number of active domains in the the Web Hosting plan.
1360+
"""
1361+
1362+
13271363
@dataclass
13281364
class Session:
13291365
url: str

0 commit comments

Comments
 (0)