qvm_kill.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/python2 -O
  2. # vim: fileencoding=utf-8
  3. #
  4. # The Qubes OS Project, https://www.qubes-os.org/
  5. #
  6. # Copyright (C) 2015 Joanna Rutkowska <joanna@invisiblethingslab.com>
  7. # Copyright (C) 2015 Wojtek Porczyk <woju@invisiblethingslab.com>
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License along
  20. # with this program; if not, write to the Free Software Foundation, Inc.,
  21. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  22. #
  23. '''qvm-kill - forceful shutdown'''
  24. import sys
  25. import qubes.exc
  26. import qubes.tools
  27. parser = qubes.tools.QubesArgumentParser(
  28. description='forceful shutdown of a domain', vmname_nargs='+')
  29. def main(args=None):
  30. '''Main routine of :program:`qvm-kill`.
  31. :param list args: Optional arguments to override those delivered from \
  32. command line.
  33. '''
  34. args = parser.parse_args(args)
  35. exit_code = 0
  36. for domain in args.domains:
  37. try:
  38. domain.force_shutdown()
  39. except (IOError, OSError, qubes.exc.QubesException) as e:
  40. exit_code = 1
  41. parser.print_error(str(e))
  42. return exit_code
  43. if __name__ == '__main__':
  44. sys.exit(main())