def main(): parser = get_parser() args = parser.parse_args() logging.setup_logging() logger = get_logger() logger.msg('metaserver.starting') redis = ProtocolConnector(reactor, 'localhost', 6379, RedisClient) srv = MetadataManager(redis, IPD_MANAGER_KEY.public()) srv.register_host( 'ipd1.tic.hefr.ch', TCP4LibvirtEndpoint(reactor, 'ipd1.tic.hefr.ch', 16509, 'qemu', 'system'), ) site = server.Site(MetadataRootResource(srv)) endpoint = endpoints.TCP4ServerEndpoint(reactor, args.port) endpoint.listen(site) reactor.run()
def main(): parser = get_parser() args = parser.parse_args() logging.setup_logging() logger = get_logger() logger.msg('metaproxy.starting') upstream = args.upstream.split(':') if len(upstream) == 1: host, port = upstream[0], 80 else: host, port = upstream[0], int(upstream[1]) if port is None: port = 80 driver, transport = args.libvirtd.scheme.split('+') mode = args.libvirtd.path.lstrip('/') virt_host = args.libvirtd.hostname virt_port = args.libvirtd.port or 16509 logger.msg('metaproxy.hypervisor', host=virt_host, port=virt_port, driver=driver, mode=mode, transport=transport) if transport == 'tcp': libvirt = TCP4LibvirtEndpoint(reactor, virt_host, virt_port, driver, mode) else: print('Transport {!r} not supported'.format(transport)) sys.exit(1) resolver = DomainResolver(libvirt) logger.msg('metaproxy.upstream', host=host, port=port) res = LibvirtMetaReverseProxyResource(resolver, host, port, '') site = server.Site(res) reactor.listenTCP(args.port, site) reactor.run()
def main(): parser = get_parser() args = parser.parse_args() logging.setup_logging() grammar_file = os.path.join(os.path.dirname( libvirt.__file__), 'idl.grammar') with open(grammar_file, 'rb') as fh: grammar = parsley.makeGrammar(fh.read(), { 'struct': Structure, 'enum': Enumeration, 'const': Constant, 'typedef': TypeDefinition, 'ref': Reference, 'union': Union, 'optional': Optional, 'integer': Integer, 'type': Type, 'fixed_array': FixedLengthArray, 'variable_array': VariableLengthArray, 'declaration': Declaration, }) with open(args.source) as fh: source = fh.read() tokens = grammar(source).tokens() constants = OrderedDict({ 'VIR_SECURITY_MODEL_BUFLEN': 257, 'VIR_SECURITY_LABEL_BUFLEN': 4097, 'VIR_SECURITY_DOI_BUFLEN': 257, 'VIR_UUID_BUFLEN': 16, }) types = OrderedDict({k:k for k in xdrtypes.TYPES}) types['string'] = '__string__' types['opaque'] = '__opaque__' try: for token in tokens: token.process_context(types, constants) except: for k, v in constants.iteritems(): print('{:<45} {}'.format(k, v)) print('-------------') for k, v in types.iteritems(): print('{:<45} {}'.format(k, v)) raise import re, sys def to_camelcase(s): s = s.capitalize() return re.sub(r'(?!^)_([a-zA-Z])', lambda m: m.group(1).upper(), s) cmdline = ' '.join(quote(a) for a in sys.argv[1:]) with open(args.dest, 'w') as fh: fh.write( '"""\n' 'Automatically generated Libvirt protocol specification.\n\n' 'Do not modify this file manually, as the changes will be overwritten\n' 'the next time that the generation script is run!\n\n' ' Generated on: {}\n' ' Command line: gen-libvirt-protocol {}\n\n' '"""\n\n'.format(datetime.datetime.now().isoformat(), cmdline) ) fh.write('from ipd.libvirt.procedures import ProcedureBase\n') fh.write('from ipd.libvirt.types import char, short, int, hyper\n') fh.write('from ipd.libvirt.types import uchar, ushort, uint, uhyper\n') fh.write('from ipd.libvirt.types import fstring, string, fopaque, opaque\n') fh.write('from ipd.libvirt.types import farray, array, optional\n') fh.write('from ipd.libvirt.types import not_implemented, compound, enum\n') fh.write('\n\n') fh.write('PROGRAM = {}\n'.format(hex(constants['REMOTE_PROGRAM']))) fh.write('PROTOCOL_VERSION = {}\n\n'.format(hex(constants['REMOTE_PROTOCOL_VERSION']))) for name, type in types.iteritems(): if name in set(['remote_procedure']): continue if not isinstance(type, (xdrtypes.ComplexType, xdrtypes.Enum)): continue if name.startswith('remote_'): name = name[len('remote_'):] if isinstance(type, xdrtypes.Enum): fh.write('{} = enum({!r}, [\n'.format(name, name)) for k, v in type.values: fh.write(' ({!r}, {}),\n'.format(k, v)) fh.write('])\n\n') continue fh.write('{} = compound({!r}, [\n'.format(name, name)) for k, v in type.fields: if isinstance(v, xdrtypes.ComplexType): v = v.name if v.startswith('remote_'): v = v[len('remote_'):] fh.write(' ({!r}, {}),\n'.format(k, v)) fh.write('])\n\n') for k, v in types['remote_procedure']: _, _, k = k.lower().split('_', 2) args_struct_name = 'remote_' + k + '_args' ret_struct_name = 'remote_' + k + '_ret' try: args = types[args_struct_name] except KeyError: args = None try: ret = types[ret_struct_name] except KeyError: ret = None name = to_camelcase(k) fh.write('class {}(ProcedureBase):\n'.format(name)) fh.write(' id = {}\n'.format(v)) fh.write(' name = {!r}\n'.format(k)) fh.write(' args = {}\n'.format(args.name if args else None)) fh.write(' ret = {}\n'.format(ret.name if ret else None)) fh.write('\n') fh.write('PROCEDURE_BY_NAME = {\n') for k, v in types['remote_procedure']: _, _, k = k.lower().split('_', 2) name = to_camelcase(k) fh.write(' {!r}: {},\n'.format(k, name)) fh.write('}\n') fh.write('PROCEDURE_BY_ID = {\n') for k, v in types['remote_procedure']: _, _, k = k.lower().split('_', 2) name = to_camelcase(k) fh.write(' {}: {},\n'.format(v, name)) fh.write('}\n')