List all available GPUs.
(self, json_output: bool = False)
| 1222 | ) |
| 1223 | |
| 1224 | def list_gpus(self, json_output: bool = False) -> None: |
| 1225 | """List all available GPUs.""" |
| 1226 | response = self.rpc_call("ListGpus") |
| 1227 | gpus = response.get("gpus", []) |
| 1228 | |
| 1229 | if json_output: |
| 1230 | # Return raw JSON data for automation/testing |
| 1231 | print(json.dumps(gpus, indent=2)) |
| 1232 | return |
| 1233 | |
| 1234 | if not gpus: |
| 1235 | print("No GPUs found") |
| 1236 | return |
| 1237 | |
| 1238 | headers = ["Slot", "Product ID", "Description", "Available"] |
| 1239 | rows = [] |
| 1240 | for gpu in gpus: |
| 1241 | row = [ |
| 1242 | gpu.get("slot", "-"), |
| 1243 | gpu.get("product_id", "-"), |
| 1244 | gpu.get("description", "-"), |
| 1245 | "Yes" if gpu.get("is_free", False) else "No", |
| 1246 | ] |
| 1247 | rows.append(row) |
| 1248 | |
| 1249 | print(format_table(rows, headers)) |
| 1250 | |
| 1251 | |
| 1252 | def format_table(rows, headers): |
no test coverage detected