Skip to content

Commit 00b09b1

Browse files
feat(baremetal): add protected flag on servers (#1075)
Co-authored-by: Rémy Léone <rleone@scaleway.com>
1 parent bf82ca3 commit 00b09b1

File tree

6 files changed

+98
-34
lines changed

6 files changed

+98
-34
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ async def create_server(
281281
offer_id: str,
282282
name: str,
283283
description: str,
284+
protected: bool,
284285
zone: Optional[ScwZone] = None,
285286
organization_id: Optional[str] = None,
286287
project_id: Optional[str] = None,
@@ -294,6 +295,7 @@ async def create_server(
294295
:param offer_id: Offer ID of the new server.
295296
:param name: Name of the server (≠hostname).
296297
:param description: Description associated with the server, max 255 characters.
298+
:param protected: If enabled, the server can not be deleted.
297299
:param zone: Zone to target. If none is passed will use default zone from the config.
298300
:param organization_id: Organization ID with which the server will be created.
299301
One-Of ('project_identifier'): at most one of 'project_id', 'organization_id' could be set.
@@ -311,6 +313,7 @@ async def create_server(
311313
offer_id="example",
312314
name="example",
313315
description="example",
316+
protected=False,
314317
)
315318
"""
316319

@@ -324,6 +327,7 @@ async def create_server(
324327
offer_id=offer_id,
325328
name=name,
326329
description=description,
330+
protected=protected,
327331
zone=zone,
328332
tags=tags,
329333
install=install,
@@ -346,15 +350,17 @@ async def update_server(
346350
name: Optional[str] = None,
347351
description: Optional[str] = None,
348352
tags: Optional[List[str]] = None,
353+
protected: Optional[bool] = None,
349354
) -> Server:
350355
"""
351356
Update an Elastic Metal server.
352-
Update the server associated with the ID. You can update parameters such as the server's name, tags and description. Any parameters left null in the request body are not updated.
357+
Update the server associated with the ID. You can update parameters such as the server's name, tags, description and protection flag. Any parameters left null in the request body are not updated.
353358
:param server_id: ID of the server to update.
354359
:param zone: Zone to target. If none is passed will use default zone from the config.
355360
:param name: Name of the server (≠hostname), not updated if null.
356361
:param description: Description associated with the server, max 255 characters, not updated if null.
357362
:param tags: Tags associated with the server, not updated if null.
363+
:param protected: If enabled, the server can not be deleted.
358364
:return: :class:`Server <Server>`
359365
360366
Usage:
@@ -378,6 +384,7 @@ async def update_server(
378384
name=name,
379385
description=description,
380386
tags=tags,
387+
protected=protected,
381388
),
382389
self.client,
383390
),

scaleway-async/scaleway_async/baremetal/v1/marshalling.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,14 @@ def unmarshal_Server(data: Any) -> Server:
10551055
if field is not None:
10561056
args["status"] = field
10571057

1058+
field = data.get("offer_id", None)
1059+
if field is not None:
1060+
args["offer_id"] = field
1061+
1062+
field = data.get("offer_name", None)
1063+
if field is not None:
1064+
args["offer_name"] = field
1065+
10581066
field = data.get("updated_at", None)
10591067
if field is not None:
10601068
args["updated_at"] = parser.isoparse(field) if isinstance(field, str) else field
@@ -1067,14 +1075,6 @@ def unmarshal_Server(data: Any) -> Server:
10671075
else:
10681076
args["created_at"] = None
10691077

1070-
field = data.get("offer_id", None)
1071-
if field is not None:
1072-
args["offer_id"] = field
1073-
1074-
field = data.get("offer_name", None)
1075-
if field is not None:
1076-
args["offer_name"] = field
1077-
10781078
field = data.get("tags", None)
10791079
if field is not None:
10801080
args["tags"] = field
@@ -1105,6 +1105,10 @@ def unmarshal_Server(data: Any) -> Server:
11051105
[unmarshal_ServerOption(v) for v in field] if field is not None else None
11061106
)
11071107

1108+
field = data.get("protected", None)
1109+
if field is not None:
1110+
args["protected"] = field
1111+
11081112
field = data.get("install", None)
11091113
if field is not None:
11101114
args["install"] = unmarshal_ServerInstall(field)
@@ -1603,6 +1607,9 @@ def marshal_CreateServerRequest(
16031607
if request.description is not None:
16041608
output["description"] = request.description
16051609

1610+
if request.protected is not None:
1611+
output["protected"] = request.protected
1612+
16061613
if request.tags is not None:
16071614
output["tags"] = request.tags
16081615

@@ -1739,6 +1746,9 @@ def marshal_UpdateServerRequest(
17391746
if request.tags is not None:
17401747
output["tags"] = request.tags
17411748

1749+
if request.protected is not None:
1750+
output["protected"] = request.protected
1751+
17421752
return output
17431753

17441754

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

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -959,24 +959,24 @@ class Server:
959959
Status of the server.
960960
"""
961961

962-
updated_at: Optional[datetime]
962+
offer_id: str
963963
"""
964-
Last modification date of the server.
964+
Offer ID of the server.
965965
"""
966966

967-
created_at: Optional[datetime]
967+
offer_name: str
968968
"""
969-
Creation date of the server.
969+
Offer name of the server.
970970
"""
971971

972-
offer_id: str
972+
updated_at: Optional[datetime]
973973
"""
974-
Offer ID of the server.
974+
Last modification date of the server.
975975
"""
976976

977-
offer_name: str
977+
created_at: Optional[datetime]
978978
"""
979-
Offer name of the server.
979+
Creation date of the server.
980980
"""
981981

982982
tags: List[str]
@@ -1014,6 +1014,11 @@ class Server:
10141014
Options enabled on the server.
10151015
"""
10161016

1017+
protected: bool
1018+
"""
1019+
If enabled, the server can not be deleted.
1020+
"""
1021+
10171022
install: Optional[ServerInstall]
10181023
"""
10191024
Configuration of the installation.
@@ -1111,6 +1116,11 @@ class CreateServerRequest:
11111116
Description associated with the server, max 255 characters.
11121117
"""
11131118

1119+
protected: bool
1120+
"""
1121+
If enabled, the server can not be deleted.
1122+
"""
1123+
11141124
zone: Optional[ScwZone]
11151125
"""
11161126
Zone to target. If none is passed will use default zone from the config.
@@ -1842,6 +1852,11 @@ class UpdateServerRequest:
18421852
Tags associated with the server, not updated if null.
18431853
"""
18441854

1855+
protected: Optional[bool]
1856+
"""
1857+
If enabled, the server can not be deleted.
1858+
"""
1859+
18451860

18461861
@dataclass
18471862
class UpdateSettingRequest:

scaleway/scaleway/baremetal/v1/api.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ def create_server(
281281
offer_id: str,
282282
name: str,
283283
description: str,
284+
protected: bool,
284285
zone: Optional[ScwZone] = None,
285286
organization_id: Optional[str] = None,
286287
project_id: Optional[str] = None,
@@ -294,6 +295,7 @@ def create_server(
294295
:param offer_id: Offer ID of the new server.
295296
:param name: Name of the server (≠hostname).
296297
:param description: Description associated with the server, max 255 characters.
298+
:param protected: If enabled, the server can not be deleted.
297299
:param zone: Zone to target. If none is passed will use default zone from the config.
298300
:param organization_id: Organization ID with which the server will be created.
299301
One-Of ('project_identifier'): at most one of 'project_id', 'organization_id' could be set.
@@ -311,6 +313,7 @@ def create_server(
311313
offer_id="example",
312314
name="example",
313315
description="example",
316+
protected=False,
314317
)
315318
"""
316319

@@ -324,6 +327,7 @@ def create_server(
324327
offer_id=offer_id,
325328
name=name,
326329
description=description,
330+
protected=protected,
327331
zone=zone,
328332
tags=tags,
329333
install=install,
@@ -346,15 +350,17 @@ def update_server(
346350
name: Optional[str] = None,
347351
description: Optional[str] = None,
348352
tags: Optional[List[str]] = None,
353+
protected: Optional[bool] = None,
349354
) -> Server:
350355
"""
351356
Update an Elastic Metal server.
352-
Update the server associated with the ID. You can update parameters such as the server's name, tags and description. Any parameters left null in the request body are not updated.
357+
Update the server associated with the ID. You can update parameters such as the server's name, tags, description and protection flag. Any parameters left null in the request body are not updated.
353358
:param server_id: ID of the server to update.
354359
:param zone: Zone to target. If none is passed will use default zone from the config.
355360
:param name: Name of the server (≠hostname), not updated if null.
356361
:param description: Description associated with the server, max 255 characters, not updated if null.
357362
:param tags: Tags associated with the server, not updated if null.
363+
:param protected: If enabled, the server can not be deleted.
358364
:return: :class:`Server <Server>`
359365
360366
Usage:
@@ -378,6 +384,7 @@ def update_server(
378384
name=name,
379385
description=description,
380386
tags=tags,
387+
protected=protected,
381388
),
382389
self.client,
383390
),

scaleway/scaleway/baremetal/v1/marshalling.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,14 @@ def unmarshal_Server(data: Any) -> Server:
10551055
if field is not None:
10561056
args["status"] = field
10571057

1058+
field = data.get("offer_id", None)
1059+
if field is not None:
1060+
args["offer_id"] = field
1061+
1062+
field = data.get("offer_name", None)
1063+
if field is not None:
1064+
args["offer_name"] = field
1065+
10581066
field = data.get("updated_at", None)
10591067
if field is not None:
10601068
args["updated_at"] = parser.isoparse(field) if isinstance(field, str) else field
@@ -1067,14 +1075,6 @@ def unmarshal_Server(data: Any) -> Server:
10671075
else:
10681076
args["created_at"] = None
10691077

1070-
field = data.get("offer_id", None)
1071-
if field is not None:
1072-
args["offer_id"] = field
1073-
1074-
field = data.get("offer_name", None)
1075-
if field is not None:
1076-
args["offer_name"] = field
1077-
10781078
field = data.get("tags", None)
10791079
if field is not None:
10801080
args["tags"] = field
@@ -1105,6 +1105,10 @@ def unmarshal_Server(data: Any) -> Server:
11051105
[unmarshal_ServerOption(v) for v in field] if field is not None else None
11061106
)
11071107

1108+
field = data.get("protected", None)
1109+
if field is not None:
1110+
args["protected"] = field
1111+
11081112
field = data.get("install", None)
11091113
if field is not None:
11101114
args["install"] = unmarshal_ServerInstall(field)
@@ -1603,6 +1607,9 @@ def marshal_CreateServerRequest(
16031607
if request.description is not None:
16041608
output["description"] = request.description
16051609

1610+
if request.protected is not None:
1611+
output["protected"] = request.protected
1612+
16061613
if request.tags is not None:
16071614
output["tags"] = request.tags
16081615

@@ -1739,6 +1746,9 @@ def marshal_UpdateServerRequest(
17391746
if request.tags is not None:
17401747
output["tags"] = request.tags
17411748

1749+
if request.protected is not None:
1750+
output["protected"] = request.protected
1751+
17421752
return output
17431753

17441754

scaleway/scaleway/baremetal/v1/types.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -959,24 +959,24 @@ class Server:
959959
Status of the server.
960960
"""
961961

962-
updated_at: Optional[datetime]
962+
offer_id: str
963963
"""
964-
Last modification date of the server.
964+
Offer ID of the server.
965965
"""
966966

967-
created_at: Optional[datetime]
967+
offer_name: str
968968
"""
969-
Creation date of the server.
969+
Offer name of the server.
970970
"""
971971

972-
offer_id: str
972+
updated_at: Optional[datetime]
973973
"""
974-
Offer ID of the server.
974+
Last modification date of the server.
975975
"""
976976

977-
offer_name: str
977+
created_at: Optional[datetime]
978978
"""
979-
Offer name of the server.
979+
Creation date of the server.
980980
"""
981981

982982
tags: List[str]
@@ -1014,6 +1014,11 @@ class Server:
10141014
Options enabled on the server.
10151015
"""
10161016

1017+
protected: bool
1018+
"""
1019+
If enabled, the server can not be deleted.
1020+
"""
1021+
10171022
install: Optional[ServerInstall]
10181023
"""
10191024
Configuration of the installation.
@@ -1111,6 +1116,11 @@ class CreateServerRequest:
11111116
Description associated with the server, max 255 characters.
11121117
"""
11131118

1119+
protected: bool
1120+
"""
1121+
If enabled, the server can not be deleted.
1122+
"""
1123+
11141124
zone: Optional[ScwZone]
11151125
"""
11161126
Zone to target. If none is passed will use default zone from the config.
@@ -1842,6 +1852,11 @@ class UpdateServerRequest:
18421852
Tags associated with the server, not updated if null.
18431853
"""
18441854

1855+
protected: Optional[bool]
1856+
"""
1857+
If enabled, the server can not be deleted.
1858+
"""
1859+
18451860

18461861
@dataclass
18471862
class UpdateSettingRequest:

0 commit comments

Comments
 (0)