qvm-template-commit 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/python2
  2. # -*- encoding: utf8 -*-
  3. #
  4. # The Qubes OS Project, http://www.qubes-os.org
  5. #
  6. # Copyright (C) 2011 Marek Marczykowski <marmarek@mimuw.edu.pl>
  7. #
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License
  10. # as published by the Free Software Foundation; either version 2
  11. # of the License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  21. #
  22. #
  23. from qubes.qubes import QubesVmCollection,vmm
  24. from qubes.qubes import QubesException
  25. from optparse import OptionParser
  26. import subprocess
  27. import sys
  28. def main():
  29. usage = "usage: %prog [options] <vm-name>"
  30. parser = OptionParser (usage)
  31. parser.add_option ("--offline-mode", dest="offline_mode",
  32. action="store_true", default=False,
  33. help="Offline mode")
  34. (options, args) = parser.parse_args ()
  35. if (len (args) != 1):
  36. parser.error ("You must specify VM name!")
  37. vmname = args[0]
  38. if options.offline_mode:
  39. vmm.offline_mode = True
  40. qvm_collection = QubesVmCollection()
  41. qvm_collection.lock_db_for_reading()
  42. qvm_collection.load()
  43. qvm_collection.unlock_db()
  44. vm = qvm_collection.get_vm_by_name(vmname)
  45. if vm is None:
  46. print >> sys.stderr, "A VM with the name '{0}' does not exist in the system.".format(vmname)
  47. exit(1)
  48. if not vm.is_template():
  49. print >> sys.stderr, "A VM '{0}' is not template.".format(vmname)
  50. exit(1)
  51. if not vmm.offline_mode and vm.is_running():
  52. print >> sys.stderr, "You must stop VM first."
  53. exit(1)
  54. try:
  55. vm.verify_files()
  56. vm.commit_changes()
  57. except (IOError, OSError, QubesException) as err:
  58. print >> sys.stderr, "ERROR: {0}".format(err)
  59. exit (1)
  60. exit (0)
  61. main()