qvm-template-commit 2.1 KB

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