Convert a VMM instance info dict to a connection URL.
(instance: Dict[str, Any])
| 146 | |
| 147 | |
| 148 | def vmm_address_to_url(instance: Dict[str, Any]) -> str: |
| 149 | """Convert a VMM instance info dict to a connection URL.""" |
| 150 | addr = instance.get("address", "") |
| 151 | if addr.startswith("unix:"): |
| 152 | # Resolve relative socket path against working directory |
| 153 | socket_path = addr[5:] |
| 154 | if not os.path.isabs(socket_path): |
| 155 | working_dir = instance.get("working_dir", "") |
| 156 | socket_path = os.path.join(working_dir, socket_path) |
| 157 | return f"unix:{socket_path}" |
| 158 | elif addr.startswith("http://") or addr.startswith("https://"): |
| 159 | return addr |
| 160 | else: |
| 161 | # host:port format from discovery |
| 162 | host, _, port = addr.rpartition(":") |
| 163 | if host == "0.0.0.0": |
| 164 | host = "127.0.0.1" |
| 165 | return f"http://{host}:{port}" |
| 166 | |
| 167 | |
| 168 | def save_active_vmm(vmm_id: str): |
no test coverage detected