|
27 | 27 | import sys |
28 | 28 |
|
29 | 29 | import asyncio |
30 | | -from typing import Iterable |
31 | 30 |
|
32 | | -from qubesadmin.app import QubesBase |
33 | | -from qubesadmin.vm import QubesVM |
34 | | - |
35 | | -try: |
36 | | - import qubesadmin.events.utils |
37 | | - have_events = True |
38 | | -except ImportError: |
39 | | - have_events = False |
| 31 | +import qubesadmin.events.utils |
40 | 32 | import qubesadmin.tools |
41 | 33 | import qubesadmin.exc |
42 | 34 |
|
@@ -72,18 +64,6 @@ def failed_domains(vms): |
72 | 64 | if not (vm.get_power_state() == 'Halted' |
73 | 65 | or (vm.klass == 'DispVM' and vm.get_power_state() == 'NA'))] |
74 | 66 |
|
75 | | -async def _wait_for_shutdown_polling(vms: Iterable[QubesVM], app: QubesBase)\ |
76 | | - -> None: |
77 | | - """Fallback polling coroutine when events are not available.""" |
78 | | - current_vms = list(vms) |
79 | | - while True: |
80 | | - current_vms = failed_domains(current_vms) |
81 | | - if not current_vms: |
82 | | - break |
83 | | - app.log.info('Waiting for shutdown: {}'.format( |
84 | | - ', '.join([str(vm) for vm in current_vms]))) |
85 | | - await asyncio.sleep(1) |
86 | | - |
87 | 67 | def main(args=None, app=None): # pylint: disable=missing-docstring |
88 | 68 | args = parser.parse_args(args, app=app) |
89 | 69 |
|
@@ -115,16 +95,11 @@ def main(args=None, app=None): # pylint: disable=missing-docstring |
115 | 95 | # no VM shutdown request succeeded, no sense to try again |
116 | 96 | break |
117 | 97 |
|
118 | | - if have_events: |
119 | | - wait_coro = qubesadmin.events.utils.wait_for_domain_shutdown( |
120 | | - awaiting) |
121 | | - else: |
122 | | - wait_coro = _wait_for_shutdown_polling(awaiting, args.app) |
123 | | - |
124 | 98 | try: |
125 | 99 | # pylint: disable=no-member |
126 | 100 | loop.run_until_complete(asyncio.wait_for( |
127 | | - wait_coro, args.timeout)) |
| 101 | + qubesadmin.events.utils.wait_for_domain_shutdown( |
| 102 | + awaiting), args.timeout)) |
128 | 103 | except (TimeoutError, asyncio.TimeoutError): |
129 | 104 | if not args.dry_run: |
130 | 105 | current_vms = failed_domains(awaiting) |
|
0 commit comments