Skip to content

Commit 2757691

Browse files
committed
fix format ruff
1 parent 0c898b8 commit 2757691

File tree

4 files changed

+62
-5
lines changed

4 files changed

+62
-5
lines changed

scaleway/scaleway/instance/v1/custom_api.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ class InstanceUtilsV1API(InstanceV1API):
1212
such as getting and setting server user data, while inheriting all methods of InstanceV1API.
1313
"""
1414

15-
def get_server_user_data(self, server_id: str, key: str, zone: Optional[Zone] = None):
15+
def get_server_user_data(
16+
self, server_id: str, key: str, zone: Optional[Zone] = None
17+
):
1618
"""
1719
GetServerUserData gets the content of a user data on a server for the given key.
1820
:param zone: Zone to target. If none is passed will use default zone from the config.
@@ -46,7 +48,9 @@ def get_server_user_data(self, server_id: str, key: str, zone: Optional[Zone] =
4648
self._throw_on_error(res)
4749
return res
4850

49-
def set_server_user_data(self, server_id: str, key: str, content: bytes, zone: Optional[Zone] = None):
51+
def set_server_user_data(
52+
self, server_id: str, key: str, content: bytes, zone: Optional[Zone] = None
53+
):
5054
"""
5155
Sets the content of a user data on a server for the given key.
5256
:param zone: Zone to target. If none is passed, it will use the default zone from the config.
@@ -58,7 +62,7 @@ def set_server_user_data(self, server_id: str, key: str, content: bytes, zone: O
5862
param_zone = validate_path_param("zone", zone or self.client.default_zone)
5963
param_server_id = validate_path_param("server_id", server_id)
6064
headers = {
61-
'Content-Type': 'text/plain',
65+
"Content-Type": "text/plain",
6266
}
6367
res = self._request(
6468
"PATCH",

scaleway/scaleway/instance/v1/custom_marshalling.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
from typing import Dict, Any
22

3-
from scaleway.instance.v1.custom_types import GetServerUserDataRequest, GetServerUserDataResponse
3+
from scaleway.instance.v1.custom_types import (
4+
GetServerUserDataRequest,
5+
GetServerUserDataResponse,
6+
)
47
from scaleway_core.profile import ProfileDefaults
58

69

7-
def marshal_GetServerUserDataRequest(request: GetServerUserDataRequest, defaults: ProfileDefaults) -> Dict[str, Any]:
10+
def marshal_GetServerUserDataRequest(
11+
request: GetServerUserDataRequest, defaults: ProfileDefaults
12+
) -> Dict[str, Any]:
813
output: Dict[str, Any] = {}
914

1015
if request.server_id is not None:

scaleway/scaleway/instance/v1/custom_types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from scaleway_core.bridge import Zone
55

6+
67
@dataclass
78
class GetServerUserDataRequest:
89
zone: Optional[Zone]
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import logging
2+
3+
# import os
4+
# import sys
5+
from io import BytesIO, StringIO
6+
7+
# sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../..")))
8+
from scaleway_core.client import Client
9+
from .custom_api import InstanceUtilsV1API
10+
11+
logger = logging.getLogger("scaleway")
12+
logger.addHandler(logging.StreamHandler())
13+
logger.setLevel(logging.DEBUG)
14+
15+
# Create a client
16+
client = Client(
17+
access_key="SCW1TKH1HKECKF6K68X5",
18+
secret_key="9034fb39-f48d-463a-9aa1-66f356077e05",
19+
default_project_id="d3520a52-2c75-4ba0-bda8-82dd087f07f2",
20+
default_region="fr-par",
21+
default_zone="fr-par-1",
22+
)
23+
24+
# How to connect to Instance API
25+
instanceClient = InstanceUtilsV1API(client)
26+
27+
28+
# Create the server and attach the volume
29+
instance_basic = instanceClient._create_server(
30+
commercial_type="DEV1-S",
31+
image="ubuntu_jammy",
32+
name="my-server-web",
33+
volumes={}, # Attach the volume to mount point "1"
34+
)
35+
36+
key = "hello"
37+
content = b"\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10" # Use bytes directly
38+
39+
# Set and get server user data
40+
instanceClient.set_server_user_data(
41+
server_id=instance_basic.server.id, key=key, content=content
42+
)
43+
response = instanceClient.get_server_user_data(
44+
server_id=instance_basic.server.id, key=key
45+
)
46+
47+
print(response.text)

0 commit comments

Comments
 (0)