Skip to content

Commit

Permalink
add set_all_user_data
Browse files Browse the repository at this point in the history
  • Loading branch information
Laure-di committed Jan 14, 2025
1 parent c3c1aa7 commit 9133698
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
23 changes: 19 additions & 4 deletions scaleway/scaleway/instance/v1/custom_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from mypy.semanal import names_modified_in_lvalue
from requests import Response

from scaleway_core.bridge import Zone
from scaleway_core.bridge import Zone as ScwZone
from scaleway_core.utils import validate_path_param
from .api import InstanceV1API
from .custom_marshalling import marshal_GetServerUserDataRequest
Expand All @@ -17,7 +17,7 @@ class InstanceUtilsV1API(InstanceV1API):
"""

def get_server_user_data(
self, server_id: str, key: str, zone: Optional[Zone] = None
self, server_id: str, key: str, zone: Optional[ScwZone] = None
) -> Response:
"""
GetServerUserData gets the content of a user data on a server for the given key.
Expand Down Expand Up @@ -53,7 +53,7 @@ def get_server_user_data(
return res

def set_server_user_data(
self, server_id: str, key: str, content: bytes, zone: Optional[Zone] = None
self, server_id: str, key: str, content: bytes, zone: Optional[ScwZone] = None
) -> Response:
"""
Sets the content of a user data on a server for the given key.
Expand All @@ -78,7 +78,7 @@ def set_server_user_data(
self._throw_on_error(res)
return res

def get_all_server_user_data(self, server_id: str, zone: Optional[Zone] = None) -> GetAllServerUserDataResponse:
def get_all_server_user_data(self, server_id: str, zone: Optional[ScwZone] = None) -> GetAllServerUserDataResponse:
param_zone = validate_path_param("zone", zone or self.client.default_zone)
param_server_id = validate_path_param("server_id", server_id)

Expand All @@ -94,5 +94,20 @@ def get_all_server_user_data(self, server_id: str, zone: Optional[Zone] = None)

return res

def set_all_server_user_data(self, server_id: str, user_data: Dict[str, bytes], zone: Optional[ScwZone] = None):
param_zone = validate_path_param("zone", zone or self.client.default_zone)
param_server_id = validate_path_param("server_id", server_id)

all_user_data_res = InstanceUtilsV1API.list_server_user_data(self, server_id=param_server_id, zone=param_zone)
for key in all_user_data_res.user_data:
if user_data.get(key) is not None:
continue
InstanceUtilsV1API.delete_server_user_data(self, server_id=param_server_id, key=key)

for key in user_data:
InstanceUtilsV1API.set_server_user_data(self, server_id=param_server_id, zone=param_zone, key=key, content=user_data[key])





4 changes: 2 additions & 2 deletions scaleway/scaleway/instance/v1/custom_marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from scaleway.instance.v1.custom_types import (
GetServerUserDataRequest,
ListServerUserDataRequest,
GetAllServerUserDataRequest,
)
from scaleway_core.profile import ProfileDefaults

Expand All @@ -21,7 +21,7 @@ def marshal_GetServerUserDataRequest(

return output

def marshal_ListServerUserDataRequest(request: ListServerUserDataRequest, defaults: ProfileDefaults) -> Dict[str, Any]:
def marshal_ListServerUserDataRequest(request: GetAllServerUserDataRequest, defaults: ProfileDefaults) -> Dict[str, Any]:
output: Dict[str, Any] = {}

if request.server_id is not None:
Expand Down
13 changes: 12 additions & 1 deletion scaleway/scaleway/instance/v1/custom_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class GetServerUserDataRequest:
"""

@dataclass
class ListServerUserDataRequest:
class GetAllServerUserDataRequest:
zone: Optional[Zone]
"""
Zone of the user data to get
Expand All @@ -30,3 +30,14 @@ class ListServerUserDataRequest:
@dataclass
class GetAllServerUserDataResponse:
user_data: Dict[str, bytes]

@dataclass
class SetAllServerUserDataRequest:
zone: Optional[Zone]
"""
Zone of the user data to set
"""

server_id: str

user_data: Dict[str, bytes]

0 comments on commit 9133698

Please sign in to comment.