Skip to content

Commit 48866fd

Browse files
authored
feat(webhosting): add control panel support in webhosting (#364)
1 parent 1fb03a2 commit 48866fd

File tree

8 files changed

+402
-0
lines changed

8 files changed

+402
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
from .types import ListOffersRequestOrderBy
1010
from .types import NameserverStatus
1111
from .types import OfferQuotaWarning
12+
from .types import ControlPanel
1213
from .types import DnsRecord
1314
from .types import DnsRecords
1415
from .types import Hosting
1516
from .types import HostingCpanelUrls
1617
from .types import HostingOption
18+
from .types import ListControlPanelsResponse
1719
from .types import ListHostingsResponse
1820
from .types import ListOffersResponse
1921
from .types import Nameserver
@@ -32,11 +34,13 @@
3234
"ListOffersRequestOrderBy",
3335
"NameserverStatus",
3436
"OfferQuotaWarning",
37+
"ControlPanel",
3538
"DnsRecord",
3639
"DnsRecords",
3740
"Hosting",
3841
"HostingCpanelUrls",
3942
"HostingOption",
43+
"ListControlPanelsResponse",
4044
"ListHostingsResponse",
4145
"ListOffersResponse",
4246
"Nameserver",

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
HostingStatus,
1818
ListHostingsRequestOrderBy,
1919
ListOffersRequestOrderBy,
20+
ControlPanel,
2021
DnsRecords,
2122
Hosting,
23+
ListControlPanelsResponse,
2224
ListHostingsResponse,
2325
ListOffersResponse,
2426
CreateHostingRequest,
@@ -32,6 +34,7 @@
3234
marshal_UpdateHostingRequest,
3335
unmarshal_Hosting,
3436
unmarshal_DnsRecords,
37+
unmarshal_ListControlPanelsResponse,
3538
unmarshal_ListHostingsResponse,
3639
unmarshal_ListOffersResponse,
3740
)
@@ -112,6 +115,7 @@ async def list_hostings(
112115
domain: Optional[str] = None,
113116
project_id: Optional[str] = None,
114117
organization_id: Optional[str] = None,
118+
control_panels: Optional[List[str]] = None,
115119
) -> ListHostingsResponse:
116120
"""
117121
List all Web Hosting plans.
@@ -125,6 +129,7 @@ async def list_hostings(
125129
:param domain: Domain to filter for, only Web Hosting plans associated with this domain will be returned.
126130
:param project_id: Project ID to filter for, only Web Hosting plans from this Project will be returned.
127131
:param organization_id: Organization ID to filter for, only Web Hosting plans from this Organization will be returned.
132+
:param control_panels: Name of the control panel to filter for, only Web Hosting plans from this control panel will be returned.
128133
:return: :class:`ListHostingsResponse <ListHostingsResponse>`
129134
130135
Usage:
@@ -141,6 +146,7 @@ async def list_hostings(
141146
"GET",
142147
f"/webhosting/v1alpha1/regions/{param_region}/hostings",
143148
params={
149+
"control_panels": control_panels,
144150
"domain": domain,
145151
"order_by": order_by,
146152
"organization_id": organization_id
@@ -168,6 +174,7 @@ async def list_hostings_all(
168174
domain: Optional[str] = None,
169175
project_id: Optional[str] = None,
170176
organization_id: Optional[str] = None,
177+
control_panels: Optional[List[str]] = None,
171178
) -> List[Hosting]:
172179
"""
173180
List all Web Hosting plans.
@@ -181,6 +188,7 @@ async def list_hostings_all(
181188
:param domain: Domain to filter for, only Web Hosting plans associated with this domain will be returned.
182189
:param project_id: Project ID to filter for, only Web Hosting plans from this Project will be returned.
183190
:param organization_id: Organization ID to filter for, only Web Hosting plans from this Organization will be returned.
191+
:param control_panels: Name of the control panel to filter for, only Web Hosting plans from this control panel will be returned.
184192
:return: :class:`List[ListHostingsResponse] <List[ListHostingsResponse]>`
185193
186194
Usage:
@@ -203,6 +211,7 @@ async def list_hostings_all(
203211
"domain": domain,
204212
"project_id": project_id,
205213
"organization_id": organization_id,
214+
"control_panels": control_panels,
206215
},
207216
)
208217

