qvm_remove.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #
  2. # The Qubes OS Project, http://www.qubes-os.org
  3. #
  4. # Copyright (C) 2016 Bahtiar `kalkin-` Gadimov <bahtiar@gadimov.de>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License along
  17. # with this program; if not, write to the Free Software Foundation, Inc.,
  18. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. #
  20. ''' Remove domains from the system '''
  21. from __future__ import print_function
  22. import sys
  23. from qubes.tools import QubesArgumentParser
  24. parser = QubesArgumentParser(description=__doc__,
  25. want_app=True,
  26. want_force_root=True,
  27. vmname_nargs='+')
  28. parser.add_argument('--just-db',
  29. action='store_true',
  30. help='Remove only from db, don\'t remove files')
  31. def main(args=None): # pylint: disable=missing-docstring
  32. args = parser.parse_args(args)
  33. for vm in args.domains:
  34. del args.app.domains[vm.qid]
  35. args.app.save()
  36. if not args.just_db:
  37. vm.remove_from_disk()
  38. else:
  39. # normally it is done by vm.remove_from_disk(), but it isn't
  40. # called in this case
  41. vm.libvirt_domain.undefine()
  42. return 0
  43. if __name__ == '__main__':
  44. sys.exit(main())