Add pool-add, pool-pre-delete, pool-delete events

This commit is contained in:
Marek Marczykowski-Górecki 2019-02-18 21:20:30 +01:00
parent d8b6d3efde
commit 23bfc18535
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -669,6 +669,38 @@ class Qubes(qubes.PropertyHolder):
:param event: Event name (``'domain-delete'``) :param event: Event name (``'domain-delete'``)
:param vm: Domain object :param vm: Domain object
.. event:: pool-add (subject, event, pool)
When storage pool is added.
Handler for this event can be asynchronous (a coroutine).
:param subject: Event emitter
:param event: Event name (``'pool-add'``)
:param pool: Pool object
.. event:: pool-pre-delete (subject, event, pool)
When pool is deleted. Pool is still contained within app.pools
dictionary. You may prevent removal by raising an exception.
Handler for this event can be asynchronous (a coroutine).
:param subject: Event emitter
:param event: Event name (``'pool-pre-delete'``)
:param pool: Pool object
.. event:: pool-delete (subject, event, pool)
When storage pool is deleted. The pool is already removed at this
point.
Handler for this event can be asynchronous (a coroutine).
:param subject: Event emitter
:param event: Event name (``'pool-delete'``)
:param pool: Pool object
Methods and attributes: Methods and attributes:
''' '''
@ -1222,6 +1254,7 @@ class Qubes(qubes.PropertyHolder):
if asyncio.iscoroutine(ret): if asyncio.iscoroutine(ret):
yield from ret yield from ret
self.pools[name] = pool self.pools[name] = pool
yield from self.fire_event_async('pool-add', pool=pool)
return pool return pool
@asyncio.coroutine @asyncio.coroutine
@ -1229,10 +1262,13 @@ class Qubes(qubes.PropertyHolder):
""" Remove a storage pool from config file. """ """ Remove a storage pool from config file. """
try: try:
pool = self.pools[name] pool = self.pools[name]
yield from self.fire_event_async('pool-pre-delete',
pre_event=True, pool=pool)
del self.pools[name] del self.pools[name]
ret = pool.destroy() ret = pool.destroy()
if asyncio.iscoroutine(ret): if asyncio.iscoroutine(ret):
yield from ret yield from ret
yield from self.fire_event_async('pool-delete', pool=pool)
except KeyError: except KeyError:
return return