qvm-check 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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@invisiblethingslab.com>
  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,QubesException
  24. from optparse import OptionParser
  25. import sys
  26. import time
  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. (options, args) = parser.parse_args ()
  32. if (len (args) != 1):
  33. parser.error ("You must specify VM name!")
  34. qvm_collection = QubesVmCollection()
  35. qvm_collection.lock_db_for_reading()
  36. qvm_collection.load()
  37. qvm_collection.unlock_db()
  38. vmname = args[0]
  39. vm = qvm_collection.get_vm_by_name(vmname)
  40. if vm is None:
  41. if options.verbose:
  42. print >> sys.stdout, "A VM with the name '{0}' does not exist in the system!".format(vmname)
  43. exit(1)
  44. else:
  45. if options.verbose:
  46. print >> sys.stdout, "A VM with the name '{0}' does exist.".format(vmname)
  47. exit(0)
  48. main()