qubesd+mgmt: convert mgmt functions to coroutines
QubesOS/qubes-issues#2622
This commit is contained in:
parent
3726c7d9c3
commit
865ab10a0c
@ -22,8 +22,8 @@
|
||||
Qubes OS Management API
|
||||
'''
|
||||
|
||||
import asyncio
|
||||
import reprlib
|
||||
import types
|
||||
|
||||
import qubes.vm.qubesvm
|
||||
|
||||
@ -91,7 +91,7 @@ class QubesMgmt(object):
|
||||
'no such attribute: {!r}'.format(
|
||||
untrusted_func_name))
|
||||
|
||||
if not isinstance(untrusted_func, types.MethodType):
|
||||
if not asyncio.iscoroutinefunction(untrusted_func):
|
||||
raise ProtocolError(
|
||||
'no such method: {!r}'.format(
|
||||
untrusted_func_name))
|
||||
@ -128,6 +128,7 @@ class QubesMgmt(object):
|
||||
# ACTUAL RPC CALLS
|
||||
#
|
||||
|
||||
@asyncio.coroutine
|
||||
def vm_list(self, untrusted_payload):
|
||||
assert self.dest.name == 'dom0'
|
||||
assert not self.arg
|
||||
@ -142,6 +143,7 @@ class QubesMgmt(object):
|
||||
vm.get_power_state())
|
||||
for vm in sorted(domains))
|
||||
|
||||
@asyncio.coroutine
|
||||
def vm_property_list(self, untrusted_payload):
|
||||
assert not self.arg
|
||||
assert not untrusted_payload
|
||||
@ -151,6 +153,7 @@ class QubesMgmt(object):
|
||||
|
||||
return ''.join('{}\n'.format(prop.__name__) for prop in properties)
|
||||
|
||||
@asyncio.coroutine
|
||||
def vm_property_get(self, untrusted_payload):
|
||||
assert self.arg in self.dest.property_list()
|
||||
assert not untrusted_payload
|
||||
@ -167,6 +170,7 @@ class QubesMgmt(object):
|
||||
str(self.dest.property_is_default(self.arg)),
|
||||
self.repr(value))
|
||||
|
||||
@asyncio.coroutine
|
||||
def vm_property_help(self, untrusted_payload):
|
||||
assert self.arg in self.dest.property_list()
|
||||
assert not untrusted_payload
|
||||
@ -181,6 +185,7 @@ class QubesMgmt(object):
|
||||
|
||||
return qubes.utils.format_doc(doc)
|
||||
|
||||
@asyncio.coroutine
|
||||
def vm_property_reset(self, untrusted_payload):
|
||||
assert self.arg in self.dest.property_list()
|
||||
assert not untrusted_payload
|
||||
|
@ -59,9 +59,15 @@ class QubesDaemonProtocol(asyncio.Protocol):
|
||||
finally:
|
||||
self.untrusted_buffer.close()
|
||||
|
||||
asyncio.ensure_future(self.respond(
|
||||
src, method, dest, arg, untrusted_payload=untrusted_payload))
|
||||
|
||||
@asyncio.coroutine
|
||||
def respond(self, src, method, dest, arg, *, untrusted_payload):
|
||||
try:
|
||||
mgmt = qubes.mgmt.QubesMgmt(self.app, src, method, dest, arg)
|
||||
response = mgmt.execute(untrusted_payload=untrusted_payload)
|
||||
response = yield from mgmt.execute(
|
||||
untrusted_payload=untrusted_payload)
|
||||
|
||||
# except clauses will fall through to transport.abort() below
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user