Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit e7bd6cc

Browse files
committed
Format with ruff
1 parent 38c41ea commit e7bd6cc

6 files changed

Lines changed: 262 additions & 235 deletions

File tree

packages/jumpstarter-driver-corellium/jumpstarter_driver_corellium/corellium/api.py

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class ApiClient:
1010
"""
1111
Corellium ReST API client used by the Corellium driver.
1212
"""
13+
1314
session: Session
1415
req: requests.Session
1516

@@ -27,7 +28,7 @@ def baseurl(self) -> str:
2728
"""
2829
Return the baseurl path for API calls.
2930
"""
30-
return f'https://{self.host}/api'
31+
return f"https://{self.host}/api"
3132

3233
def login(self) -> None:
3334
"""
@@ -38,34 +39,32 @@ def login(self) -> None:
3839
3940
It uses the global requests objects so a new session can be generated.
4041
"""
41-
data = {
42-
'apiToken': self.token
43-
}
42+
data = {"apiToken": self.token}
4443

4544
try:
46-
res = requests.post(f'{self.baseurl}/v1/auth/login', json=data)
45+
res = requests.post(f"{self.baseurl}/v1/auth/login", json=data)
4746
data = res.json()
4847
res.raise_for_status()
4948
except (requests.exceptions.RequestException, requests.exceptions.HTTPError) as e:
50-
raise CorelliumApiException(data.get('error', str(e))) from e
49+
raise CorelliumApiException(data.get("error", str(e))) from e
5150

5251
self.session = Session(**data)
5352
self.req.headers.update(self.session.as_header())
5453

55-
def get_project(self, project_ref: str = 'Default Project') -> Optional[Project]:
54+
def get_project(self, project_ref: str = "Default Project") -> Optional[Project]:
5655
"""
5756
Retrieve a project based on project_ref, which is either its id or name.
5857
"""
5958
try:
60-
res = self.req.get(f'{self.baseurl}/v1/projects')
59+
res = self.req.get(f"{self.baseurl}/v1/projects")
6160
data = res.json()
6261
res.raise_for_status()
6362
except requests.exceptions.RequestException as e:
64-
raise CorelliumApiException(data.get('error', str(e))) from e
63+
raise CorelliumApiException(data.get("error", str(e))) from e
6564

6665
for project in data:
67-
if project['name'] == project_ref or project['id'] == project_ref:
68-
return Project(id=project['id'], name=project['name'])
66+
if project["name"] == project_ref or project["id"] == project_ref:
67+
return Project(id=project["id"], name=project["name"])
6968

7069
return None
7170

@@ -76,14 +75,14 @@ def get_device(self, model: str) -> Optional[Device]:
7675
A device object is used to create a new virtual instance.
7776
"""
7877
try:
79-
res = self.req.get(f'{self.baseurl}/v1/models')
78+
res = self.req.get(f"{self.baseurl}/v1/models")
8079
data = res.json()
8180
res.raise_for_status()
8281
except requests.exceptions.RequestException as e:
83-
raise CorelliumApiException(data.get('error', str(e))) from e
82+
raise CorelliumApiException(data.get("error", str(e))) from e
8483

8584
for device in data:
86-
if device['model'] == model:
85+
if device["model"] == model:
8786
return Device(**device)
8887

8988
return None
@@ -93,19 +92,19 @@ def create_instance(self, name: str, project: Project, device: Device, os_versio
9392
Create a new virtual instance from a device spec.
9493
"""
9594
data = {
96-
'name': name,
97-
'project': project.id,
98-
'flavor': device.flavor,
99-
'os': os_version,
100-
'osbuild': os_build,
95+
"name": name,
96+
"project": project.id,
97+
"flavor": device.flavor,
98+
"os": os_version,
99+
"osbuild": os_build,
101100
}
102101

103102
try:
104-
res = self.req.post(f'{self.baseurl}/v1/instances', json=data)
103+
res = self.req.post(f"{self.baseurl}/v1/instances", json=data)
105104
data = res.json()
106105
res.raise_for_status()
107106
except requests.exceptions.RequestException as e:
108-
raise CorelliumApiException(data.get('error', str(e))) from e
107+
raise CorelliumApiException(data.get("error", str(e))) from e
109108

110109
return Instance(**data)
111110

@@ -116,15 +115,15 @@ def get_instance(self, instance_ref: str) -> Optional[Instance]:
116115
Return None if it does not exist.
117116
"""
118117
try:
119-
res = self.req.get(f'{self.baseurl}/v1/instances')
118+
res = self.req.get(f"{self.baseurl}/v1/instances")
120119
data = res.json()
121120
res.raise_for_status()
122121
except requests.exceptions.RequestException as e:
123-
raise CorelliumApiException(data.get('error', str(e))) from e
122+
raise CorelliumApiException(data.get("error", str(e))) from e
124123

125124
for instance in data:
126-
if instance['name'] == instance_ref or instance['id'] == instance_ref:
127-
return Instance(id=instance['id'], state=instance['state'])
125+
if instance["name"] == instance_ref or instance["id"] == instance_ref:
126+
return Instance(id=instance["id"], state=instance["state"])
128127

129128
return None
130129

@@ -144,12 +143,10 @@ def set_instance_state(self, instance: Instance, instance_state: str) -> None:
144143
- rebooting
145144
- error
146145
"""
147-
data = {
148-
'state': instance_state
149-
}
146+
data = {"state": instance_state}
150147

151148
try:
152-
res = self.req.put(f'{self.baseurl}/v1/instances/{instance.id}/state', json=data)
149+
res = self.req.put(f"{self.baseurl}/v1/instances/{instance.id}/state", json=data)
153150
data = res.json() if res.status_code != 204 else None
154151
res.raise_for_status()
155152
except requests.exceptions.RequestException as e:
@@ -164,7 +161,7 @@ def destroy_instance(self, instance: Instance) -> None:
164161
Does not return anything since Corellium's API return a HTTP 204 response.
165162
"""
166163
try:
167-
res = self.req.delete(f'{self.baseurl}/v1/instances/{instance.id}')
164+
res = self.req.delete(f"{self.baseurl}/v1/instances/{instance.id}")
168165
data = res.json() if res.status_code != 204 else None
169166
res.raise_for_status()
170167
except requests.exceptions.RequestException as e:

0 commit comments

Comments
 (0)