qvm-start 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 qubes.qubes import QubesException
  24. from optparse import OptionParser
  25. import subprocess
  26. qubes_guid_path = "/usr/bin/qubes_guid"
  27. def main():
  28. usage = "usage: %prog [options] <vm-name>"
  29. parser = OptionParser (usage)
  30. parser.add_option ("-q", "--quiet", action="store_false", dest="verbose", default=True)
  31. parser.add_option ("--no-guid", action="store_true", dest="noguid", default=False,
  32. help="Do not start the GUId")
  33. parser.add_option ("--console", action="store_true", dest="debug_console", default=False,
  34. help="Attach debugging console to the newly started VM")
  35. parser.add_option ("--dvm", action="store_true", dest="preparing_dvm", default=False,
  36. help="Do actions necessary when preparing DVM image")
  37. (options, args) = parser.parse_args ()
  38. if (len (args) != 1):
  39. parser.error ("You must specify VM name!")
  40. vmname = args[0]
  41. qvm_collection = QubesVmCollection()
  42. qvm_collection.lock_db_for_reading()
  43. qvm_collection.load()
  44. qvm_collection.unlock_db()
  45. vm = qvm_collection.get_vm_by_name(vmname)
  46. if vm is None:
  47. print "A VM with the name '{0}' does not exist in the system.".format(vmname)
  48. exit(1)
  49. try:
  50. vm.verify_files()
  51. xid = vm.start(debug_console=options.debug_console, verbose=options.verbose, preparing_dvm=options.preparing_dvm)
  52. except (IOError, OSError, QubesException) as err:
  53. print "ERROR: {0}".format(err)
  54. exit (1)
  55. if options.noguid:
  56. exit (0)
  57. if options.verbose:
  58. print "--> Starting Qubes GUId..."
  59. retcode = subprocess.call ([qubes_guid_path, "-d", str(xid), "-c", vm.label.color, "-i", vm.label.icon, "-l", str(vm.label.index)])
  60. if (retcode != 0) :
  61. print "ERROR: Cannot start qubes_guid!"
  62. exit (1)
  63. main()