2015-09-25 23:29:07 +02:00
|
|
|
#!/usr/bin/python2 -O
|
|
|
|
# vim: fileencoding=utf-8
|
|
|
|
|
|
|
|
#
|
|
|
|
# The Qubes OS Project, https://www.qubes-os.org/
|
|
|
|
#
|
|
|
|
# Copyright (C) 2010-2015 Joanna Rutkowska <joanna@invisiblethingslab.com>
|
|
|
|
# Copyright (C) 2015 Wojtek Porczyk <woju@invisiblethingslab.com>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
'''qvm-start - Start a domain'''
|
|
|
|
|
|
|
|
# TODO notification in tray
|
|
|
|
|
|
|
|
import argparse
|
2016-08-08 00:11:46 +02:00
|
|
|
import os
|
2015-10-05 23:46:25 +02:00
|
|
|
import sys
|
2016-05-18 17:05:25 +02:00
|
|
|
|
2015-09-25 23:29:07 +02:00
|
|
|
import qubes
|
|
|
|
|
2016-05-18 17:05:25 +02:00
|
|
|
|
2015-09-25 23:29:07 +02:00
|
|
|
class DriveAction(argparse.Action):
|
|
|
|
'''Action for argument parser that stores drive image path.'''
|
2016-05-18 17:05:25 +02:00
|
|
|
|
2015-10-05 23:46:25 +02:00
|
|
|
# pylint: disable=redefined-builtin,too-few-public-methods
|
2015-09-25 23:29:07 +02:00
|
|
|
def __init__(self,
|
|
|
|
option_strings,
|
|
|
|
dest='drive',
|
|
|
|
prefix='cdrom:',
|
|
|
|
metavar='IMAGE',
|
|
|
|
required=False,
|
|
|
|
help='Attach drive'):
|
|
|
|
super(DriveAction, self).__init__(option_strings, dest,
|
|
|
|
metavar=metavar, help=help)
|
|
|
|
self.prefix = prefix
|
|
|
|
|
|
|
|
def __call__(self, parser, namespace, values, option_string=None):
|
2015-10-05 23:46:25 +02:00
|
|
|
# pylint: disable=redefined-outer-name
|
|
|
|
setattr(namespace, self.dest, self.prefix + values)
|
2015-09-25 23:29:07 +02:00
|
|
|
|
|
|
|
|
2016-05-18 17:05:25 +02:00
|
|
|
parser = qubes.tools.QubesArgumentParser(vmname_nargs=1,
|
|
|
|
description='start a domain')
|
2015-09-25 23:29:07 +02:00
|
|
|
|
|
|
|
parser_drive = parser.add_mutually_exclusive_group()
|
|
|
|
|
|
|
|
parser_drive.add_argument('--drive', metavar='DRIVE',
|
|
|
|
help='temporarily attach specified drive as CD/DVD or hard disk (can be'
|
|
|
|
' specified with prefix "hd:" or "cdrom:", default is cdrom)')
|
|
|
|
|
|
|
|
parser_drive.add_argument('--hddisk',
|
|
|
|
action=DriveAction, prefix='hd:',
|
|
|
|
help='temporarily attach specified drive as hard disk')
|
|
|
|
|
|
|
|
parser_drive.add_argument('--cdrom', metavar='IMAGE',
|
|
|
|
action=DriveAction, prefix='cdrom:',
|
|
|
|
help='temporarily attach specified drive as CD/DVD')
|
|
|
|
|
|
|
|
parser_drive.add_argument('--install-windows-tools',
|
|
|
|
action='store_const', dest='drive', default=False,
|
|
|
|
const='cdrom:dom0:/usr/lib/qubes/qubes-windows-tools.iso',
|
2016-08-08 00:11:46 +02:00
|
|
|
help='temporarily attach Windows tools CDROM to the domain')
|
2015-09-25 23:29:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
parser.add_argument('--conf-file', metavar='FILE',
|
|
|
|
help='use custom libvirt config instead of Qubes-generated one')
|
|
|
|
|
|
|
|
parser.add_argument('--debug',
|
|
|
|
action='store_true', default=False,
|
|
|
|
help='enable debug mode for this domain (until its shutdown)')
|
|
|
|
|
|
|
|
parser.add_argument('--preparing-dvm',
|
|
|
|
action='store_true', default=False,
|
|
|
|
help='do actions necessary when preparing DVM image')
|
|
|
|
|
|
|
|
parser.add_argument('--no-start-guid',
|
|
|
|
action='store_false', dest='start_guid', default=True,
|
2015-10-05 23:46:25 +02:00
|
|
|
help='do not start the gui daemon (ignored)')
|
2015-09-25 23:29:07 +02:00
|
|
|
|
2016-03-03 01:05:23 +01:00
|
|
|
parser.add_argument('--skip-if-running',
|
|
|
|
action='store_true', default=False,
|
|
|
|
help='Do not fail if the qube is already runnning')
|
|
|
|
|
2015-09-25 23:29:07 +02:00
|
|
|
#parser.add_option ("--tray", action="store_true", dest="tray", default=False,
|
|
|
|
# help="Use tray notifications instead of stdout" )
|
|
|
|
|
|
|
|
parser.set_defaults(drive=None)
|
|
|
|
|
2016-05-18 17:05:25 +02:00
|
|
|
|
2015-09-25 23:29:07 +02:00
|
|
|
def main(args=None):
|
|
|
|
'''Main routine of :program:`qvm-start`.
|
|
|
|
|
|
|
|
:param list args: Optional arguments to override those delivered from \
|
|
|
|
command line.
|
|
|
|
'''
|
|
|
|
|
|
|
|
args = parser.parse_args(args)
|
|
|
|
|
|
|
|
# if options.tray:
|
|
|
|
# tray_notify_init()
|
|
|
|
|
2016-05-18 17:05:25 +02:00
|
|
|
vm = args.domains[0]
|
2015-09-25 23:29:07 +02:00
|
|
|
|
2016-03-03 01:05:23 +01:00
|
|
|
if args.skip_if_running and vm.is_running():
|
|
|
|
return
|
|
|
|
|
2015-09-25 23:29:07 +02:00
|
|
|
if args.drive is not None:
|
|
|
|
if 'drive' not in (prop.__name__ for prop in vm.property_list()):
|
|
|
|
parser.error(
|
|
|
|
'domain {!r} does not support attaching drives'.format(vm.name))
|
2016-08-08 00:11:46 +02:00
|
|
|
else:
|
|
|
|
if args.drive == 'cdrom:dom0:/usr/lib/qubes/qubes-windows-tools.iso':
|
|
|
|
path = args.drive.split(':', 2)[2]
|
|
|
|
if not os.path.exists(path):
|
|
|
|
parser.error('qubes-windows-tools package not installed')
|
2015-09-25 23:29:07 +02:00
|
|
|
|
|
|
|
if args.conf_file is not None:
|
|
|
|
vm.conf_file = args.conf_file
|
|
|
|
|
|
|
|
if args.debug:
|
|
|
|
vm.debug = args.debug
|
|
|
|
|
|
|
|
try:
|
2015-10-05 23:46:25 +02:00
|
|
|
vm.start(
|
2015-09-25 23:29:07 +02:00
|
|
|
preparing_dvm=args.preparing_dvm,
|
|
|
|
start_guid=args.start_guid)
|
2015-10-14 22:02:11 +02:00
|
|
|
except qubes.exc.QubesException as e:
|
2015-10-05 18:06:02 +02:00
|
|
|
parser.error_runtime('Qubes error: {!r}'.format(e))
|
2015-09-25 23:29:07 +02:00
|
|
|
|
2015-12-28 18:14:37 +01:00
|
|
|
return 0
|
2015-09-25 23:29:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2015-12-28 18:14:37 +01:00
|
|
|
sys.exit(main())
|