List all discovered VMM instances.
(args)
| 175 | |
| 176 | |
| 177 | def cmd_ls_vmm(args): |
| 178 | """List all discovered VMM instances.""" |
| 179 | instances = discover_vmm_instances() |
| 180 | config = load_config() |
| 181 | active_id = config.get("active_vmm") |
| 182 | |
| 183 | if not instances: |
| 184 | print("No running VMM instances found.") |
| 185 | print( |
| 186 | f" (scanned: {', '.join(d for d, _ in _get_discovery_dirs()) or '/run/user/*/dstack-vmm'})" |
| 187 | ) |
| 188 | return |
| 189 | |
| 190 | if getattr(args, "json", False): |
| 191 | print(json.dumps(instances, indent=2)) |
| 192 | return |
| 193 | |
| 194 | # Table output |
| 195 | |
| 196 | fmt = " {active} {id:<12s} {pid:<8s} {user:<10s} {node:<12s} {address:<24s} {workdir}" |
| 197 | print( |
| 198 | fmt.format( |
| 199 | active="", |
| 200 | id="ID", |
| 201 | pid="PID", |
| 202 | user="USER", |
| 203 | node="NAME", |
| 204 | address="ADDRESS", |
| 205 | workdir="WORKING DIR", |
| 206 | ) |
| 207 | ) |
| 208 | print(" " + "-" * 100) |
| 209 | |
| 210 | for inst in instances: |
| 211 | short_id = inst["id"][:8] |
| 212 | is_active = "*" if active_id and inst["id"].startswith(active_id) else " " |
| 213 | node_name = inst.get("node_name", "") or "-" |
| 214 | address = inst.get("address", "?") |
| 215 | |
| 216 | print( |
| 217 | fmt.format( |
| 218 | active=is_active, |
| 219 | id=short_id, |
| 220 | pid=str(inst.get("pid", "?")), |
| 221 | user=inst.get("user", "?")[:10], |
| 222 | node=node_name[:12], |
| 223 | address=address[:24], |
| 224 | workdir=inst.get("working_dir", "?"), |
| 225 | ) |
| 226 | ) |
| 227 | |
| 228 | |
| 229 | def cmd_switch_vmm(args): |
no test coverage detected