osbrain.proxy — osBrain proxy logic

Implementation of proxy-related features.

class osbrain.proxy.NSProxy(nsaddr=None, timeout=3)

Bases: Pyro4.core.Proxy

A proxy to access a name server.

Parameters:
  • nsaddr (SocketAddress, str) – Name server address.
  • timeout (float) – Timeout, in seconds, to wait until the name server is discovered.
addr(agent_alias=None, address_alias=None)

Return the name server address or the address of an agent’s socket.

Parameters:
  • agent_alias (str, default is None) – The alias of the agent to retrieve its socket address.
  • address_alias (str, default is None) – The alias of the socket address to retrieve from the agent.
Returns:

The name server or agent’s socket address.

Return type:

SocketAddress or AgentAddress

proxy(name, timeout=3.0)

Get a proxy to access an agent registered in the name server.

Parameters:
  • name (str) – Proxy name, as registered in the name server.
  • timeout (float) – Timeout, in seconds, to wait until the agent is discovered.
Returns:

A proxy to access an agent registered in the name server.

Return type:

Proxy

release()

Release the connection to the Pyro daemon.

shutdown(timeout=10.0)

Shutdown the name server. All agents will be shutdown as well.

Parameters:timeout (float, default is 10.) – Timeout, in seconds, to wait for the agents to shutdown.
shutdown_agents(timeout=10.0)

Shutdown all agents registered in the name server.

Parameters:timeout (float, default is 10.) – Timeout, in seconds, to wait for the agents to shutdown.
class osbrain.proxy.Proxy(name, nsaddr=None, timeout=3.0, safe=None)

Bases: Pyro4.core.Proxy

A proxy to access remote agents.

Parameters:
  • name (str) – Proxy name, as registered in the name server.
  • nsaddr (SocketAddress, str) – Name server address.
  • timeout (float) – Timeout, in seconds, to wait until the agent is discovered.
  • safe (bool, default is None) – Use safe calls by default. When not set, osbrain default’s osbrain.config['SAFE'] is used.
nsaddr()

Get the socket address of the name server.

Returns:The socket address.
Return type:SocketAddress
oneway

Make the next remote method call be one way.

Returns:
Return type:The proxy itself.
release()

Release the connection to the Pyro daemon.

safe

Make the next remote method call be safe.

Returns:
Return type:The proxy itself.
unsafe

Make the next remote method call be unsafe.

Returns:
Return type:The proxy itself.
wait_for_running(timeout=3.0)

Wait until the agent is running.

Parameters:timeout (float) – Raise and exception if the agent is not running after this number of seconds. Use a negative value to wait forever.
Raises:TimeoutError – If the agent is not running after the given timeout.
Returns:The object itself.
Return type:Proxy
osbrain.proxy.locate_ns(nsaddr, timeout=3.0)

Locate a name server to ensure it actually exists.

Parameters:
  • nsaddr (SocketAddress) – The address where the name server should be up and running.
  • timeout (float) – Timeout in seconds before aborting location.
Returns:

The address where the name server was located.

Return type:

nsaddr

Raises:

NamingError – If the name server could not be located.