qvm_kill.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # encoding=utf-8
  2. #
  3. # The Qubes OS Project, https://www.qubes-os.org/
  4. #
  5. # Copyright (C) 2015 Joanna Rutkowska <joanna@invisiblethingslab.com>
  6. # Copyright (C) 2015 Wojtek Porczyk <woju@invisiblethingslab.com>
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU Lesser General Public License as published by
  10. # the Free Software Foundation; either version 2.1 of the License, or
  11. # (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 Lesser General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Lesser General Public License along
  19. # with this program; if not, see <http://www.gnu.org/licenses/>.
  20. '''qvm-kill - forceful shutdown'''
  21. import sys
  22. import qubesadmin.exc
  23. import qubesadmin.tools
  24. parser = qubesadmin.tools.QubesArgumentParser(
  25. description='forceful shutdown of a domain', vmname_nargs='+')
  26. def main(args=None, app=None):
  27. '''Main routine of :program:`qvm-kill`.
  28. :param list args: Optional arguments to override those delivered from \
  29. command line.
  30. '''
  31. args = parser.parse_args(args, app=app)
  32. exit_code = 0
  33. for domain in args.domains:
  34. try:
  35. domain.kill()
  36. except qubesadmin.exc.QubesVMNotStartedError:
  37. pass
  38. except (IOError, OSError, qubesadmin.exc.QubesException) as e:
  39. exit_code = 1
  40. parser.print_error("Failed to kill '{}': {}".format(
  41. domain.name, e))
  42. return exit_code
  43. if __name__ == '__main__':
  44. sys.exit(main())