qvm-check 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/python2
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2011 Marek Marczykowski <marmarek@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,QubesException
  23. from optparse import OptionParser
  24. import sys
  25. import time
  26. def main():
  27. usage = "usage: %prog [options] <vm-name>"
  28. parser = OptionParser (usage)
  29. parser.add_option ("-q", "--quiet", action="store_false", dest="verbose", default=True)
  30. (options, args) = parser.parse_args ()
  31. if (len (args) != 1):
  32. parser.error ("You must specify VM name!")
  33. qvm_collection = QubesVmCollection()
  34. qvm_collection.lock_db_for_reading()
  35. qvm_collection.load()
  36. qvm_collection.unlock_db()
  37. vmname = args[0]
  38. vm = qvm_collection.get_vm_by_name(vmname)
  39. if vm is None:
  40. if options.verbose:
  41. print >> sys.stdout, "A VM with the name '{0}' does not exist in the system!".format(vmname)
  42. exit(1)
  43. else:
  44. if options.verbose:
  45. print >> sys.stdout, "A VM with the name '{0}' does exist.".format(vmname)
  46. exit(0)
  47. main()