Przeglądaj źródła

vm/dispvm: convert DispVM related function to coroutines

Some functions used there (create_on_disk, remove_from_disk, kill) are
coroutines, so callers needs to be too.

Fixes QubesOS/qubes-issues#2896
Marek Marczykowski-Górecki 7 lat temu
rodzic
commit
c32f0db582
2 zmienionych plików z 10 dodań i 7 usunięć
  1. 2 4
      qubes/api/internal.py
  2. 8 3
      qubes/vm/dispvm.py

+ 2 - 4
qubes/api/internal.py

@@ -69,8 +69,7 @@ class QubesInternalAPI(qubes.api.AbstractQubesAPI):
     def create_dispvm(self):
         assert not self.arg
 
-        # TODO convert to coroutine
-        dispvm = qubes.vm.dispvm.DispVM.from_appvm(self.dest)
+        dispvm = yield from qubes.vm.dispvm.DispVM.from_appvm(self.dest)
         return dispvm.name
 
     @qubes.api.method('internal.vm.CleanupDispVM', no_payload=True)
@@ -78,8 +77,7 @@ class QubesInternalAPI(qubes.api.AbstractQubesAPI):
     def cleanup_dispvm(self):
         assert not self.arg
 
-        # TODO convert to coroutine
-        self.dest.cleanup()
+        yield from self.dest.cleanup()
 
     @qubes.api.method('internal.vm.volume.ImportEnd')
     @asyncio.coroutine

+ 8 - 3
qubes/vm/dispvm.py

@@ -23,6 +23,8 @@
 
 import copy
 
+import asyncio
+
 import qubes.vm.qubesvm
 import qubes.vm.appvm
 import qubes.config
@@ -116,6 +118,7 @@ class DispVM(qubes.vm.qubesvm.QubesVM):
             'Cannot change template of Disposable VM')
 
     @classmethod
+    @asyncio.coroutine
     def from_appvm(cls, appvm, **kwargs):
         '''Create a new instance from given AppVM
 
@@ -147,10 +150,11 @@ class DispVM(qubes.vm.qubesvm.QubesVM):
         proplist = [prop for prop in dispvm.property_list()
             if prop.clone and prop.__name__ not in ['template']]
         dispvm.clone_properties(app.domains[appvm], proplist=proplist)
-        dispvm.create_on_disk()
+        yield from dispvm.create_on_disk()
         app.save()
         return dispvm
 
+    @asyncio.coroutine
     def cleanup(self):
         '''Clean up after the DispVM
 
@@ -158,9 +162,10 @@ class DispVM(qubes.vm.qubesvm.QubesVM):
         This method modifies :file:`qubes.xml` file.
         '''
         try:
-            self.force_shutdown()
+            # pylint: disable=not-an-iterable
+            yield from self.kill()
         except qubes.exc.QubesVMNotStartedError:
             pass
-        self.remove_from_disk()
+        yield from self.remove_from_disk()
         del self.app.domains[self]
         self.app.save()