Skip to content

Commit 32ad9a2

Browse files
authored
feat(rdb): promote read replica (#263)
1 parent c2909b1 commit 32ad9a2

File tree

6 files changed

+94
-0
lines changed

6 files changed

+94
-0
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,38 @@ async def reset_read_replica(
14941494
self._throw_on_error(res)
14951495
return unmarshal_ReadReplica(res.json())
14961496

1497+
async def promote_read_replica(
1498+
self,
1499+
*,
1500+
read_replica_id: str,
1501+
region: Optional[Region] = None,
1502+
) -> Instance:
1503+
"""
1504+
Promote a Read Replica.
1505+
Promote a Read Replica to Database Instance automatically.
1506+
:param region: Region to target. If none is passed will use default region from the config.
1507+
:param read_replica_id: UUID of the Read Replica.
1508+
:return: :class:`Instance <Instance>`
1509+
1510+
Usage:
1511+
::
1512+
1513+
result = await api.promote_read_replica(read_replica_id="example")
1514+
"""
1515+
1516+
param_region = validate_path_param(
1517+
"region", region or self.client.default_region
1518+
)
1519+
param_read_replica_id = validate_path_param("read_replica_id", read_replica_id)
1520+
1521+
res = self._request(
1522+
"POST",
1523+
f"/rdb/v1/regions/{param_region}/read-replicas/{param_read_replica_id}/promote",
1524+
)
1525+
1526+
self._throw_on_error(res)
1527+
return unmarshal_Instance(res.json())
1528+
14971529
async def create_read_replica_endpoint(
14981530
self,
14991531
*,

scaleway-async/scaleway_async/rdb/v1/content.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
ReadReplicaStatus.INITIALIZING,
5656
ReadReplicaStatus.DELETING,
5757
ReadReplicaStatus.CONFIGURING,
58+
ReadReplicaStatus.PROMOTING,
5859
]
5960
"""
6061
Lists transient statutes of the enum :class:`ReadReplicaStatus <ReadReplicaStatus>`.

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ class ReadReplicaStatus(str, Enum):
220220
ERROR = "error"
221221
LOCKED = "locked"
222222
CONFIGURING = "configuring"
223+
PROMOTING = "promoting"
223224

224225
def __str__(self) -> str:
225226
return str(self.value)
@@ -2105,6 +2106,19 @@ class ResetReadReplicaRequest:
21052106
"""
21062107

21072108

2109+
@dataclass
2110+
class PromoteReadReplicaRequest:
2111+
region: Optional[Region]
2112+
"""
2113+
Region to target. If none is passed will use default region from the config.
2114+
"""
2115+
2116+
read_replica_id: str
2117+
"""
2118+
UUID of the Read Replica.
2119+
"""
2120+
2121+
21082122
@dataclass
21092123
class CreateReadReplicaEndpointRequest:
21102124
region: Optional[Region]

scaleway/scaleway/rdb/v1/api.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,38 @@ def reset_read_replica(
14881488
self._throw_on_error(res)
14891489
return unmarshal_ReadReplica(res.json())
14901490

1491+
def promote_read_replica(
1492+
self,
1493+
*,
1494+
read_replica_id: str,
1495+
region: Optional[Region] = None,
1496+
) -> Instance:
1497+
"""
1498+
Promote a Read Replica.
1499+
Promote a Read Replica to Database Instance automatically.
1500+
:param region: Region to target. If none is passed will use default region from the config.
1501+
:param read_replica_id: UUID of the Read Replica.
1502+
:return: :class:`Instance <Instance>`
1503+
1504+
Usage:
1505+
::
1506+
1507+
result = api.promote_read_replica(read_replica_id="example")
1508+
"""
1509+
1510+
param_region = validate_path_param(
1511+
"region", region or self.client.default_region
1512+
)
1513+
param_read_replica_id = validate_path_param("read_replica_id", read_replica_id)
1514+
1515+
res = self._request(
1516+
"POST",
1517+
f"/rdb/v1/regions/{param_region}/read-replicas/{param_read_replica_id}/promote",
1518+
)
1519+
1520+
self._throw_on_error(res)
1521+
return unmarshal_Instance(res.json())
1522+
14911523
def create_read_replica_endpoint(
14921524
self,
14931525
*,

scaleway/scaleway/rdb/v1/content.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
ReadReplicaStatus.INITIALIZING,
5656
ReadReplicaStatus.DELETING,
5757
ReadReplicaStatus.CONFIGURING,
58+
ReadReplicaStatus.PROMOTING,
5859
]
5960
"""
6061
Lists transient statutes of the enum :class:`ReadReplicaStatus <ReadReplicaStatus>`.

scaleway/scaleway/rdb/v1/types.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ class ReadReplicaStatus(str, Enum):
220220
ERROR = "error"
221221
LOCKED = "locked"
222222
CONFIGURING = "configuring"
223+
PROMOTING = "promoting"
223224

224225
def __str__(self) -> str:
225226
return str(self.value)
@@ -2105,6 +2106,19 @@ class ResetReadReplicaRequest:
21052106
"""
21062107

21072108

2109+
@dataclass
2110+
class PromoteReadReplicaRequest:
2111+
region: Optional[Region]
2112+
"""
2113+
Region to target. If none is passed will use default region from the config.
2114+
"""
2115+
2116+
read_replica_id: str
2117+
"""
2118+
UUID of the Read Replica.
2119+
"""
2120+
2121+
21082122
@dataclass
21092123
class CreateReadReplicaEndpointRequest:
21102124
region: Optional[Region]

0 commit comments

Comments
 (0)