0

I have the following case:

  • Two servers running each their own name server (NS)
  • Each of these servers has the same object registering with a different URI. The URI includes the local server's hostname to make it unique
  • A third server, the client, tries to target the right server to query information available only that server

Please note that all of these 3 servers can communicate with each other.

My questions and issues:

  1. The requests from the third server always goes to the first server, no matter what; except when I shutdown the first NS. Is there something definitely wrong with that I'm doing? I guess I do, but I can't figure it out...
  2. Is running separate nameservers the root cause? What would be the alternative if this not allowed? I run multiple name servers for redundancy as some other upcoming operations can run on any of the two first servers. When I list the content of each name server (locally on each server), I get the right registration (which includes the hostname).
  3. Is the use of Pyro4.config.NS_HOST parameter wrong, see below the usage in the code? What would be the alternative?

My configuration:

  • Pyro 4-4.63-1.1
  • Python 2.7.13
  • Linux OpenSuse (kernel version 4.4.92)

The test code is listed below. I got rid of the details like try blocks and imports, etc...

My server skeleton code (which runs on the first two servers):

daemon = Pyro4.Daemon(local_ip_address)
ns = Pyro4.locateNS()
uri = daemon.register(TestObject())
ns.register("test.object@%s" % socket.gethostname(), uri)
daemon.requestLoop()

The local_ip_address is the one supplied below by the user to contact the correct name server (on the correct server).

The name server is started on each of the first tow servers as follows:

python -m Pyro4.naming -n local_ip_address

The local_ip_address is the same as above.

My client skeleton code (which runs on the third server):

target_server_hostname = user_provided_hostname
target_server_ip = user_provided_ip

Pyro4.config.NS_HOST = target_server_ip
uri = "test.object@%s" % target_server_hostname 
proxy = Pyro4.Proxy(uri)
proxy._pyroTimeout = my_timeout
proxy._pyroMaxRetries = my_retries

rc, reason = proxy.testAction(target_server_hostname)
if rc != 0:
  print reason
else:
  print "Hostname matches"

If more information is required, please let me know.

Djurdjura.

Djurdjura H.
  • 99
  • 2
  • 9
  • Your client code running on the third server seems incomplete. It doesn't DO anything with the name server! Your proxy connects immediately to the fixed uri at ``target_server_hostname`` which is always the same I guess? Is that intentional> – Irmen de Jong Jan 16 '18 at 20:32

1 Answers1

0

I think figured it out. Hope this will be useful to anyone else looking for a similar use case.

You just need to specify where to look for the name server itself. The client code becomes something like the following:

target_server_hostname = user_provided_hostname
target_server_ip = user_provided_ip

# The following statement finds the correct name server
ns = Pyro4.locateNS(host=target_server_ip)

name = "test.object@%s" % target_server_hostname
uri = ns.lookup(name)
proxy = Pyro4.Proxy(uri)
proxy._pyroTimeout = my_timeout
proxy._pyroMaxRetries = my_retries

rc, reason = proxy.testAction(target_server_hostname)
if rc != 0:
  print reason
else:
  print "Hostname matches"

In my case, I guess the alternative would be using a single common name server running on ... the third server (the client server). This server is always on and ready before the other ones. I didn't try this approach one yet.

Regards.

D.

PS. Thanks Irmen for your answer.

Djurdjura H.
  • 99
  • 2
  • 9
  • You could use the URI of the form "PYRONAME:test.object" as well, Pyro will query the name server for you automatically then. Omit the @hostname btw that should not be part of a logical name. – Irmen de Jong Jan 18 '18 at 00:24