Skip to content

Commit 335c908

Browse files
committed
Improve disposables docstrings
For: QubesOS/qubes-doc#1554 For: QubesOS/qubes-issues#1512
1 parent c9504b7 commit 335c908

File tree

8 files changed

+469
-121
lines changed

8 files changed

+469
-121
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
@@ -1636,6 +1636,12 @@ def _domain_event_callback(self, _conn, domain, event, _detail, _opaque):
16361636

16371637
@qubes.events.handler("domain-pre-delete")
16381638
def on_domain_pre_deleted(self, event, vm):
1639+
"""
1640+
Forbid deleting qube if it is a dependency of another qube.
1641+
1642+
:param str event: Event which was fired.
1643+
:param qubes.vm.QubesVM name: Qube name.
1644+
"""
16391645
# pylint: disable=unused-argument
16401646
for obj in itertools.chain(self.domains, (self,)):
16411647
if obj is vm:
@@ -1738,6 +1744,21 @@ def on_property_set_default_netvm(
17381744
def on_property_set_default_dispvm(
17391745
self, event, name, newvalue=None, oldvalue=None
17401746
):
1747+
"""
1748+
When system's default_dispvm is (re)set, alert every domain that has
1749+
the default value.
1750+
1751+
If there is a difference between the maximum number of preloaded
1752+
disposables configured globally and on the new and old setting, adapt
1753+
it to match the current scenario.
1754+
1755+
:param str event: Event which was fired.
1756+
:param str name: Property name.
1757+
:param qubes.vm.mix.dvmtemplate.DVMTemplateMixin newvalue: New value \
1758+
of the property.
1759+
:param qubes.vm.mix.dvmtemplate.DVMTemplateMixin oldvalue: Old value \
1760+
of the property.
1761+
"""
17411762
# pylint: disable=unused-argument
17421763
for vm in self.domains:
17431764
if hasattr(vm, "default_dispvm") and vm.property_is_default(

qubes/vm/adminvm.py

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ def xid(self) -> int:
116116
117117
.. seealso:
118118
:py:attr:`qubes.vm.qubesvm.QubesVM.xid`
119+
120+
:return: 0
121+
:rtype: int
119122
"""
120123
return 0
121124

@@ -351,17 +354,33 @@ async def run_service_for_stdio(self, *args, input=None, **kwargs):
351354
@qubes.events.handler("domain-feature-pre-set:preload-dispvm-threshold")
352355
def on_feature_pre_set_preload_dispvm_threshold(
353356
self, event, feature, value, oldvalue=None
354-
): # pylint: disable=unused-argument
357+
):
358+
"""
359+
Before accepting the ``preload-dispvm-threshold`` feature, validate it.
360+
361+
:param str event: Event which was fired.
362+
:param str feature: Feature name.
363+
:param int value: New value of the feature.
364+
:param int oldvalue: Old value of the feature.
365+
"""
366+
# pylint: disable=unused-argument
355367
value = value or "0"
356368
if not value.isdigit():
357369
raise qubes.exc.QubesValueError(
358370
"Invalid preload-dispvm-threshold value: not a digit"
359371
)
360372

361373
@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
374+
def on_feature_delete_preload_dispvm_max(self, event, feature):
375+
"""
376+
On deletion of the ``preload-dispvm-max`` feature, fire
377+
``domain-preload-dispvm-start`` event on the system's
378+
``default_dispvm``.
379+
380+
:param str event: Event which was fired.
381+
:param str feature: Feature name.
382+
"""
383+
# pylint: disable=unused-argument
365384
if not (appvm := getattr(self.app, "default_dispvm", None)):
366385
return
367386
reason = "global feature was deleted"
@@ -372,7 +391,16 @@ def on_feature_delete_preload_dispvm_max(
372391
@qubes.events.handler("domain-feature-pre-set:preload-dispvm-max")
373392
def on_feature_pre_set_preload_dispvm_max(
374393
self, event, feature, value, oldvalue=None
375-
): # pylint: disable=unused-argument
394+
):
395+
"""
396+
Before accepting the ``preload-dispvm-max`` feature, validate it.
397+
398+
:param str event: Event which was fired.
399+
:param str feature: Feature name.
400+
:param int value: New value of the feature.
401+
:param int oldvalue: Old value of the feature.
402+
"""
403+
# pylint: disable=unused-argument
376404
if value == oldvalue:
377405
return
378406
if not (appvm := getattr(self.app, "default_dispvm", None)):
@@ -388,7 +416,18 @@ def on_feature_pre_set_preload_dispvm_max(
388416
@qubes.events.handler("domain-feature-set:preload-dispvm-max")
389417
def on_feature_set_preload_dispvm_max(
390418
self, event, feature, value, oldvalue=None
391-
): # pylint: disable=unused-argument
419+
):
420+
"""
421+
After setting the ``preload-dispvm-max`` feature, fire
422+
``domain-preload-dispvm-start`` event on the system's
423+
``default_dispvm``.
424+
425+
:param str event: Event which was fired.
426+
:param str feature: Feature name.
427+
:param int value: New value of the feature.
428+
:param int oldvalue: Old value of the feature.
429+
"""
430+
# pylint: disable=unused-argument
392431
if value == oldvalue:
393432
return
394433
if not (appvm := getattr(self.app, "default_dispvm", None)):

0 commit comments

Comments
 (0)