List all VMs and their status.
(self, verbose: bool = False, json_output: bool = False)
| 503 | return response |
| 504 | |
| 505 | def list_vms(self, verbose: bool = False, json_output: bool = False) -> None: |
| 506 | """List all VMs and their status.""" |
| 507 | response = self.rpc_call("Status") |
| 508 | vms = response["vms"] |
| 509 | |
| 510 | if json_output: |
| 511 | # Return raw JSON data for automation/testing |
| 512 | print(json.dumps(vms, indent=2)) |
| 513 | return |
| 514 | |
| 515 | if not vms: |
| 516 | print("No VMs found") |
| 517 | return |
| 518 | |
| 519 | headers = ["VM ID", "App ID", "Name", "Status", "Uptime"] |
| 520 | if verbose: |
| 521 | headers.extend(["Instance ID", "vCPU", "Memory", "Disk", "Image", "GPUs"]) |
| 522 | |
| 523 | rows = [] |
| 524 | for vm in vms: |
| 525 | row = [ |
| 526 | vm["id"], |
| 527 | vm["app_id"], |
| 528 | vm["name"], |
| 529 | vm["status"], |
| 530 | vm.get("uptime", "-"), |
| 531 | ] |
| 532 | |
| 533 | if verbose: |
| 534 | config = vm.get("configuration", {}) |
| 535 | gpu_info = self._format_gpu_info(config.get("gpus")) |
| 536 | row.extend( |
| 537 | [ |
| 538 | vm.get("instance_id", "-") or "-", |
| 539 | config.get("vcpu", "-"), |
| 540 | f"{config.get('memory', '-')}MB", |
| 541 | f"{config.get('disk_size', '-')}GB", |
| 542 | config.get("image", "-"), |
| 543 | gpu_info, |
| 544 | ] |
| 545 | ) |
| 546 | |
| 547 | rows.append(row) |
| 548 | |
| 549 | print(format_table(rows, headers)) |
| 550 | |
| 551 | def _format_gpu_info(self, gpu_config): |
| 552 | """Format GPU configuration for display.""" |
no test coverage detected