Package ganeti :: Package rpc :: Module transport :: Class Transport
[hide private]
[frames] | no frames]

Class Transport

source code

Low-level transport class.

This is used on the client side.

This could be replaced by any other class that provides the same semantics to the Client. This means:

Instance Methods [hide private]
 
__init__(self, address, timeouts=None, allow_non_master=None)
Constructor for the Client class.
source code
 
_CheckSocket(self)
Make sure we are connected.
source code
 
Send(self, msg)
Send a message.
source code
 
Recv(self)
Try to receive a message from the socket.
source code
 
Call(self, msg)
Send a message and wait for the response.
source code
 
Close(self)
Close the socket
source code
Static Methods [hide private]
 
_Connect(sock, address, timeout, allow_non_master) source code
 
RetryOnNetworkError(fn, on_error, retries=15, wait_on_error=5)
Calls a given function, retrying if it fails on a network IO exception.
source code
Method Details [hide private]

__init__(self, address, timeouts=None, allow_non_master=None)
(Constructor)

source code 

Constructor for the Client class.

There are two timeouts used since we might want to wait for a long time for a response, but the connect timeout should be lower.

If not passed, we use a default of 10 and respectively 60 seconds.

Note that on reading data, since the timeout applies to an invidual receive, it might be that the total duration is longer than timeout value passed (we make a hard limit at twice the read timeout).

Parameters:
  • address (socket address) - address the transport connects to
  • timeouts (list of ints) - timeouts to be used on connect and read/write
  • allow_non_master (bool) - skip checks for the master node on errors

Send(self, msg)

source code 

Send a message.

This just sends a message and doesn't wait for the response.

Recv(self)

source code 

Try to receive a message from the socket.

In case we already have messages queued, we just return from the queue. Otherwise, we try to read data with a _rwtimeout network timeout, and making sure we don't go over 2x_rwtimeout as a global limit.

Call(self, msg)

source code 

Send a message and wait for the response.

This is just a wrapper over Send and Recv.

RetryOnNetworkError(fn, on_error, retries=15, wait_on_error=5)
Static Method

source code 

Calls a given function, retrying if it fails on a network IO exception.

This allows to re-establish a broken connection and retry an IO operation.

The function receives one an integer argument stating the current retry number, 0 being the first call, 1 being the first retry, 2 the second, and so on.

If any exception occurs, on_error is invoked first with the exception given as an argument. Then, if the exception is a network exception, the function call is retried once more.