From 6f87f310dbd4b355f30fb4ff09b3aecf74759d02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sun, 15 Sep 2019 03:38:37 +0200 Subject: [PATCH] Add support for 'tag-created-vm-with' feature When a VM with 'tag-created-vm-with' feature set creates a VM (using Admin API), that VM will get all the tags listed in the feature. Multiple tags can be separated with spaces. This will be useful to tag VMs created during paranoid mode backup restore. QubesOS/qubes-issues#5310 --- qubes/ext/admin.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/qubes/ext/admin.py b/qubes/ext/admin.py index ae052eea..c58c7bca 100644 --- a/qubes/ext/admin.py +++ b/qubes/ext/admin.py @@ -142,3 +142,12 @@ class AdminExtension(qubes.ext.Extension): if hasattr(self, 'policy_cache'): self.policy_cache.cleanup() del self.policy_cache + + @qubes.ext.handler('domain-tag-add:created-by-*') + def on_tag_add(self, vm, event, tag, **kwargs): + '''Add extra tags based on creators 'tag-created-vm-with' feature''' + # pylint: disable=unused-argument,no-self-use + created_by = vm.app.domains[tag.partition('created-by-')[2]] + tag_with = created_by.features.get('tag-created-vm-with', '') + for tag_with_single in tag_with.split(): + vm.tags.add(tag_with_single)