@@ -466,3 +475,72 @@ async def list_offers(
466475

467476
self._throw_on_error(res)
468477
return unmarshal_ListOffersResponse(res.json())
478+
479+
async def list_control_panels(
480+
self,
481+
*,
482+
region: Optional[Region] = None,
483+
page: Optional[int] = None,
484+
page_size: Optional[int] = None,
485+
) -> ListControlPanelsResponse:
486+
"""
487+
List all control panels type.
488+
List the control panels type: cpanel or plesk.
489+
:param region: Region to target. If none is passed will use default region from the config.
490+
:param page: Page number to return, from the paginated results (must be a positive integer).
491+
:param page_size: Number of control panels to return (must be a positive integer lower or equal to 100).
492+
:return: :class:`ListControlPanelsResponse <ListControlPanelsResponse>`
493+
494+
Usage:
495+
::
496+
497+
result = await api.list_control_panels()
498+
"""
499+
500+
param_region = validate_path_param(
501+
"region", region or self.client.default_region
502+
)
503+
504+
res = self._request(
505+
"GET",
506+
f"/webhosting/v1alpha1/regions/{param_region}/control-panels",
507+
params={
508+
"page": page,
509+
"page_size": page_size or self.client.default_page_size,
510+
},
511+
)
512+
513+
self._throw_on_error(res)
514+
return unmarshal_ListControlPanelsResponse(res.json())
515+
516+
async def list_control_panels_all(
517+
self,
518+
*,
519+
region: Optional[Region] = None,
520+
page: Optional[int] = None,
521+
page_size: Optional[int] = None,
522+
) -> List[ControlPanel]:
523+
"""
524+
List all control panels type.
525+
List the control panels type: cpanel or plesk.
526+
:param region: Region to target. If none is passed will use default region from the config.
527+
:param page: Page number to return, from the paginated results (must be a positive integer).
528+
:param page_size: Number of control panels to return (must be a positive integer lower or equal to 100).
529+
:return: :class:`List[ListControlPanelsResponse] <List[ListControlPanelsResponse]>`
530+
531+
Usage:
532+
::
533+
534+
result = await api.list_control_panels_all()
535+
"""
536+
537+
return await fetch_all_pages_async(
538+
type=ListControlPanelsResponse,
539+
key="control_panels",
540+
fetcher=self.list_control_panels,
541+
args={
542+
"region": region,
543+
"page": page,
544+
"page_size": page_size,
545+
},
546+
)

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
)
1010
from dateutil import parser
1111
from .types import (
12+
ControlPanel,
1213
DnsRecord,
1314
DnsRecords,
1415
Hosting,
1516
HostingCpanelUrls,
1617
HostingOption,
18+
ListControlPanelsResponse,
1719
ListHostingsResponse,
1820
ListOffersResponse,
1921
Nameserver,
@@ -99,6 +101,26 @@ def unmarshal_OfferProduct(data: Any) -> OfferProduct:
99101
return OfferProduct(**args)
100102

101103

104+
def unmarshal_ControlPanel(data: Any) -> ControlPanel:
105+
if type(data) is not dict:
106+
raise TypeError(
107+
f"Unmarshalling the type 'ControlPanel' failed as data isn't a dictionary."
108+
)
109+
110+
args: Dict[str, Any] = {}
111+
112+
field = data.get("available", None)
113+
args["available"] = field
114+
115+
field = data.get("logo_url", None)
116+
args["logo_url"] = field
117+
118+
field = data.get("name", None)
119+
args["name"] = field
120+
121+
return ControlPanel(**args)
122+
123+
102124
def unmarshal_DnsRecord(data: Any) -> DnsRecord:
103125
if type(data) is not dict:
104126
raise TypeError(
@@ -136,6 +158,9 @@ def unmarshal_Hosting(data: Any) -> Hosting:
136158

137159
args: Dict[str, Any] = {}
138160

161+
field = data.get("control_panel_name", None)
162+
args["control_panel_name"] = field
163+
139164
field = data.get("cpanel_urls", None)
140165
args["cpanel_urls"] = (
141166
unmarshal_HostingCpanelUrls(field) if field is not None else None
@@ -231,6 +256,9 @@ def unmarshal_Offer(data: Any) -> Offer:
231256
field = data.get("billing_operation_path", None)
232257
args["billing_operation_path"] = field
233258

259+
field = data.get("control_panel_name", None)
260+
args["control_panel_name"] = field
261+
234262
field = data.get("end_of_life", None)
235263
args["end_of_life"] = field
236264

@@ -273,6 +301,25 @@ def unmarshal_DnsRecords(data: Any) -> DnsRecords:
273301
return DnsRecords(**args)
274302

275303

304+
def unmarshal_ListControlPanelsResponse(data: Any) -> ListControlPanelsResponse:
305+
if type(data) is not dict:
306+
raise TypeError(
307+
f"Unmarshalling the type 'ListControlPanelsResponse' failed as data isn't a dictionary."
308+
)
309+
310+
args: Dict[str, Any] = {}
311+
312+
field = data.get("control_panels", None)
313+
args["control_panels"] = (
314+
[unmarshal_ControlPanel(v) for v in field] if field is not None else None
315+
)
316+
317+
field = data.get("total_count", None)
318+
args["total_count"] = field
319+
320+
return ListControlPanelsResponse(**args)
321+
322+
276323
def unmarshal_ListHostingsResponse(data: Any) -> ListHostingsResponse:
277324
if type(data) is not dict:
278325
raise TypeError(

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

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,28 @@ def __str__(self) -> str:
103103
return str(self.value)
104104

105105

106+
@dataclass
107+
class ControlPanel:
108+
"""
109+
Control panel.
110+
"""
111+
112+
name: str
113+
"""
114+
Control panel name.
115+
"""
116+
117+
available: bool
118+
"""
119+
Define if the control panel type is available to order.
120+
"""
121+
122+
logo_url: str
123+
"""
124+
URL of this control panel's logo.
125+
"""
126+
127+
106128
@dataclass
107129
class DnsRecord:
108130
"""
@@ -253,6 +275,11 @@ class Hosting:
253275
Indicates if the hosting offer has reached its end of life.
254276
"""
255277

278+
control_panel_name: str
279+
"""
280+
Name of the control panel.
281+
"""
282+
256283
region: Region
257284
"""
258285
Region where the Web Hosting plan is hosted.
@@ -283,6 +310,23 @@ class HostingOption:
283310
"""
284311

285312

313+
@dataclass
314+
class ListControlPanelsResponse:
315+
"""
316+
List control panels response.
317+
"""
318+
319+
total_count: int
320+
"""
321+
Number of control panels returned.
322+
"""
323+
324+
control_panels: List[ControlPanel]
325+
"""
326+
List of control panels.
327+
"""
328+
329+
286330
@dataclass
287331
class ListHostingsResponse:
288332
"""
@@ -375,6 +419,11 @@ class Offer:
375419
Indicates if the offer has reached its end of life.
376420
"""
377421

422+
control_panel_name: str
423+
"""
424+
Name of the control panel.
425+
"""
426+
378427

379428
@dataclass
380429
class OfferProduct:
@@ -518,6 +567,11 @@ class ListHostingsRequest:
518567
Organization ID to filter for, only Web Hosting plans from this Organization will be returned.
519568
"""
520569

570+
control_panels: Optional[List[str]]
571+
"""
572+
Name of the control panel to filter for, only Web Hosting plans from this control panel will be returned.
573+
"""
574+
521575

522576
@dataclass
523577
class GetHostingRequest:
@@ -630,3 +684,21 @@ class ListOffersRequest:
630684
"""
631685
ID of a Web Hosting plan, to check compatibility with returned offers (in case of wanting to update the plan).
632686
"""
687+
688+
689+
@dataclass
690+
class ListControlPanelsRequest:
691+
region: Optional[Region]
692+
"""
693+
Region to target. If none is passed will use default region from the config.
694+
"""
695+
696+
page: Optional[int]
697+
"""
698+
Page number to return, from the paginated results (must be a positive integer).
699+
"""
700+
701+
page_size: Optional[int]
702+
"""
703+
Number of control panels to return (must be a positive integer lower or equal to 100).
704+
"""

scaleway/scaleway/webhosting/v1alpha1/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
from .types import ListOffersRequestOrderBy
1010
from .types import NameserverStatus
1111
from .types import OfferQuotaWarning
12+
from .types import ControlPanel
1213
from .types import DnsRecord
1314
from .types import DnsRecords
1415
from .types import Hosting
1516
from .types import HostingCpanelUrls
1617
from .types import HostingOption
18+
from .types import ListControlPanelsResponse
1719
from .types import ListHostingsResponse
1820
from .types import ListOffersResponse
1921
from .types import Nameserver
@@ -32,11 +34,13 @@
3234
"ListOffersRequestOrderBy",
3335
"NameserverStatus",
3436
"OfferQuotaWarning",
37+
"ControlPanel",
3538
"DnsRecord",
3639
"DnsRecords",
3740
"Hosting",
3841
"HostingCpanelUrls",
3942
"HostingOption",
43+
"ListControlPanelsResponse",
4044
"ListHostingsResponse",
4145
"ListOffersResponse",
4246
"Nameserver",

0 commit comments

Comments
 (0)