qvm_start.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # -*- encoding: utf8 -*-
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2017 Marek Marczykowski-Górecki
  6. # <marmarek@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-start - start a domain'''
  21. import sys
  22. import qubesadmin.exc
  23. import qubesadmin.tools
  24. parser = qubesadmin.tools.QubesArgumentParser(
  25. description='start a domain', vmname_nargs='+')
  26. parser.add_argument('--skip-if-running',
  27. action='store_true', default=False,
  28. help='Do not fail if the qube is already runnning')
  29. def main(args=None, app=None):
  30. '''Main routine of :program:`qvm-start`.
  31. :param list args: Optional arguments to override those delivered from \
  32. command line.
  33. '''
  34. args = parser.parse_args(args, app=app)
  35. exit_code = 0
  36. for domain in args.domains:
  37. if args.skip_if_running and domain.is_running():
  38. continue
  39. try:
  40. domain.start()
  41. except (IOError, OSError, qubesadmin.exc.QubesException) as e:
  42. exit_code = 1
  43. parser.print_error(str(e))
  44. return exit_code
  45. if __name__ == '__main__':
  46. sys.exit(main())