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
17- from vmupdate .utils import shutdown_domains , get_feature , get_boolean_feature , \
18- is_stale
19+ from vmupdate .utils import (
20+ shutdown_domains ,
21+ restart_vms ,
22+ get_feature ,
23+ get_boolean_feature ,
24+ is_stale ,
25+ )
1926from . import update_manager
2027from .agent .source .args import AgentArgs
2128
@@ -109,9 +116,9 @@ def main(args=None, app=qubesadmin.Qubes()):
109116 and no_updates
110117 )
111118
112- ret_code_restart = apply_updates_to_appvm (
119+ ret_code_restart = asyncio . run ( apply_updates_to_appvm (
113120 args , independent , templ_statuses , app_statuses , log
114- )
121+ ))
115122
116123 ret_code = max (
117124 ret_code_admin , ret_code_independent , ret_code_appvm , ret_code_restart
@@ -386,7 +393,7 @@ def run_update(
386393 return ret_code , statuses
387394
388395
389- def apply_updates_to_appvm (
396+ async def apply_updates_to_appvm (
390397 args ,
391398 vm_updated : Iterable ,
392399 template_statuses : Dict [str , FinalStatus ],
@@ -435,7 +442,7 @@ def apply_updates_to_appvm(
435442
436443 # first shutdown templates to apply changes to the root volume
437444 # they are no need to start templates automatically
438- ret_code , _ = shutdown_domains (templates_to_shutdown , log )
445+ ret_code , _ = await shutdown_domains (templates_to_shutdown , log )
439446
440447 if ret_code != EXIT .OK :
441448 log .error ("Shutdown of some templates fails with code %d" , ret_code )
@@ -454,11 +461,11 @@ def apply_updates_to_appvm(
454461 )
455462
456463 # both flags `restart` and `apply-to-all` include service vms
457- ret_code_ = restart_vms (to_restart , log )
464+ ret_code_ = await restart_vms (to_restart , log )
458465 ret_code = max (ret_code , ret_code_ )
459466 if args .apply_to_all :
460467 # there is no need to start plain AppVMs automatically
461- ret_code_ , _ = shutdown_domains (to_shutdown , log )
468+ ret_code_ , _ = await shutdown_domains (to_shutdown , log )
462469 ret_code = max (ret_code , ret_code_ )
463470
464471 return ret_code
@@ -486,23 +493,5 @@ def get_derived_vm_to_apply(templates, derived_statuses):
486493 return to_restart , to_shutdown
487494
488495
489-
490- def restart_vms (to_restart , log ):
491- """
492- Try to restart vms.
493- """
494- ret_code , shutdowns = shutdown_domains (to_restart , log )
495-
496- # restart shutdown qubes
497- for vm in shutdowns :
498- try :
499- vm .start ()
500- except qubesadmin .exc .QubesVMError as exc :
501- log .error (str (exc ))
502- ret_code = EXIT .ERR_START_APP
503-
504- return ret_code
505-
506-
507496if __name__ == "__main__" :
508497 sys .exit (main ())
0 commit comments