44"""
55
66import argparse
7+ import asyncio
78import logging
89import sys
910import os
1011import grp
1112from typing import Set , Iterable , Dict , Tuple
1213
1314import qubesadmin
15+ import qubesadmin .utils
1416import qubesadmin .exc
1517from vmupdate .agent .source .status import FinalStatus
1618from vmupdate .agent .source .common .exit_codes import EXIT
1719from vmupdate .utils import (
1820 shutdown_domains ,
21+ restart_vms ,
1922 get_feature ,
2023 get_boolean_feature ,
2124 is_stale ,
@@ -119,8 +122,10 @@ def main(args=None, app=qubesadmin.Qubes()):
119122 if ret_code_appvm == EXIT .SIGINT :
120123 return EXIT .SIGINT
121124
122- ret_code_restart = apply_updates_to_appvm (
123- args , independent , templ_statuses , app_statuses , log
125+ ret_code_restart = asyncio .run (
126+ apply_updates_to_appvm (
127+ args , independent , templ_statuses , app_statuses , log
128+ )
124129 )
125130
126131 ret_code = max (
@@ -396,7 +401,7 @@ def run_update(
396401 return ret_code , statuses
397402
398403
399- def apply_updates_to_appvm (
404+ async def apply_updates_to_appvm (
400405 args ,
401406 vm_updated : Iterable ,
402407 template_statuses : Dict [str , FinalStatus ],
@@ -445,7 +450,7 @@ def apply_updates_to_appvm(
445450
446451 # first shutdown templates to apply changes to the root volume
447452 # they are no need to start templates automatically
448- ret_code , _ = shutdown_domains (templates_to_shutdown , log )
453+ ret_code , _ = await shutdown_domains (templates_to_shutdown , log )
449454
450455 if ret_code != EXIT .OK :
451456 log .error ("Shutdown of some templates fails with code %d" , ret_code )
@@ -464,11 +469,11 @@ def apply_updates_to_appvm(
464469 )
465470
466471 # both flags `restart` and `apply-to-all` include service vms
467- ret_code_ = restart_vms (to_restart , log )
472+ ret_code_ = await restart_vms (to_restart , log )
468473 ret_code = max (ret_code , ret_code_ )
469474 if args .apply_to_all :
470475 # there is no need to start plain AppVMs automatically
471- ret_code_ , _ = shutdown_domains (to_shutdown , log )
476+ ret_code_ , _ = await shutdown_domains (to_shutdown , log )
472477 ret_code = max (ret_code , ret_code_ )
473478
474479 return ret_code
@@ -496,22 +501,5 @@ def get_derived_vm_to_apply(templates, derived_statuses):
496501 return to_restart , to_shutdown
497502
498503
499- def restart_vms (to_restart , log ):
500- """
501- Try to restart vms.
502- """
503- ret_code , shutdowns = shutdown_domains (to_restart , log )
504-
505- # restart shutdown qubes
506- for vm in shutdowns :
507- try :
508- vm .start ()
509- except qubesadmin .exc .QubesVMError as exc :
510- log .error (str (exc ))
511- ret_code = EXIT .ERR_START_APP
512-
513- return ret_code
514-
515-
516504if __name__ == "__main__" :
517505 sys .exit (main ())
0 commit comments