app.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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. '''
  21. Main Qubes() class and related classes.
  22. '''
  23. import os
  24. import shlex
  25. import socket
  26. import subprocess
  27. import sys
  28. import logging
  29. import qubesadmin.base
  30. import qubesadmin.exc
  31. import qubesadmin.label
  32. import qubesadmin.storage
  33. import qubesadmin.utils
  34. import qubesadmin.vm
  35. import qubesadmin.config
  36. BUF_SIZE = 4096
  37. class VMCollection(object):
  38. '''Collection of VMs objects'''
  39. def __init__(self, app):
  40. self.app = app
  41. self._vm_list = None
  42. self._vm_objects = {}
  43. def clear_cache(self):
  44. '''Clear cached list of VMs'''
  45. self._vm_list = None
  46. def refresh_cache(self, force=False):
  47. '''Refresh cached list of VMs'''
  48. if not force and self._vm_list is not None:
  49. return
  50. vm_list_data = self.app.qubesd_call(
  51. 'dom0',
  52. 'admin.vm.List'
  53. )
  54. new_vm_list = {}
  55. # FIXME: this will probably change
  56. for vm_data in vm_list_data.splitlines():
  57. vm_name, props = vm_data.decode('ascii').split(' ', 1)
  58. vm_name = str(vm_name)
  59. props = props.split(' ')
  60. new_vm_list[vm_name] = dict(
  61. [vm_prop.split('=', 1) for vm_prop in props])
  62. self._vm_list = new_vm_list
  63. for name, vm in list(self._vm_objects.items()):
  64. if vm.name not in self._vm_list:
  65. # VM no longer exists
  66. del self._vm_objects[name]
  67. elif vm.__class__.__name__ != self._vm_list[vm.name]['class']:
  68. # VM class have changed
  69. del self._vm_objects[name]
  70. # TODO: some generation ID, to detect VM re-creation
  71. elif name != vm.name:
  72. # renamed
  73. self._vm_objects[vm.name] = vm
  74. del self._vm_objects[name]
  75. def __getitem__(self, item):
  76. if not self.app.blind_mode and item not in self:
  77. raise KeyError(item)
  78. return self.get_blind(item)
  79. def get_blind(self, item):
  80. '''
  81. Get a vm without downloading the list
  82. and checking if exists
  83. '''
  84. if item not in self._vm_objects:
  85. cls = qubesadmin.vm.QubesVM
  86. # provide class name to constructor, if already cached (which can be
  87. # done by 'item not in self' check above, unless blind_mode is
  88. # enabled
  89. klass = None
  90. if self._vm_list and item in self._vm_list:
  91. klass = self._vm_list[item]['class']
  92. self._vm_objects[item] = cls(self.app, item, klass=klass)
  93. return self._vm_objects[item]
  94. def __contains__(self, item):
  95. self.refresh_cache()
  96. return item in self._vm_list
  97. def __delitem__(self, key):
  98. self.app.qubesd_call(key, 'admin.vm.Remove')
  99. self.clear_cache()
  100. def __iter__(self):
  101. self.refresh_cache()
  102. for vm in sorted(self._vm_list):
  103. yield self[vm]
  104. def keys(self):
  105. '''Get list of VM names.'''
  106. self.refresh_cache()
  107. return self._vm_list.keys()
  108. def values(self):
  109. '''Get list of VM objects.'''
  110. self.refresh_cache()
  111. return [self[name] for name in self._vm_list]
  112. class QubesBase(qubesadmin.base.PropertyHolder):
  113. '''Main Qubes application'''
  114. #: domains (VMs) collection
  115. domains = None
  116. #: labels collection
  117. labels = None
  118. #: storage pools
  119. pools = None
  120. #: type of qubesd connection: either 'socket' or 'qrexec'
  121. qubesd_connection_type = None
  122. #: logger
  123. log = None
  124. #: do not check for object (VM, label etc) existence before really needed
  125. blind_mode = False
  126. def __init__(self):
  127. super(QubesBase, self).__init__(self, 'admin.property.', 'dom0')
  128. self.domains = VMCollection(self)
  129. self.labels = qubesadmin.base.WrapperObjectsCollection(
  130. self, 'admin.label.List', qubesadmin.label.Label)
  131. self.pools = qubesadmin.base.WrapperObjectsCollection(
  132. self, 'admin.pool.List', qubesadmin.storage.Pool)
  133. #: cache for available storage pool drivers and options to create them
  134. self._pool_drivers = None
  135. self.log = logging.getLogger('app')
  136. def _refresh_pool_drivers(self):
  137. '''
  138. Refresh cached storage pool drivers and their parameters.
  139. :return: None
  140. '''
  141. if self._pool_drivers is None:
  142. pool_drivers_data = self.qubesd_call(
  143. 'dom0', 'admin.pool.ListDrivers', None, None)
  144. assert pool_drivers_data.endswith(b'\n')
  145. pool_drivers = {}
  146. for driver_line in pool_drivers_data.decode('ascii').splitlines():
  147. if not driver_line:
  148. continue
  149. driver_name, driver_options = driver_line.split(' ', 1)
  150. pool_drivers[driver_name] = driver_options.split(' ')
  151. self._pool_drivers = pool_drivers
  152. @property
  153. def pool_drivers(self):
  154. ''' Available storage pool drivers '''
  155. self._refresh_pool_drivers()
  156. return self._pool_drivers.keys()
  157. def pool_driver_parameters(self, driver):
  158. ''' Parameters to initialize storage pool using given driver '''
  159. self._refresh_pool_drivers()
  160. return self._pool_drivers[driver]
  161. def add_pool(self, name, driver, **kwargs):
  162. ''' Add a storage pool to config
  163. :param name: name of storage pool to create
  164. :param driver: driver to use, see :py:meth:`pool_drivers` for
  165. available drivers
  166. :param kwargs: configuration parameters for storage pool,
  167. see :py:meth:`pool_driver_parameters` for a list
  168. '''
  169. # sort parameters only to ease testing, not required by API
  170. payload = 'name={}\n'.format(name) + \
  171. ''.join('{}={}\n'.format(key, value)
  172. for key, value in sorted(kwargs.items()))
  173. self.qubesd_call('dom0', 'admin.pool.Add', driver,
  174. payload.encode('utf-8'))
  175. def remove_pool(self, name):
  176. ''' Remove a storage pool '''
  177. self.qubesd_call('dom0', 'admin.pool.Remove', name, None)
  178. def get_label(self, label):
  179. '''Get label as identified by index or name
  180. :throws KeyError: when label is not found
  181. '''
  182. # first search for name, verbatim
  183. try:
  184. return self.labels[label]
  185. except KeyError:
  186. pass
  187. # then search for index
  188. if label.isdigit():
  189. for i in self.labels:
  190. if i.index == int(label):
  191. return i
  192. raise KeyError(label)
  193. @staticmethod
  194. def get_vm_class(clsname):
  195. '''Find the class for a domain.
  196. Compatibility function, client tools use str to identify domain classes.
  197. :param str clsname: name of the class
  198. :return str: class
  199. '''
  200. return clsname
  201. def add_new_vm(self, cls, name, label, template=None, pool=None,
  202. pools=None):
  203. '''Create new Virtual Machine
  204. Example usage with custom storage pools:
  205. >>> app = qubesadmin.Qubes()
  206. >>> pools = {'private': 'external'}
  207. >>> vm = app.add_new_vm('AppVM', 'my-new-vm', 'red',
  208. >>> 'my-template', pools=pools)
  209. >>> vm.netvm = app.domains['sys-whonix']
  210. :param str cls: name of VM class (`AppVM`, `TemplateVM` etc)
  211. :param str name: name of VM
  212. :param str label: label color for new VM
  213. :param str template: template to use (if apply for given VM class),
  214. can be also VM object; use None for default value
  215. :param str pool: storage pool to use instead of default one
  216. :param dict pools: storage pool for specific volumes
  217. :return new VM object
  218. '''
  219. if not isinstance(cls, str):
  220. cls = cls.__name__
  221. if template is qubesadmin.DEFAULT:
  222. template = None
  223. elif template is not None:
  224. template = str(template)
  225. if pool and pools:
  226. raise ValueError('only one of pool= and pools= can be used')
  227. method_prefix = 'admin.vm.Create.'
  228. payload = 'name={} label={}'.format(name, label)
  229. if pool:
  230. payload += ' pool={}'.format(str(pool))
  231. method_prefix = 'admin.vm.CreateInPool.'
  232. if pools:
  233. payload += ''.join(' pool:{}={}'.format(vol, str(pool))
  234. for vol, pool in sorted(pools.items()))
  235. method_prefix = 'admin.vm.CreateInPool.'
  236. self.qubesd_call('dom0', method_prefix + cls, template,
  237. payload.encode('utf-8'))
  238. self.domains.clear_cache()
  239. return self.domains[name]
  240. def clone_vm(self, src_vm, new_name, new_cls=None,
  241. pool=None, pools=None, ignore_errors=False, ignore_volumes=None):
  242. '''Clone Virtual Machine
  243. Example usage with custom storage pools:
  244. >>> app = qubesadmin.Qubes()
  245. >>> pools = {'private': 'external'}
  246. >>> src_vm = app.domains['personal']
  247. >>> vm = app.clone_vm(src_vm, 'my-new-vm', pools=pools)
  248. >>> vm.label = app.labels['green']
  249. :param QubesVM or str src_vm: source VM
  250. :param str new_name: name of new VM
  251. :param str new_cls: name of VM class (`AppVM`, `TemplateVM` etc) - use
  252. None to copy it from *src_vm*
  253. :param str pool: storage pool to use instead of default one
  254. :param dict pools: storage pool for specific volumes
  255. :param bool ignore_errors: should errors on meta-data setting be only
  256. logged, or abort the whole operation?
  257. :param list ignore_volumes: do not clone volumes on this list,
  258. like 'private' or 'root'
  259. :return new VM object
  260. '''
  261. if pool and pools:
  262. raise ValueError('only one of pool= and pools= can be used')
  263. if isinstance(src_vm, str):
  264. src_vm = self.domains[src_vm]
  265. if new_cls is None:
  266. new_cls = src_vm.klass
  267. template = getattr(src_vm, 'template', None)
  268. if template is not None:
  269. template = str(template)
  270. label = src_vm.label
  271. method_prefix = 'admin.vm.Create.'
  272. payload = 'name={} label={}'.format(new_name, label)
  273. if pool:
  274. payload += ' pool={}'.format(str(pool))
  275. method_prefix = 'admin.vm.CreateInPool.'
  276. if pools:
  277. payload += ''.join(' pool:{}={}'.format(vol, str(pool))
  278. for vol, pool in sorted(pools.items()))
  279. method_prefix = 'admin.vm.CreateInPool.'
  280. self.qubesd_call('dom0', method_prefix + new_cls, template,
  281. payload.encode('utf-8'))
  282. self.domains.clear_cache()
  283. dst_vm = self.domains[new_name]
  284. try:
  285. assert isinstance(dst_vm, qubesadmin.vm.QubesVM)
  286. for prop in src_vm.property_list():
  287. # handled by admin.vm.Create call
  288. if prop in ('name', 'qid', 'template', 'label', 'uuid',
  289. 'installed_by_rpm'):
  290. continue
  291. if src_vm.property_is_default(prop):
  292. continue
  293. try:
  294. setattr(dst_vm, prop, getattr(src_vm, prop))
  295. except AttributeError:
  296. pass
  297. except qubesadmin.exc.QubesException as e:
  298. dst_vm.log.error(
  299. 'Failed to set {!s} property: {!s}'.format(prop, e))
  300. if not ignore_errors:
  301. raise
  302. for tag in src_vm.tags:
  303. if tag.startswith('created-by-'):
  304. continue
  305. try:
  306. dst_vm.tags.add(tag)
  307. except qubesadmin.exc.QubesException as e:
  308. dst_vm.log.error(
  309. 'Failed to add {!s} tag: {!s}'.format(tag, e))
  310. if not ignore_errors:
  311. raise
  312. for feature, value in src_vm.features.items():
  313. try:
  314. dst_vm.features[feature] = value
  315. except qubesadmin.exc.QubesException as e:
  316. dst_vm.log.error(
  317. 'Failed to set {!s} feature: {!s}'.format(feature, e))
  318. if not ignore_errors:
  319. raise
  320. try:
  321. dst_vm.firewall.save_rules(src_vm.firewall.rules)
  322. except qubesadmin.exc.QubesException as e:
  323. self.log.error('Failed to set firewall: %s', e)
  324. if not ignore_errors:
  325. raise
  326. try:
  327. # FIXME: convert to qrexec calls to dom0/GUI VM
  328. appmenus_cmd = \
  329. ['qvm-appmenus', '--init', '--update',
  330. '--source', src_vm.name, dst_vm.name]
  331. subprocess.check_output(appmenus_cmd, stderr=subprocess.STDOUT)
  332. except OSError:
  333. # this file needs to be python 2.7 compatible,
  334. # so no FileNotFoundError
  335. self.log.error('Failed to clone appmenus, qvm-appmenus missing')
  336. if not ignore_errors:
  337. raise qubesadmin.exc.QubesException(
  338. 'Failed to clone appmenus')
  339. except subprocess.CalledProcessError as e:
  340. self.log.error('Failed to clone appmenus: %s',
  341. e.output.decode())
  342. if not ignore_errors:
  343. raise qubesadmin.exc.QubesException(
  344. 'Failed to clone appmenus')
  345. except qubesadmin.exc.QubesException:
  346. if not ignore_errors:
  347. del self.domains[dst_vm.name]
  348. raise
  349. try:
  350. for dst_volume in sorted(dst_vm.volumes.values()):
  351. if not dst_volume.save_on_stop:
  352. # clone only persistent volumes
  353. continue
  354. if ignore_volumes and dst_volume.name in ignore_volumes:
  355. continue
  356. src_volume = src_vm.volumes[dst_volume.name]
  357. dst_vm.log.info('Cloning {} volume'.format(dst_volume.name))
  358. dst_volume.clone(src_volume)
  359. except qubesadmin.exc.QubesException:
  360. del self.domains[dst_vm.name]
  361. raise
  362. return dst_vm
  363. def run_service(self, dest, service, filter_esc=False, user=None,
  364. localcmd=None, wait=True, **kwargs):
  365. '''Run qrexec service in a given destination
  366. *kwargs* are passed verbatim to :py:meth:`subprocess.Popen`.
  367. :param str dest: Destination - may be a VM name or empty
  368. string for default (for a given service)
  369. :param str service: service name
  370. :param bool filter_esc: filter escape sequences to protect terminal \
  371. emulator
  372. :param str user: username to run service as
  373. :param str localcmd: Command to connect stdin/stdout to
  374. :rtype: subprocess.Popen
  375. '''
  376. raise NotImplementedError
  377. class QubesLocal(QubesBase):
  378. '''Application object communicating through local socket.
  379. Used when running in dom0.
  380. '''
  381. qubesd_connection_type = 'socket'
  382. def qubesd_call(self, dest, method, arg=None, payload=None,
  383. payload_stream=None):
  384. '''
  385. Execute Admin API method.
  386. Only one of `payload` and `payload_stream` can be specified.
  387. :param dest: Destination VM name
  388. :param method: Full API method name ('admin...')
  389. :param arg: Method argument (if any)
  390. :param payload: Payload send to the method
  391. :param payload_stream: file-like object to read payload from
  392. :return: Data returned by qubesd (string)
  393. .. warning:: *payload_stream* will get closed by this function
  394. '''
  395. if payload and payload_stream:
  396. raise ValueError(
  397. 'Only one of payload and payload_stream can be used')
  398. if payload_stream:
  399. # payload_stream can be used for large amount of data,
  400. # so optimize for throughput, not latency: spawn actual qrexec
  401. # service implementation, which may use some optimization there (
  402. # see admin.vm.volume.Import - actual data handling is done with dd)
  403. method_path = os.path.join(
  404. qubesadmin.config.QREXEC_SERVICES_DIR, method)
  405. if not os.path.exists(method_path):
  406. raise qubesadmin.exc.QubesDaemonCommunicationError(
  407. '{} not found'.format(method_path))
  408. command = ['env', 'QREXEC_REMOTE_DOMAIN=dom0',
  409. 'QREXEC_REQUESTED_TARGET=' + dest, method_path, arg]
  410. if os.getuid() != 0:
  411. command.insert(0, 'sudo')
  412. proc = subprocess.Popen(command, stdin=payload_stream,
  413. stdout=subprocess.PIPE)
  414. payload_stream.close()
  415. (return_data, _) = proc.communicate()
  416. return self._parse_qubesd_response(return_data)
  417. try:
  418. client_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
  419. client_socket.connect(qubesadmin.config.QUBESD_SOCKET)
  420. except (IOError, OSError) as e:
  421. raise qubesadmin.exc.QubesDaemonCommunicationError(
  422. 'Failed to connect to qubesd service: %s', str(e))
  423. # src, method, dest, arg
  424. for call_arg in ('dom0', method, dest, arg):
  425. if call_arg is not None:
  426. client_socket.sendall(call_arg.encode('ascii'))
  427. client_socket.sendall(b'\0')
  428. if payload is not None:
  429. client_socket.sendall(payload)
  430. client_socket.shutdown(socket.SHUT_WR)
  431. return_data = client_socket.makefile('rb').read()
  432. client_socket.close()
  433. return self._parse_qubesd_response(return_data)
  434. def run_service(self, dest, service, filter_esc=False, user=None,
  435. localcmd=None, wait=True, **kwargs):
  436. '''Run qrexec service in a given destination
  437. :param str dest: Destination - may be a VM name or empty
  438. string for default (for a given service)
  439. :param str service: service name
  440. :param bool filter_esc: filter escape sequences to protect terminal \
  441. emulator
  442. :param str user: username to run service as
  443. :param str localcmd: Command to connect stdin/stdout to
  444. :param bool wait: wait for remote process to finish
  445. :param int connect_timeout: qrexec client connection timeout
  446. :rtype: subprocess.Popen
  447. '''
  448. if not dest:
  449. raise ValueError('Empty destination name allowed only from a VM')
  450. if not wait and localcmd:
  451. raise ValueError('wait=False incompatible with localcmd')
  452. try:
  453. self.qubesd_call(dest, 'admin.vm.Start')
  454. except qubesadmin.exc.QubesVMNotHaltedError:
  455. pass
  456. qrexec_opts = ['-d', dest]
  457. if filter_esc:
  458. qrexec_opts.extend(['-t'])
  459. if filter_esc or os.isatty(sys.stderr.fileno()):
  460. qrexec_opts.extend(['-T'])
  461. if localcmd:
  462. qrexec_opts.extend(['-l', localcmd])
  463. if user is None:
  464. user = 'DEFAULT'
  465. if not wait:
  466. qrexec_opts.extend(['-e'])
  467. if 'connect_timeout' in kwargs:
  468. qrexec_opts.extend(['-w', str(kwargs.pop('connect_timeout'))])
  469. kwargs.setdefault('stdin', subprocess.PIPE)
  470. kwargs.setdefault('stdout', subprocess.PIPE)
  471. kwargs.setdefault('stderr', subprocess.PIPE)
  472. proc = subprocess.Popen([qubesadmin.config.QREXEC_CLIENT] +
  473. qrexec_opts + ['{}:QUBESRPC {} dom0'.format(user, service)],
  474. **kwargs)
  475. return proc
  476. class QubesRemote(QubesBase):
  477. '''Application object communicating through qrexec services.
  478. Used when running in VM.
  479. '''
  480. qubesd_connection_type = 'qrexec'
  481. def qubesd_call(self, dest, method, arg=None, payload=None,
  482. payload_stream=None):
  483. '''
  484. Execute Admin API method.
  485. Only one of `payload` and `payload_stream` can be specified.
  486. :param dest: Destination VM name
  487. :param method: Full API method name ('admin...')
  488. :param arg: Method argument (if any)
  489. :param payload: Payload send to the method
  490. :param payload_stream: file-like object to read payload from
  491. :return: Data returned by qubesd (string)
  492. .. warning:: *payload_stream* will get closed by this function
  493. '''
  494. if payload and payload_stream:
  495. raise ValueError(
  496. 'Only one of payload and payload_stream can be used')
  497. service_name = method
  498. if arg is not None:
  499. service_name += '+' + arg
  500. p = subprocess.Popen([qubesadmin.config.QREXEC_CLIENT_VM,
  501. dest, service_name],
  502. stdin=(payload_stream or subprocess.PIPE),
  503. stdout=subprocess.PIPE,
  504. stderr=subprocess.PIPE)
  505. if payload_stream is not None:
  506. payload_stream.close()
  507. (stdout, stderr) = p.communicate(payload)
  508. if p.returncode != 0:
  509. raise qubesadmin.exc.QubesDaemonNoResponseError(
  510. 'Service call error: %s', stderr.decode())
  511. return self._parse_qubesd_response(stdout)
  512. def run_service(self, dest, service, filter_esc=False, user=None,
  513. localcmd=None, wait=True, **kwargs):
  514. '''Run qrexec service in a given destination
  515. :param str dest: Destination - may be a VM name or empty
  516. string for default (for a given service)
  517. :param str service: service name
  518. :param bool filter_esc: filter escape sequences to protect terminal \
  519. emulator
  520. :param str user: username to run service as
  521. :param str localcmd: Command to connect stdin/stdout to
  522. :param bool wait: wait for process to finish
  523. :rtype: subprocess.Popen
  524. '''
  525. if filter_esc:
  526. raise NotImplementedError(
  527. 'filter_esc not implemented for calls from VM')
  528. if user:
  529. raise ValueError(
  530. 'non-default user not possible for calls from VM')
  531. if not wait and localcmd:
  532. raise ValueError('wait=False incompatible with localcmd')
  533. if not wait:
  534. # qrexec-client-vm can only request service calls, which are
  535. # started using MSG_EXEC_CMDLINE qrexec protocol message; this
  536. # message means "start the process, pipe its stdin/out/err,
  537. # and when it terminates, send exit code back".
  538. # According to the protocol qrexec-client-vm needs to wait for
  539. # MSG_DATA_EXIT_CODE, so implementing wait=False would require
  540. # some protocol change (or protocol violation).
  541. raise NotImplementedError(
  542. 'wait=False not implemented for calls from VM')
  543. kwargs.setdefault('stdin', subprocess.PIPE)
  544. kwargs.setdefault('stdout', subprocess.PIPE)
  545. kwargs.setdefault('stderr', subprocess.PIPE)
  546. proc = subprocess.Popen([qubesadmin.config.QREXEC_CLIENT_VM,
  547. dest or '', service] + (shlex.split(localcmd) if localcmd else []),
  548. **kwargs)
  549. return proc