Skip to content

Commit 3aebc76

Browse files
committed
Improve disposables docstrings
For: QubesOS/qubes-doc#1554 For: QubesOS/qubes-issues#1512
1 parent 76b23c9 commit 3aebc76

File tree

8 files changed

+468
-122
lines changed

8 files changed

+468
-122
lines changed

linux/aux-tools/preload-dispvm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ import qubesadmin
1313

1414

1515
def get_preload_max(qube) -> int | None:
16+
"""
17+
Get the ``preload-dispvm-max`` feature as an integer.
18+
19+
:param qubes.vm.qubes.QubesVM qube: Qube to query the feature from.
20+
"""
1621
value = qube.features.get("preload-dispvm-max", None)
1722
return int(value) if value else value
1823

qubes/api/internal.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,6 @@ async def vm_volume_import_end(self, untrusted_payload):
261261
async def suspend_pre(self):
262262
"""
263263
Method called before host system goes to sleep.
264-
265-
:return:
266264
"""
267265

268266
preload_templates = qubes.vm.dispvm.get_preload_templates(self.app)
@@ -346,8 +344,6 @@ async def suspend_pre(self):
346344
async def suspend_post(self):
347345
"""
348346
Method called after host system wake up from sleep.
349-
350-
:return:
351347
"""
352348

353349
# Reload list of previously paused qubes before suspending

qubes/app.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,12 @@ def _domain_event_callback(self, _conn, domain, event, _detail, _opaque):
16311631

16321632
@qubes.events.handler("domain-pre-delete")
16331633
def on_domain_pre_deleted(self, event, vm):
1634+
"""
1635+
Forbid deleting qube if it is a dependency of another qube.
1636+
1637+
:param str event: Event which was fired.
1638+
:param qubes.vm.QubesVM name: Qube name.
1639+
"""
16341640
# pylint: disable=unused-argument
16351641
for obj in itertools.chain(self.domains, (self,)):
16361642
if obj is vm:
@@ -1733,6 +1739,21 @@ def on_property_set_default_netvm(
17331739
def on_property_set_default_dispvm(
17341740
self, event, name, newvalue=None, oldvalue=None
17351741
):
1742+
"""
1743+
When system's default_dispvm is (re)set, alert every domain that has
1744+
the default value.
1745+
1746+
If there is a difference between the maximum number of preloaded
1747+
disposables configured globally and on the new and old setting, adapt
1748+
it to match the current scenario.
1749+
1750+
:param str event: Event which was fired.
1751+
:param str name: Property name.
1752+
:param qubes.vm.mix.dvmtemplate.DVMTemplateMixin newvalue: New value \
1753+
of the property.
1754+
:param qubes.vm.mix.dvmtemplate.DVMTemplateMixin oldvalue: Old value \
1755+
of the property.
1756+
"""
17361757
# pylint: disable=unused-argument
17371758
for vm in self.domains:
17381759
if hasattr(vm, "default_dispvm") and vm.property_is_default(

qubes/vm/adminvm.py

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ def xid(self) -> int:
116116
117117
.. seealso:
118118
:py:attr:`qubes.vm.qubesvm.QubesVM.xid`
119+
120+
:return int: 0
119121
"""
120122
return 0
121123

@@ -351,17 +353,33 @@ async def run_service_for_stdio(self, *args, input=None, **kwargs):
351353
@qubes.events.handler("domain-feature-pre-set:preload-dispvm-threshold")
352354
def on_feature_pre_set_preload_dispvm_threshold(
353355
self, event, feature, value, oldvalue=None
354-
): # pylint: disable=unused-argument
356+
):
357+
"""
358+
Before accepting the ``preload-dispvm-threshold`` feature, validate it.
359+
360+
:param str event: Event which was fired.
361+
:param str feature: Feature name.
362+
:param int value: New value of the feature.
363+
:param int oldvalue: Old value of the feature.
364+
"""
365+
# pylint: disable=unused-argument
355366
value = value or "0"
356367
if not value.isdigit():
357368
raise qubes.exc.QubesValueError(
358369
"Invalid preload-dispvm-threshold value: not a digit"
359370
)
360371

361372
@qubes.events.handler("domain-feature-delete:preload-dispvm-max")
362-
def on_feature_delete_preload_dispvm_max(
363-
self, event, feature
364-
): # pylint: disable=unused-argument
373+
def on_feature_delete_preload_dispvm_max(self, event, feature):
374+
"""
375+
On deletion of the ``preload-dispvm-max`` feature, fire
376+
``domain-preload-dispvm-start`` event on the system's
377+
``default_dispvm``.
378+
379+
:param str event: Event which was fired.
380+
:param str feature: Feature name.
381+
"""
382+
# pylint: disable=unused-argument
365383
if not (appvm := getattr(self.app, "default_dispvm", None)):
366384
return
367385
reason = "global feature was deleted"
@@ -372,7 +390,16 @@ def on_feature_delete_preload_dispvm_max(
372390
@qubes.events.handler("domain-feature-pre-set:preload-dispvm-max")
373391
def on_feature_pre_set_preload_dispvm_max(
374392
self, event, feature, value, oldvalue=None
375-
): # pylint: disable=unused-argument
393+
):
394+
"""
395+
Before accepting the ``preload-dispvm-max`` feature, validate it.
396+
397+
:param str event: Event which was fired.
398+
:param str feature: Feature name.
399+
:param int value: New value of the feature.
400+
:param int oldvalue: Old value of the feature.
401+
"""
402+
# pylint: disable=unused-argument
376403
if value == oldvalue:
377404
return
378405
if not (appvm := getattr(self.app, "default_dispvm", None)):
@@ -388,7 +415,18 @@ def on_feature_pre_set_preload_dispvm_max(
388415
@qubes.events.handler("domain-feature-set:preload-dispvm-max")
389416
def on_feature_set_preload_dispvm_max(
390417
self, event, feature, value, oldvalue=None
391-
): # pylint: disable=unused-argument
418+
):
419+
"""
420+
After setting the ``preload-dispvm-max`` feature, fire
421+
``domain-preload-dispvm-start`` event on the system's
422+
``default_dispvm``.
423+
424+
:param str event: Event which was fired.
425+
:param str feature: Feature name.
426+
:param int value: New value of the feature.
427+
:param int oldvalue: Old value of the feature.
428+
"""
429+
# pylint: disable=unused-argument
392430
if value == oldvalue:
393431
return
394432
if not (appvm := getattr(self.app, "default_dispvm", None)):

0 commit comments

Comments
 (0)