Prechádzať zdrojové kódy

qvm-template-commit: add --offline-mode option

Allow force offline mode (disable check if VM isn't running) - useful
for running from anaconda (inside of chroot).
Marek Marczykowski 11 rokov pred
rodič
commit
5a28074c2b

+ 3 - 2
core-modules/003QubesTemplateVm.py

@@ -28,7 +28,7 @@ import sys
 
 from qubes.qubes import QubesVm,register_qubes_vm_class,dry_run
 from qubes.qubes import QubesVmCollection,QubesException,QubesVmLabels
-from qubes.qubes import defaults,system_path,vm_files
+from qubes.qubes import defaults,system_path,vm_files,vmm
 
 class QubesTemplateVm(QubesVm):
     """
@@ -151,7 +151,8 @@ class QubesTemplateVm(QubesVm):
 
     def commit_changes (self, verbose = False):
 
-        assert not self.is_running(), "Attempt to commit changes on running Template VM!"
+        if not vmm.offline_mode:
+            assert not self.is_running(), "Attempt to commit changes on running Template VM!"
 
         if verbose:
             print >> sys.stderr, "--> Commiting template updates... COW: {0}...".format (self.rootcow_img)

+ 5 - 2
qvm-tools/qvm-template-commit

@@ -21,7 +21,7 @@
 #
 #
 
-from qubes.qubes import QubesVmCollection
+from qubes.qubes import QubesVmCollection,vmm
 from qubes.qubes import QubesException
 from optparse import OptionParser
 import subprocess
@@ -39,6 +39,9 @@ def main():
         parser.error ("You must specify VM name!")
     vmname = args[0]
 
+    if options.offline_mode:
+        vmm.offline_mode = True
+
     qvm_collection = QubesVmCollection()
     qvm_collection.lock_db_for_reading()
     qvm_collection.load()
@@ -53,7 +56,7 @@ def main():
         print >> sys.stderr, "A VM '{0}' is not template.".format(vmname)
         exit(1)
 
-    if vm.is_running():
+    if not vmm.offline_mode and vm.is_running():
         print >> sys.stderr, "You must stop VM first."
         exit(1)