def run(self): mocked_service = varlink.Service(vendor=self.vendor, product=self.product, version=self.version, url=self.url) instanciated_service = self.service_to_mock() mocked_service._set_interface(self.interface_file, instanciated_service) class ServiceRequestHandler(varlink.RequestHandler): service = mocked_service self.varlink_server = varlink.ThreadingServer(self.address, ServiceRequestHandler) self.varlink_server.serve_forever()
for ret in con.Test10(client_id, ret["mytype"], _more=True): print("Test10:", ret) ret_array.append(ret["string"]) ret = con.Test11(client_id, ret_array, _oneway=True) print("Test11:", ret) ret = con.End(client_id) print("End:", ret) print("Certification passed") ######## SERVER ############# service = varlink.Service( vendor='Varlink', product='Varlink Examples', version='1', url='http://varlink.org', interface_dir=os.path.dirname(__file__) ) class ServiceRequestHandler(varlink.RequestHandler): service = service def sorted_json(dct): if isinstance(dct, type([])): return sorted(dct) return dct
# 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, see <https://www.gnu.org/licenses/>. # vim: fileencoding=utf8 import os import libnmstate.netapplier import libnmstate.netinfo import varlink service = varlink.Service(vendor='Nmstate', product='Nmstate', version='0', url='http://nmstate.io', interface_dir=os.path.dirname(__file__)) class ServiceRequestHandler(varlink.RequestHandler): service = service @service.interface('io.nmstate') class NMState(object): def Get(self): return {"state": libnmstate.netinfo.show()} def Set(self, state): libnmstate.netapplier.apply(state)
# Monkey-patch varlink.scanner # systemd uses uppercase service names, which python-varlink rejects. import varlink.scanner orig_init = varlink.scanner.Scanner.__init__ def scanner_init(self, string): orig_init(self, string) self.patterns['interface-name'] = re.compile(r'[a-z]([-]*[a-z0-9])*([.][a-zA-Z0-9]([-]*[a-zA-Z0-9])*)+') varlink.scanner.Scanner.__init__ = scanner_init SERVICE_NAME = "edu.mit.jupyter.User" varlink_service = varlink.Service( vendor='SIPB', product='JupyterHub', version='1', url='http://jupyter.mit.edu', interface_dir=pkg_resources.resource_filename(__name__, 'interface'), ) class ServiceRequestHandler(varlink.RequestHandler): service = varlink_service class UserDBError(varlink.VarlinkError): def __init__(self): super().__init__({ 'error': 'io.systemd.UserDatabase.' + self.__class__.__name__, 'parameters': {}, }) class NoRecordFound(UserDBError): pass class BadService(UserDBError): pass
Disk enumeration/filtering proof of concept as a varlink service """ import getopt import os import sys import json import varlink from blkinfo.filters import BlkDiskInfo from blkinfo.errors import NoLsblkFound service = varlink.Service(vendor='Red Hat', product='Blkinfo', version='1', url='http://varlink.org', interface_dir=os.path.dirname(__file__)) class ServiceRequestHandler(varlink.RequestHandler): service = service class GetDisksError(varlink.VarlinkError): def __init__(self, reason): varlink.VarlinkError.__init__( self, { 'error': 'com.redhat.blkinfo.ActionFailed', 'parameters': { 'field': reason