qvm_remove.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #
  2. # The Qubes OS Project, http://www.qubes-os.org
  3. #
  4. # Copyright (C) 2017 Marek Marczykowski-Górecki
  5. # <marmarek@invisiblethingslab.com>
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU Lesser General Public License as published by
  9. # the Free Software Foundation; either version 2.1 of the License, or
  10. # (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 Lesser General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public License along
  18. # with this program; if not, write to the Free Software Foundation, Inc.,
  19. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. #
  21. ''' Remove domains from the system '''
  22. import sys
  23. from qubesadmin.tools import QubesArgumentParser
  24. parser = QubesArgumentParser(description=__doc__,
  25. want_app=True,
  26. vmname_nargs='+')
  27. parser.add_argument("--force", "-f", action="store_true", dest="no_confirm",
  28. default=False, help="Do not prompt for confirmation")
  29. def main(args=None, app=None): # pylint: disable=missing-docstring
  30. args = parser.parse_args(args, app=app)
  31. go_ahead = ""
  32. if not args.no_confirm:
  33. print("This will completely remove the selected VM(s)...")
  34. for vm in args.domains:
  35. print(" ", vm.name)
  36. go_ahead = input("Are you sure? [y/N] ").upper()
  37. if args.no_confirm or go_ahead == "Y":
  38. for vm in args.domains:
  39. del args.app.domains[vm.name]
  40. retcode = 0
  41. else:
  42. print("Remove cancelled.")
  43. retcode = 1
  44. return retcode
  45. if __name__ == '__main__':
  46. sys.exit(main())