Skip to content

feat(webhosting): add hosting resource summary #751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2024
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
4 changes: 4 additions & 0 deletions scaleway-async/scaleway_async/webhosting/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from .types import HostingApiCreateSessionRequest
from .types import HostingApiDeleteHostingRequest
from .types import HostingApiGetHostingRequest
from .types import HostingApiGetResourceSummaryRequest
from .types import HostingApiListHostingsRequest
from .types import HostingApiResetHostingPasswordRequest
from .types import HostingApiUpdateHostingRequest
Expand All @@ -65,6 +66,7 @@
from .types import MailAccountApiRemoveMailAccountRequest
from .types import OfferApiListOffersRequest
from .types import ResetHostingPasswordResponse
from .types import ResourceSummary
from .types import Session
from .types import WebsiteApiListWebsitesRequest
from .api import WebhostingV1ControlPanelAPI
Expand Down Expand Up @@ -124,6 +126,7 @@
"HostingApiCreateSessionRequest",
"HostingApiDeleteHostingRequest",
"HostingApiGetHostingRequest",
"HostingApiGetResourceSummaryRequest",
"HostingApiListHostingsRequest",
"HostingApiResetHostingPasswordRequest",
"HostingApiUpdateHostingRequest",
Expand All @@ -141,6 +144,7 @@
"MailAccountApiRemoveMailAccountRequest",
"OfferApiListOffersRequest",
"ResetHostingPasswordResponse",
"ResourceSummary",
"Session",
"WebsiteApiListWebsitesRequest",
"WebhostingV1ControlPanelAPI",
Expand Down
35 changes: 35 additions & 0 deletions scaleway-async/scaleway_async/webhosting/v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
Offer,
OfferOptionRequest,
ResetHostingPasswordResponse,
ResourceSummary,
Session,
Website,
)
Expand All @@ -74,6 +75,7 @@
unmarshal_ListOffersResponse,
unmarshal_ListWebsitesResponse,
unmarshal_ResetHostingPasswordResponse,
unmarshal_ResourceSummary,
unmarshal_Session,
marshal_DatabaseApiAssignDatabaseUserRequest,
marshal_DatabaseApiChangeDatabaseUserPasswordRequest,
Expand Down Expand Up @@ -1228,6 +1230,39 @@ async def reset_hosting_password(
self._throw_on_error(res)
return unmarshal_ResetHostingPasswordResponse(res.json())

async def get_resource_summary(
self,
*,
hosting_id: str,
region: Optional[Region] = None,
) -> ResourceSummary:
"""
Get the total counts of websites, databases, email accounts, and FTP accounts of a Web Hosting plan.
:param hosting_id: Hosting ID.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`ResourceSummary <ResourceSummary>`

Usage:
::

result = await api.get_resource_summary(
hosting_id="example",
)
"""

param_region = validate_path_param(
"region", region or self.client.default_region
)
param_hosting_id = validate_path_param("hosting_id", hosting_id)

res = self._request(
"GET",
f"/webhosting/v1/regions/{param_region}/hostings/{param_hosting_id}/resource-summary",
)

self._throw_on_error(res)
return unmarshal_ResourceSummary(res.json())


class WebhostingV1FtpAccountAPI(API):
"""
Expand Down
28 changes: 28 additions & 0 deletions scaleway-async/scaleway_async/webhosting/v1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
Website,
ListWebsitesResponse,
ResetHostingPasswordResponse,
ResourceSummary,
Session,
DatabaseApiAssignDatabaseUserRequest,
DatabaseApiChangeDatabaseUserPasswordRequest,
Expand Down Expand Up @@ -642,6 +643,33 @@ def unmarshal_ResetHostingPasswordResponse(data: Any) -> ResetHostingPasswordRes
return ResetHostingPasswordResponse(**args)


def unmarshal_ResourceSummary(data: Any) -> ResourceSummary:
if not isinstance(data, dict):
raise TypeError(
"Unmarshalling the type 'ResourceSummary' failed as data isn't a dictionary."
)

args: Dict[str, Any] = {}

field = data.get("databases_count", None)
if field is not None:
args["databases_count"] = field

field = data.get("mail_accounts_count", None)
if field is not None:
args["mail_accounts_count"] = field

field = data.get("ftp_accounts_count", None)
if field is not None:
args["ftp_accounts_count"] = field

field = data.get("websites_count", None)
if field is not None:
args["websites_count"] = field

return ResourceSummary(**args)


def unmarshal_Session(data: Any) -> Session:
if not isinstance(data, dict):
raise TypeError(
Expand Down
36 changes: 36 additions & 0 deletions scaleway-async/scaleway_async/webhosting/v1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,19 @@ class HostingApiGetHostingRequest:
"""


@dataclass
class HostingApiGetResourceSummaryRequest:
hosting_id: str
"""
Hosting ID.
"""

region: Optional[Region]
"""
Region to target. If none is passed will use default region from the config.
"""


@dataclass
class HostingApiListHostingsRequest:
region: Optional[Region]
Expand Down Expand Up @@ -1324,6 +1337,29 @@ class ResetHostingPasswordResponse:
"""


@dataclass
class ResourceSummary:
databases_count: int
"""
Total number of active databases in the Web Hosting plan.
"""

mail_accounts_count: int
"""
Total number of active email accounts in the Web Hosting plan.
"""

ftp_accounts_count: int
"""
Total number of active FTP accounts in the Web Hosting plan.
"""

websites_count: int
"""
Total number of active domains in the the Web Hosting plan.
"""


@dataclass
class Session:
url: str
Expand Down
4 changes: 4 additions & 0 deletions scaleway/scaleway/webhosting/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from .types import HostingApiCreateSessionRequest
from .types import HostingApiDeleteHostingRequest
from .types import HostingApiGetHostingRequest
from .types import HostingApiGetResourceSummaryRequest
from .types import HostingApiListHostingsRequest
from .types import HostingApiResetHostingPasswordRequest
from .types import HostingApiUpdateHostingRequest
Expand All @@ -65,6 +66,7 @@
from .types import MailAccountApiRemoveMailAccountRequest
from .types import OfferApiListOffersRequest
from .types import ResetHostingPasswordResponse
from .types import ResourceSummary
from .types import Session
from .types import WebsiteApiListWebsitesRequest
from .api import WebhostingV1ControlPanelAPI
Expand Down Expand Up @@ -124,6 +126,7 @@
"HostingApiCreateSessionRequest",
"HostingApiDeleteHostingRequest",
"HostingApiGetHostingRequest",
"HostingApiGetResourceSummaryRequest",
"HostingApiListHostingsRequest",
"HostingApiResetHostingPasswordRequest",
"HostingApiUpdateHostingRequest",
Expand All @@ -141,6 +144,7 @@
"MailAccountApiRemoveMailAccountRequest",
"OfferApiListOffersRequest",
"ResetHostingPasswordResponse",
"ResourceSummary",
"Session",
"WebsiteApiListWebsitesRequest",
"WebhostingV1ControlPanelAPI",
Expand Down
35 changes: 35 additions & 0 deletions scaleway/scaleway/webhosting/v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
Offer,
OfferOptionRequest,
ResetHostingPasswordResponse,
ResourceSummary,
Session,
Website,
)
Expand All @@ -74,6 +75,7 @@
unmarshal_ListOffersResponse,
unmarshal_ListWebsitesResponse,
unmarshal_ResetHostingPasswordResponse,
unmarshal_ResourceSummary,
unmarshal_Session,
marshal_DatabaseApiAssignDatabaseUserRequest,
marshal_DatabaseApiChangeDatabaseUserPasswordRequest,
Expand Down Expand Up @@ -1228,6 +1230,39 @@ def reset_hosting_password(
self._throw_on_error(res)
return unmarshal_ResetHostingPasswordResponse(res.json())

def get_resource_summary(
self,
*,
hosting_id: str,
region: Optional[Region] = None,
) -> ResourceSummary:
"""
Get the total counts of websites, databases, email accounts, and FTP accounts of a Web Hosting plan.
:param hosting_id: Hosting ID.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`ResourceSummary <ResourceSummary>`

Usage:
::

result = api.get_resource_summary(
hosting_id="example",
)
"""

param_region = validate_path_param(
"region", region or self.client.default_region
)
param_hosting_id = validate_path_param("hosting_id", hosting_id)

res = self._request(
"GET",
f"/webhosting/v1/regions/{param_region}/hostings/{param_hosting_id}/resource-summary",
)

self._throw_on_error(res)
return unmarshal_ResourceSummary(res.json())


class WebhostingV1FtpAccountAPI(API):
"""
Expand Down
28 changes: 28 additions & 0 deletions scaleway/scaleway/webhosting/v1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
Website,
ListWebsitesResponse,
ResetHostingPasswordResponse,
ResourceSummary,
Session,
DatabaseApiAssignDatabaseUserRequest,
DatabaseApiChangeDatabaseUserPasswordRequest,
Expand Down Expand Up @@ -642,6 +643,33 @@ def unmarshal_ResetHostingPasswordResponse(data: Any) -> ResetHostingPasswordRes
return ResetHostingPasswordResponse(**args)


def unmarshal_ResourceSummary(data: Any) -> ResourceSummary:
if not isinstance(data, dict):
raise TypeError(
"Unmarshalling the type 'ResourceSummary' failed as data isn't a dictionary."
)

args: Dict[str, Any] = {}

field = data.get("databases_count", None)
if field is not None:
args["databases_count"] = field

field = data.get("mail_accounts_count", None)
if field is not None:
args["mail_accounts_count"] = field

field = data.get("ftp_accounts_count", None)
if field is not None:
args["ftp_accounts_count"] = field

field = data.get("websites_count", None)
if field is not None:
args["websites_count"] = field

return ResourceSummary(**args)


def unmarshal_Session(data: Any) -> Session:
if not isinstance(data, dict):
raise TypeError(
Expand Down
36 changes: 36 additions & 0 deletions scaleway/scaleway/webhosting/v1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,19 @@ class HostingApiGetHostingRequest:
"""


@dataclass
class HostingApiGetResourceSummaryRequest:
hosting_id: str
"""
Hosting ID.
"""

region: Optional[Region]
"""
Region to target. If none is passed will use default region from the config.
"""


@dataclass
class HostingApiListHostingsRequest:
region: Optional[Region]
Expand Down Expand Up @@ -1324,6 +1337,29 @@ class ResetHostingPasswordResponse:
"""


@dataclass
class ResourceSummary:
databases_count: int
"""
Total number of active databases in the Web Hosting plan.
"""

mail_accounts_count: int
"""
Total number of active email accounts in the Web Hosting plan.
"""

ftp_accounts_count: int
"""
Total number of active FTP accounts in the Web Hosting plan.
"""

websites_count: int
"""
Total number of active domains in the the Web Hosting plan.
"""


@dataclass
class Session:
url: str
Expand Down