From 10f071691102d7f0359060bd3cf4833f497904ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sun, 15 May 2016 15:08:30 +0200 Subject: [PATCH] trim-template: Fix handling long named templates Trim template name to fit full VM name in 31 chars. At the same time, check if the VM already exists - if so - remove it first (or error out asking the user to remove it manually - if VM isn't marked as internal). Now that VM is created as internal, to skip appmenus creation. QubesOS/qubes-issues#1910 Fixes QubesOS/qubes-issues#1655 --- qvm-tools/qvm-trim-template | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/qvm-tools/qvm-trim-template b/qvm-tools/qvm-trim-template index f576822b..d5812210 100755 --- a/qvm-tools/qvm-trim-template +++ b/qvm-tools/qvm-trim-template @@ -92,10 +92,21 @@ def main(): touch_dvm_savefile = is_dvm_up_to_date(tvm, dvm_tmpl) print >> sys.stderr, "Creating temporary VM..." - fstrim_vm = qvm_collection.add_new_vm("QubesAppVm", - template=tvm, - name="{}-fstrim".format(tvm_name), - netvm=None, + trim_vmname = "trim-{}".format(tvm_name[:31 - len('trim-')]) + fstrim_vm = qvm_collection.get_vm_by_name(trim_vmname) + if fstrim_vm is not None: + if not fstrim_vm.internal: + print >>sys.stderr, \ + "ERROR: VM '{}' already exists and is not marked as internal. " \ + "Remove it manually." + fstrim_vm.remove_from_disk() + qvm_collection.pop(fstrim_vm.qid) + fstrim_vm = qvm_collection.add_new_vm( + "QubesAppVm", + template=tvm, + name=trim_vmname, + netvm=None, + internal=True, ) if not fstrim_vm: print >> sys.stderr, "ERROR: Failed to create new VM"