def discover(service_name, host = None, registrar = None, timeout = 2): """ discovers hosts running the given service :param service_name: the service to look for :param host: limit the discovery to the given host only (None means any host) :param registrar: use this registry client to discover services. if None, use the default UDPRegistryClient with the default settings. :param timeout: the number of seconds to wait for a reply from the registry if no hosts are found, raises DiscoveryError :raises: ``DiscoveryError`` if no server is found :returns: a list of (ip, port) pairs """ if registrar is None: registrar = UDPRegistryClient(timeout = timeout) addrs = registrar.discover(service_name) if not addrs: raise DiscoveryError("no servers exposing %r were found" % (service_name,)) if host: ips = socket.gethostbyname_ex(host)[2] addrs = [(h, p) for h, p in addrs if h in ips] if not addrs: raise DiscoveryError("no servers exposing %r were found on %r" % (service_name, host)) return addrs
def discover(service_name, host=None, registrar=None, timeout=2): """ discovers hosts running the given service :param service_name: the service to look for :param host: limit the discovery to the given host only (None means any host) :param registrar: use this registry client to discover services. if None, use the default UDPRegistryClient with the default settings. :param timeout: the number of seconds to wait for a reply from the registry if no hosts are found, raises DiscoveryError :raises: ``DiscoveryError`` if no server is found :returns: a list of (ip, port) pairs """ if registrar is None: registrar = UDPRegistryClient(timeout=timeout) addrs = registrar.discover(service_name) if not addrs: raise DiscoveryError("no servers exposing %r were found" % (service_name,)) if host: ips = socket.gethostbyname_ex(host)[2] addrs = [(h, p) for h, p in addrs if h in ips] if not addrs: raise DiscoveryError("no servers exposing %r were found on %r" % (service_name, host)) return addrs
def service01(): conn = rpyc.connect(host='localhost', port=18861) root = conn.root # MyService object # object print root print root.get_service_name() print root.get_service_aliases() # custom method print root.get_answer() # 66 print root.exposed_get_answer() # 66 # print root.get_question() # AttributeError: cannot access 'get_question' registrar = UDPRegistryClient() list_of_servers = registrar.discover("foo") print rpyc.discover(service_name='MY', host='localhost')
def service01(): conn = rpyc.connect(host='localhost', port=18861) root = conn.root # MyService object # object print root print root.get_service_name() print root.get_service_aliases() # custom method print root.get_answer() # 66 print root.exposed_get_answer() # 66 # print root.get_question() # AttributeError: cannot access 'get_question' registrar = UDPRegistryClient() list_of_servers = registrar.discover("foo") print rpyc.discover(service_name='MY', host='localhost')
def discover(service_name, host = None, registrar = None, timeout = 2): """discovers hosts running the given service service_name - the service to look for host - limit the discovery to the given host only (None means any host) registrar - use this registry client to discover services. if None, use the default UDPRegistryClient with the default settings. timeout - the number of seconds to wait for a reply from the registry if no hosts are found, raises DiscoveryError returns a list of (ip, port) pairs """ if registrar is None: registrar = UDPRegistryClient(timeout=timeout) addrs = registrar.discover(service_name) if not addrs: raise DiscoveryError("no servers exposing {0} were found".format(service_name)) if host: ips = socket.gethostbyname_ex(host)[2] addrs = [(h, p) for h, p in addrs if h in ips] if not addrs: raise DiscoveryError("no servers exposing {0} were found on {1}".format(service_name, host)) return addrs