async def debug(self, engine, options): """ Setup middlewared for remote debugging. engines: - PTVS: Python Visual Studio - PYDEV: Python Dev (Eclipse/PyCharm) options: - secret: password for PTVS - host: required for PYDEV, hostname of local computer (developer workstation) - local_path: required for PYDEV, path for middlewared source in local computer (e.g. /home/user/freenas/src/middlewared/middlewared """ if engine == 'PTVS': import ptvsd if 'secret' not in options: raise ValidationError('secret', 'secret is required for PTVS') ptvsd.enable_attach( options['secret'], address=(options['bind_address'], options['bind_port']), ) if options['wait_attach']: ptvsd.wait_for_attach() elif engine == 'PYDEV': for i in ('host', 'local_path'): if i not in options: raise ValidationError(i, f'{i} is required for PYDEV') os.environ['PATHS_FROM_ECLIPSE_TO_PYTHON'] = json.dumps([ [options['local_path'], '/usr/local/lib/python3.7/site-packages/middlewared'], ]) import pydevd pydevd.stoptrace() pydevd.settrace(host=options['host'])
def __debug(self, engine, options): if engine == 'PTVS': import ptvsd if 'secret' not in options: raise ValidationError('secret', 'secret is required for PTVS') ptvsd.enable_attach( options['secret'], address=(options['bind_address'], options['bind_port']), ) if options['wait_attach']: ptvsd.wait_for_attach() elif engine == 'PYDEV': for i in ('host', 'local_path'): if i not in options: raise ValidationError(i, f'{i} is required for PYDEV') os.environ['PATHS_FROM_ECLIPSE_TO_PYTHON'] = json.dumps([ [ options['local_path'], '/usr/local/lib/python3.7/site-packages/middlewared' ], ]) import pydevd pydevd.stoptrace() pydevd.settrace(host=options['host']) elif engine == 'REMOTE_PDB': from remote_pdb import RemotePdb RemotePdb(options['bind_address'], options['bind_port']).set_trace()
async def _get_instance(self, id): """ Helpher method to get an instance from a collection given the `id`. """ instance = await self.middleware.call(f'{self._config.namespace}.query', [('id', '=', id)]) if not instance: raise ValidationError(None, f'{self._config.verbose_name} {id} does not exist', errno.ENOENT) return instance[0]
async def _get_instance(self, id): """ Helper method to get an instance from a collection given the `id`. """ instance = await self.middleware.call( f'{self._config.namespace}.query', [[self._config.datastore_primary_key, '=', id]], {'force_sql_filters': True} ) if not instance: raise ValidationError(None, f'{self._config.verbose_name} {id} does not exist', errno.ENOENT) return instance[0]