Skip to content

Commit 832b6fc

Browse files
authored
feat(mongodb): add Create Endpoint Endpoint (#754)
1 parent 3803290 commit 832b6fc

File tree

8 files changed

+218
-50
lines changed

8 files changed

+218
-50
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
from .types import NodeTypeVolumeType
2121
from .types import SnapshotVolumeType
2222
from .types import Setting
23-
from .types import CreateInstanceRequestVolumeDetails
2423
from .types import EndpointSpec
24+
from .types import CreateInstanceRequestVolumeDetails
2525
from .types import Instance
2626
from .types import NodeType
2727
from .types import Snapshot
2828
from .types import User
2929
from .types import Version
3030
from .types import RestoreSnapshotRequestVolumeDetails
31+
from .types import CreateEndpointRequest
3132
from .types import CreateInstanceRequest
3233
from .types import CreateSnapshotRequest
3334
from .types import CreateUserRequest
@@ -75,14 +76,15 @@
7576
"NodeTypeVolumeType",
7677
"SnapshotVolumeType",
7778
"Setting",
78-
"CreateInstanceRequestVolumeDetails",
7979
"EndpointSpec",
80+
"CreateInstanceRequestVolumeDetails",
8081
"Instance",
8182
"NodeType",
8283
"Snapshot",
8384
"User",
8485
"Version",
8586
"RestoreSnapshotRequestVolumeDetails",
87+
"CreateEndpointRequest",
8688
"CreateInstanceRequest",
8789
"CreateSnapshotRequest",
8890
"CreateUserRequest",

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
ListInstancesRequestOrderBy,
2222
ListSnapshotsRequestOrderBy,
2323
ListUsersRequestOrderBy,
24+
CreateEndpointRequest,
2425
CreateInstanceRequest,
2526
CreateInstanceRequestVolumeDetails,
2627
CreateSnapshotRequest,
2728
CreateUserRequest,
29+
Endpoint,
2830
EndpointSpec,
2931
Instance,
3032
ListInstancesResponse,
@@ -48,6 +50,7 @@
4850
SNAPSHOT_TRANSIENT_STATUSES,
4951
)
5052
from .marshalling import (
53+
unmarshal_Endpoint,
5154
unmarshal_Instance,
5255
unmarshal_Snapshot,
5356
unmarshal_User,
@@ -56,6 +59,7 @@
5659
unmarshal_ListSnapshotsResponse,
5760
unmarshal_ListUsersResponse,
5861
unmarshal_ListVersionsResponse,
62+
marshal_CreateEndpointRequest,
5963
marshal_CreateInstanceRequest,
6064
marshal_CreateSnapshotRequest,
6165
marshal_CreateUserRequest,
@@ -1201,3 +1205,47 @@ async def delete_endpoint(
12011205
)
12021206

12031207
self._throw_on_error(res)
1208+
1209+
async def create_endpoint(
1210+
self,
1211+
*,
1212+
instance_id: str,
1213+
endpoint: EndpointSpec,
1214+
region: Optional[Region] = None,
1215+
) -> Endpoint:
1216+
"""
1217+
Create a new Instance endpoint.
1218+
Create a new endpoint for a MongoDB® Database Instance. You can add `public_network` or `private_network` specifications to the body of the request.
1219+
:param instance_id: UUID of the Database Instance.
1220+
:param endpoint: EndpointSpec used to expose your Database Instance.
1221+
:param region: Region to target. If none is passed will use default region from the config.
1222+
:return: :class:`Endpoint <Endpoint>`
1223+
1224+
Usage:
1225+
::
1226+
1227+
result = await api.create_endpoint(
1228+
instance_id="example",
1229+
endpoint=EndpointSpec(),
1230+
)
1231+
"""
1232+
1233+
param_region = validate_path_param(
1234+
"region", region or self.client.default_region
1235+
)
1236+
1237+
res = self._request(
1238+
"POST",
1239+
f"/mongodb/v1alpha1/regions/{param_region}/endpoints",
1240+
body=marshal_CreateEndpointRequest(
1241+
CreateEndpointRequest(
1242+
instance_id=instance_id,
1243+
endpoint=endpoint,
1244+
region=region,
1245+
),
1246+
self.client,
1247+
),
1248+
)
1249+
1250+
self._throw_on_error(res)
1251+
return unmarshal_Endpoint(res.json())

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

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
ListVersionsResponse,
3131
EndpointSpecPrivateNetworkDetails,
3232
EndpointSpecPublicDetails,
33-
CreateInstanceRequestVolumeDetails,
3433
EndpointSpec,
34+
CreateEndpointRequest,
35+
CreateInstanceRequestVolumeDetails,
3536
CreateInstanceRequest,
3637
CreateSnapshotRequest,
3738
CreateUserRequest,
@@ -619,21 +620,6 @@ def marshal_EndpointSpecPublicDetails(
619620
return output
620621

621622

622-
def marshal_CreateInstanceRequestVolumeDetails(
623-
request: CreateInstanceRequestVolumeDetails,
624-
defaults: ProfileDefaults,
625-
) -> Dict[str, Any]:
626-
output: Dict[str, Any] = {}
627-
628-
if request.volume_size is not None:
629-
output["volume_size"] = request.volume_size
630-
631-
if request.volume_type is not None:
632-
output["volume_type"] = str(request.volume_type)
633-
634-
return output
635-
636-
637623
def marshal_EndpointSpec(
638624
request: EndpointSpec,
639625
defaults: ProfileDefaults,
@@ -651,6 +637,36 @@ def marshal_EndpointSpec(
651637
return output
652638

653639

640+
def marshal_CreateEndpointRequest(
641+
request: CreateEndpointRequest,
642+
defaults: ProfileDefaults,
643+
) -> Dict[str, Any]:
644+
output: Dict[str, Any] = {}
645+
646+
if request.instance_id is not None:
647+
output["instance_id"] = request.instance_id
648+
649+
if request.endpoint is not None:
650+
output["endpoint"] = marshal_EndpointSpec(request.endpoint, defaults)
651+
652+
return output
653+
654+
655+
def marshal_CreateInstanceRequestVolumeDetails(
656+
request: CreateInstanceRequestVolumeDetails,
657+
defaults: ProfileDefaults,
658+
) -> Dict[str, Any]:
659+
output: Dict[str, Any] = {}
660+
661+
if request.volume_size is not None:
662+
output["volume_size"] = request.volume_size
663+
664+
if request.volume_type is not None:
665+
output["volume_type"] = str(request.volume_type)
666+
667+
return output
668+
669+
654670
def marshal_CreateInstanceRequest(
655671
request: CreateInstanceRequest,
656672
defaults: ProfileDefaults,

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,13 @@ class Setting:
278278
"""
279279

280280

281+
@dataclass
282+
class EndpointSpec:
283+
public: Optional[EndpointSpecPublicDetails]
284+
285+
private_network: Optional[EndpointSpecPrivateNetworkDetails]
286+
287+
281288
@dataclass
282289
class CreateInstanceRequestVolumeDetails:
283290
volume_size: int
@@ -291,13 +298,6 @@ class CreateInstanceRequestVolumeDetails:
291298
"""
292299

293300

294-
@dataclass
295-
class EndpointSpec:
296-
public: Optional[EndpointSpecPublicDetails]
297-
298-
private_network: Optional[EndpointSpecPrivateNetworkDetails]
299-
300-
301301
@dataclass
302302
class Instance:
303303
id: str
@@ -511,6 +511,24 @@ class RestoreSnapshotRequestVolumeDetails:
511511
"""
512512

513513

514+
@dataclass
515+
class CreateEndpointRequest:
516+
instance_id: str
517+
"""
518+
UUID of the Database Instance.
519+
"""
520+
521+
endpoint: EndpointSpec
522+
"""
523+
EndpointSpec used to expose your Database Instance.
524+
"""
525+
526+
region: Optional[Region]
527+
"""
528+
Region to target. If none is passed will use default region from the config.
529+
"""
530+
531+
514532
@dataclass
515533
class CreateInstanceRequest:
516534
version: str

scaleway/scaleway/mongodb/v1alpha1/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
from .types import NodeTypeVolumeType
2121
from .types import SnapshotVolumeType
2222
from .types import Setting
23-
from .types import CreateInstanceRequestVolumeDetails
2423
from .types import EndpointSpec
24+
from .types import CreateInstanceRequestVolumeDetails
2525
from .types import Instance
2626
from .types import NodeType
2727
from .types import Snapshot
2828
from .types import User
2929
from .types import Version
3030
from .types import RestoreSnapshotRequestVolumeDetails
31+
from .types import CreateEndpointRequest
3132
from .types import CreateInstanceRequest
3233
from .types import CreateSnapshotRequest
3334
from .types import CreateUserRequest
@@ -75,14 +76,15 @@
7576
"NodeTypeVolumeType",
7677
"SnapshotVolumeType",
7778
"Setting",
78-
"CreateInstanceRequestVolumeDetails",
7979
"EndpointSpec",
80+
"CreateInstanceRequestVolumeDetails",
8081
"Instance",
8182
"NodeType",
8283
"Snapshot",
8384
"User",
8485
"Version",
8586
"RestoreSnapshotRequestVolumeDetails",
87+
"CreateEndpointRequest",
8688
"CreateInstanceRequest",
8789
"CreateSnapshotRequest",
8890
"CreateUserRequest",

scaleway/scaleway/mongodb/v1alpha1/api.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
ListInstancesRequestOrderBy,
2222
ListSnapshotsRequestOrderBy,
2323
ListUsersRequestOrderBy,
24+
CreateEndpointRequest,
2425
CreateInstanceRequest,
2526
CreateInstanceRequestVolumeDetails,
2627
CreateSnapshotRequest,
2728
CreateUserRequest,
29+
Endpoint,
2830
EndpointSpec,
2931
Instance,
3032
ListInstancesResponse,
@@ -48,6 +50,7 @@
4850
SNAPSHOT_TRANSIENT_STATUSES,
4951
)
5052
from .marshalling import (
53+
unmarshal_Endpoint,
5154
unmarshal_Instance,
5255
unmarshal_Snapshot,
5356
unmarshal_User,
@@ -56,6 +59,7 @@
5659
unmarshal_ListSnapshotsResponse,
5760
unmarshal_ListUsersResponse,
5861
unmarshal_ListVersionsResponse,
62+
marshal_CreateEndpointRequest,
5963
marshal_CreateInstanceRequest,
6064
marshal_CreateSnapshotRequest,
6165
marshal_CreateUserRequest,
@@ -1197,3 +1201,47 @@ def delete_endpoint(
11971201
)
11981202

11991203
self._throw_on_error(res)
1204+
1205+
def create_endpoint(
1206+
self,
1207+
*,
1208+
instance_id: str,
1209+
endpoint: EndpointSpec,
1210+
region: Optional[Region] = None,
1211+
) -> Endpoint:
1212+
"""
1213+
Create a new Instance endpoint.
1214+
Create a new endpoint for a MongoDB® Database Instance. You can add `public_network` or `private_network` specifications to the body of the request.
1215+
:param instance_id: UUID of the Database Instance.
1216+
:param endpoint: EndpointSpec used to expose your Database Instance.
1217+
:param region: Region to target. If none is passed will use default region from the config.
1218+
:return: :class:`Endpoint <Endpoint>`
1219+
1220+
Usage:
1221+
::
1222+
1223+
result = api.create_endpoint(
1224+
instance_id="example",
1225+
endpoint=EndpointSpec(),
1226+
)
1227+
"""
1228+
1229+
param_region = validate_path_param(
1230+
"region", region or self.client.default_region
1231+
)
1232+
1233+
res = self._request(
1234+
"POST",
1235+
f"/mongodb/v1alpha1/regions/{param_region}/endpoints",
1236+
body=marshal_CreateEndpointRequest(
1237+
CreateEndpointRequest(
1238+
instance_id=instance_id,
1239+
endpoint=endpoint,
1240+
region=region,
1241+
),
1242+
self.client,
1243+
),
1244+
)
1245+
1246+
self._throw_on_error(res)
1247+
return unmarshal_Endpoint(res.json())

0 commit comments

Comments
 (0)