Skip to content
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

feat(mongodb): add Create Endpoint Endpoint #754

Merged
merged 1 commit into from
Nov 19, 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
6 changes: 4 additions & 2 deletions scaleway-async/scaleway_async/mongodb/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
from .types import NodeTypeVolumeType
from .types import SnapshotVolumeType
from .types import Setting
from .types import CreateInstanceRequestVolumeDetails
from .types import EndpointSpec
from .types import CreateInstanceRequestVolumeDetails
from .types import Instance
from .types import NodeType
from .types import Snapshot
from .types import User
from .types import Version
from .types import RestoreSnapshotRequestVolumeDetails
from .types import CreateEndpointRequest
from .types import CreateInstanceRequest
from .types import CreateSnapshotRequest
from .types import CreateUserRequest
Expand Down Expand Up @@ -75,14 +76,15 @@
"NodeTypeVolumeType",
"SnapshotVolumeType",
"Setting",
"CreateInstanceRequestVolumeDetails",
"EndpointSpec",
"CreateInstanceRequestVolumeDetails",
"Instance",
"NodeType",
"Snapshot",
"User",
"Version",
"RestoreSnapshotRequestVolumeDetails",
"CreateEndpointRequest",
"CreateInstanceRequest",
"CreateSnapshotRequest",
"CreateUserRequest",
Expand Down
48 changes: 48 additions & 0 deletions scaleway-async/scaleway_async/mongodb/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
ListInstancesRequestOrderBy,
ListSnapshotsRequestOrderBy,
ListUsersRequestOrderBy,
CreateEndpointRequest,
CreateInstanceRequest,
CreateInstanceRequestVolumeDetails,
CreateSnapshotRequest,
CreateUserRequest,
Endpoint,
EndpointSpec,
Instance,
ListInstancesResponse,
Expand All @@ -48,6 +50,7 @@
SNAPSHOT_TRANSIENT_STATUSES,
)
from .marshalling import (
unmarshal_Endpoint,
unmarshal_Instance,
unmarshal_Snapshot,
unmarshal_User,
Expand All @@ -56,6 +59,7 @@
unmarshal_ListSnapshotsResponse,
unmarshal_ListUsersResponse,
unmarshal_ListVersionsResponse,
marshal_CreateEndpointRequest,
marshal_CreateInstanceRequest,
marshal_CreateSnapshotRequest,
marshal_CreateUserRequest,
Expand Down Expand Up @@ -1201,3 +1205,47 @@ async def delete_endpoint(
)

self._throw_on_error(res)

async def create_endpoint(
self,
*,
instance_id: str,
endpoint: EndpointSpec,
region: Optional[Region] = None,
) -> Endpoint:
"""
Create a new Instance endpoint.
Create a new endpoint for a MongoDB® Database Instance. You can add `public_network` or `private_network` specifications to the body of the request.
:param instance_id: UUID of the Database Instance.
:param endpoint: EndpointSpec used to expose your Database Instance.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`Endpoint <Endpoint>`

Usage:
::

result = await api.create_endpoint(
instance_id="example",
endpoint=EndpointSpec(),
)
"""

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

res = self._request(
"POST",
f"/mongodb/v1alpha1/regions/{param_region}/endpoints",
body=marshal_CreateEndpointRequest(
CreateEndpointRequest(
instance_id=instance_id,
endpoint=endpoint,
region=region,
),
self.client,
),
)

self._throw_on_error(res)
return unmarshal_Endpoint(res.json())
48 changes: 32 additions & 16 deletions scaleway-async/scaleway_async/mongodb/v1alpha1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
ListVersionsResponse,
EndpointSpecPrivateNetworkDetails,
EndpointSpecPublicDetails,
CreateInstanceRequestVolumeDetails,
EndpointSpec,
CreateEndpointRequest,
CreateInstanceRequestVolumeDetails,
CreateInstanceRequest,
CreateSnapshotRequest,
CreateUserRequest,
Expand Down Expand Up @@ -619,21 +620,6 @@ def marshal_EndpointSpecPublicDetails(
return output


def marshal_CreateInstanceRequestVolumeDetails(
request: CreateInstanceRequestVolumeDetails,
defaults: ProfileDefaults,
) -> Dict[str, Any]:
output: Dict[str, Any] = {}

if request.volume_size is not None:
output["volume_size"] = request.volume_size

if request.volume_type is not None:
output["volume_type"] = str(request.volume_type)

return output


def marshal_EndpointSpec(
request: EndpointSpec,
defaults: ProfileDefaults,
Expand All @@ -651,6 +637,36 @@ def marshal_EndpointSpec(
return output


def marshal_CreateEndpointRequest(
request: CreateEndpointRequest,
defaults: ProfileDefaults,
) -> Dict[str, Any]:
output: Dict[str, Any] = {}

if request.instance_id is not None:
output["instance_id"] = request.instance_id

if request.endpoint is not None:
output["endpoint"] = marshal_EndpointSpec(request.endpoint, defaults)

return output


def marshal_CreateInstanceRequestVolumeDetails(
request: CreateInstanceRequestVolumeDetails,
defaults: ProfileDefaults,
) -> Dict[str, Any]:
output: Dict[str, Any] = {}

if request.volume_size is not None:
output["volume_size"] = request.volume_size

if request.volume_type is not None:
output["volume_type"] = str(request.volume_type)

return output


def marshal_CreateInstanceRequest(
request: CreateInstanceRequest,
defaults: ProfileDefaults,
Expand Down
32 changes: 25 additions & 7 deletions scaleway-async/scaleway_async/mongodb/v1alpha1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ class Setting:
"""


@dataclass
class EndpointSpec:
public: Optional[EndpointSpecPublicDetails]

private_network: Optional[EndpointSpecPrivateNetworkDetails]


@dataclass
class CreateInstanceRequestVolumeDetails:
volume_size: int
Expand All @@ -291,13 +298,6 @@ class CreateInstanceRequestVolumeDetails:
"""


@dataclass
class EndpointSpec:
public: Optional[EndpointSpecPublicDetails]

private_network: Optional[EndpointSpecPrivateNetworkDetails]


@dataclass
class Instance:
id: str
Expand Down Expand Up @@ -511,6 +511,24 @@ class RestoreSnapshotRequestVolumeDetails:
"""


@dataclass
class CreateEndpointRequest:
instance_id: str
"""
UUID of the Database Instance.
"""

endpoint: EndpointSpec
"""
EndpointSpec used to expose your Database Instance.
"""

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


@dataclass
class CreateInstanceRequest:
version: str
Expand Down
6 changes: 4 additions & 2 deletions scaleway/scaleway/mongodb/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
from .types import NodeTypeVolumeType
from .types import SnapshotVolumeType
from .types import Setting
from .types import CreateInstanceRequestVolumeDetails
from .types import EndpointSpec
from .types import CreateInstanceRequestVolumeDetails
from .types import Instance
from .types import NodeType
from .types import Snapshot
from .types import User
from .types import Version
from .types import RestoreSnapshotRequestVolumeDetails
from .types import CreateEndpointRequest
from .types import CreateInstanceRequest
from .types import CreateSnapshotRequest
from .types import CreateUserRequest
Expand Down Expand Up @@ -75,14 +76,15 @@
"NodeTypeVolumeType",
"SnapshotVolumeType",
"Setting",
"CreateInstanceRequestVolumeDetails",
"EndpointSpec",
"CreateInstanceRequestVolumeDetails",
"Instance",
"NodeType",
"Snapshot",
"User",
"Version",
"RestoreSnapshotRequestVolumeDetails",
"CreateEndpointRequest",
"CreateInstanceRequest",
"CreateSnapshotRequest",
"CreateUserRequest",
Expand Down
48 changes: 48 additions & 0 deletions scaleway/scaleway/mongodb/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
ListInstancesRequestOrderBy,
ListSnapshotsRequestOrderBy,
ListUsersRequestOrderBy,
CreateEndpointRequest,
CreateInstanceRequest,
CreateInstanceRequestVolumeDetails,
CreateSnapshotRequest,
CreateUserRequest,
Endpoint,
EndpointSpec,
Instance,
ListInstancesResponse,
Expand All @@ -48,6 +50,7 @@
SNAPSHOT_TRANSIENT_STATUSES,
)
from .marshalling import (
unmarshal_Endpoint,
unmarshal_Instance,
unmarshal_Snapshot,
unmarshal_User,
Expand All @@ -56,6 +59,7 @@
unmarshal_ListSnapshotsResponse,
unmarshal_ListUsersResponse,
unmarshal_ListVersionsResponse,
marshal_CreateEndpointRequest,
marshal_CreateInstanceRequest,
marshal_CreateSnapshotRequest,
marshal_CreateUserRequest,
Expand Down Expand Up @@ -1197,3 +1201,47 @@ def delete_endpoint(
)

self._throw_on_error(res)

def create_endpoint(
self,
*,
instance_id: str,
endpoint: EndpointSpec,
region: Optional[Region] = None,
) -> Endpoint:
"""
Create a new Instance endpoint.
Create a new endpoint for a MongoDB® Database Instance. You can add `public_network` or `private_network` specifications to the body of the request.
:param instance_id: UUID of the Database Instance.
:param endpoint: EndpointSpec used to expose your Database Instance.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`Endpoint <Endpoint>`

Usage:
::

result = api.create_endpoint(
instance_id="example",
endpoint=EndpointSpec(),
)
"""

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

res = self._request(
"POST",
f"/mongodb/v1alpha1/regions/{param_region}/endpoints",
body=marshal_CreateEndpointRequest(
CreateEndpointRequest(
instance_id=instance_id,
endpoint=endpoint,
region=region,
),
self.client,
),
)

self._throw_on_error(res)
return unmarshal_Endpoint(res.json())
Loading