diff --git a/scaleway/scaleway/instance/v1/custom_api.py b/scaleway/scaleway/instance/v1/custom_api.py index 749d85ccd..61f0865c8 100644 --- a/scaleway/scaleway/instance/v1/custom_api.py +++ b/scaleway/scaleway/instance/v1/custom_api.py @@ -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 @@ -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. @@ -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. @@ -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) @@ -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]) + + + diff --git a/scaleway/scaleway/instance/v1/custom_marshalling.py b/scaleway/scaleway/instance/v1/custom_marshalling.py index ab8196316..b26432890 100644 --- a/scaleway/scaleway/instance/v1/custom_marshalling.py +++ b/scaleway/scaleway/instance/v1/custom_marshalling.py @@ -2,7 +2,7 @@ from scaleway.instance.v1.custom_types import ( GetServerUserDataRequest, - ListServerUserDataRequest, + GetAllServerUserDataRequest, ) from scaleway_core.profile import ProfileDefaults @@ -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: diff --git a/scaleway/scaleway/instance/v1/custom_types.py b/scaleway/scaleway/instance/v1/custom_types.py index 3e1dc682a..33015a482 100644 --- a/scaleway/scaleway/instance/v1/custom_types.py +++ b/scaleway/scaleway/instance/v1/custom_types.py @@ -19,7 +19,7 @@ class GetServerUserDataRequest: """ @dataclass -class ListServerUserDataRequest: +class GetAllServerUserDataRequest: zone: Optional[Zone] """ Zone of the user data to get @@ -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]