qvm-set-default-template 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/python2.6
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2010 Joanna Rutkowska <joanna@invisiblethingslab.com>
  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 optparse import OptionParser;
  24. def main():
  25. usage = "usage: %prog <template-vm-name>"
  26. parser = OptionParser (usage)
  27. (options, args) = parser.parse_args ()
  28. if (len (args) != 1):
  29. parser.error ("Missing argument!")
  30. vmname = args[0]
  31. qvm_collection = QubesVmCollection()
  32. qvm_collection.lock_db_for_writing()
  33. qvm_collection.load()
  34. vm = qvm_collection.get_vm_by_name(vmname)
  35. if vm is None or vm.qid not in qvm_collection:
  36. print "A VM with the name '{0}' does not exist in the system.".format(vmname)
  37. exit(1)
  38. if not vm.is_templete():
  39. print "VM '{0}' is not a TemplateVM".format(vmname)
  40. exit (1)
  41. qvm_collection.set_default_template_vm(vm)
  42. qvm_collection.save()
  43. qvm_collection.unlock_db()
  44. main()