Lines Matching full:arch
46 $ ssh crosvm_$ARCH
63 Arch = Literal["x86_64", "aarch64"] variable
90 def data_dir(arch: Arch): argument
91 return CACHE_DIR.joinpath("crosvm_tools").joinpath(arch)
94 def pid_path(arch: Arch): argument
95 return data_dir(arch).joinpath("pid")
98 def base_img_name(arch: Arch): argument
99 return f"base-{arch}-{BASE_IMG_VERSION}.qcow2"
102 def base_img_url(arch: Arch): argument
103 return f"{IMAGE_DIR_URL}/{base_img_name(arch)}"
106 def base_img_path(arch: Arch): argument
107 return data_dir(arch).joinpath(base_img_name(arch))
110 def rootfs_img_path(arch: Arch): argument
111 return data_dir(arch).joinpath(f"rootfs-{arch}-{BASE_IMG_VERSION}.qcow2")
115 SSH_PORTS: Dict[Arch, int] = {
129 ARCH_TO_QEMU: Dict[Arch, Tuple[str, List[Iterable[str]]]] = {
130 # arch: (qemu-binary, [(param, value), ...])
157 def ssh_opts(arch: Arch) -> Dict[str, str]: argument
159 "Port": str(SSH_PORTS[arch]),
168 def ssh_cmd_args(arch: Arch): argument
169 return [f"-o{k}={v}" for k, v in ssh_opts(arch).items()]
172 def ssh_exec(arch: Arch, cmd: Optional[str] = None): argument
177 *ssh_cmd_args(arch),
183 def ping_vm(arch: Arch): argument
190 *ssh_cmd_args(arch),
201 def write_pid_file(arch: Arch, pid: int): argument
202 with open(pid_path(arch), "w") as pid_file:
206 def read_pid_file(arch: Arch): argument
207 if not pid_path(arch).exists():
210 with open(pid_path(arch), "r") as pid_file:
215 arch: Arch, argument
219 if not is_ssh_port_available(arch):
220 print(f"Port {SSH_PORTS[arch]} is occupied, but is required for the {arch} vm to run.")
221 print(f"You may be running the {arch}vm in another place and need to kill it.")
224 (binary, arch_args) = ARCH_TO_QEMU[arch]
227 qemu_args.append(("-serial", f"file:{data_dir(arch).joinpath('vm_log')}"))
234 write_pid_file(arch, process.pid)
239 def run_vm(arch: Arch, background: bool = False): argument
241 arch,
242 rootfs_img_path(arch),
247 def is_running(arch: Arch): argument
248 pid = read_pid_file(arch)
260 def kill_vm(arch: Arch): argument
261 pid = read_pid_file(arch)
266 def build_if_needed(arch: Arch, reset: bool = False): argument
267 if reset and is_running(arch):
269 kill_vm(arch)
272 data_dir(arch).mkdir(parents=True, exist_ok=True)
274 base_img = base_img_path(arch)
276 print(f"Downloading base image ({base_img_url(arch)})...")
277 download_file(base_img_url(arch), base_img_path(arch))
279 rootfs_img = rootfs_img_path(arch)
300 def is_ssh_port_available(arch: Arch): argument
302 return sock.connect_ex(("127.0.0.1", SSH_PORTS[arch])) != 0
305 def up(arch: Arch): argument
306 if is_running(arch):
311 arch,
312 rootfs_img_path(arch),
317 def run(arch: Arch): argument
318 if is_running(arch):
321 arch,
322 rootfs_img_path(arch),
327 def wait(arch: Arch, timeout: int = 120): argument
328 if not is_running(arch):
329 up(arch)
330 elif ping_vm(arch):
339 if ping_vm(arch):
345 def ssh(arch: Arch, timeout: int): argument
346 wait(arch, timeout)
347 ssh_exec(arch)
350 def ssh_config(arch: Arch): argument
351 print(f"Host crosvm_{arch}")
353 for opt, value in ssh_opts(arch).items():
357 def stop(arch: Arch): argument
358 if not is_running(arch):
361 ssh_exec(arch, "sudo poweroff")
364 def kill(arch: Arch): argument
365 if not is_running(arch):
368 kill_vm(arch)
371 def clean(arch: Arch): argument
372 if is_running(arch):
373 kill(arch)
374 if data_dir(arch).exists():
375 shutil.rmtree(data_dir(arch))
378 def main(arch: Arch, argv: List[str]): argument
406 clean(arch)
410 ssh_config(arch)
414 build_if_needed(arch, reset=args.reset)
419 run(arch)
421 up(arch)
423 ssh(arch, args.timeout)
425 stop(arch)
427 kill(arch)
429 wait(arch, args.timeout)