Package ganeti :: Package confd :: Module client :: Class ConfdClient
[hide private]
[frames] | no frames]

Class ConfdClient

source code


Send queries to confd, and get back answers.

Since the confd model works by querying multiple master candidates, and getting back answers, this is an asynchronous library. It can either work through asyncore or with your own handling.

Instance Methods [hide private]
 
__init__(self, hmac_key, peers, callback, port=None, logger=None)
Constructor for ConfdClient
source code
 
UpdatePeerList(self, peers)
Update the list of peers
source code
 
_PackRequest(self, request, now=None)
Prepare a request to be sent on the wire.
source code
 
_UnpackReply(self, payload) source code
 
ExpireRequests(self)
Delete all the expired requests.
source code
 
SendRequest(self, request, args=None, coverage=0, async=True)
Send a confd request to some MCs
source code
 
HandleResponse(self, payload, ip, port)
Asynchronous handler for a confd reply
source code
 
FlushSendQueue(self)
Send out all pending requests.
source code
boolean
ReceiveReply(self, timeout=1)
Receive one reply.
source code
tuple
WaitForReply(self, salt, timeout=constants.CONFD_CLIENT_EXPIRE_TIMEOUT)
Wait for replies to a given request.
source code
 
_SetPeersAddressFamily(self) source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods [hide private]
int
_NeededReplies(peer_cnt)
Compute the minimum safe number of replies for a query.
source code
Instance Variables [hide private]
dict _requests
dictionary indexes by salt, which contains data about the outstanding requests; the values are objects of type _Request
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, hmac_key, peers, callback, port=None, logger=None)
(Constructor)

source code 

Constructor for ConfdClient

Parameters:
  • hmac_key (string) - hmac key to talk to confd
  • peers (list) - list of peer nodes
  • callback (f(ConfdUpcallPayload)) - function to call when getting answers
  • port (integer) - confd port (default: use GetDaemonPort)
  • logger (logging.Logger) - optional logger for internal conditions
Overrides: object.__init__

UpdatePeerList(self, peers)

source code 

Update the list of peers

Parameters:
  • peers (list) - list of peer nodes

_PackRequest(self, request, now=None)

source code 

Prepare a request to be sent on the wire.

This function puts a proper salt in a confd request, puts the proper salt, and adds the correct magic number.

SendRequest(self, request, args=None, coverage=0, async=True)

source code 

Send a confd request to some MCs

Parameters:
  • request (objects.ConfdRequest) - the request to send
  • args (tuple) - additional callback arguments
  • coverage (integer) - number of remote nodes to contact; if default (0), it will use a reasonable default (ganeti.constants.CONFD_DEFAULT_REQ_COVERAGE), if -1 is passed, it will use the maximum number of peers, otherwise the number passed in will be used
  • async (boolean) - handle the write asynchronously

HandleResponse(self, payload, ip, port)

source code 

Asynchronous handler for a confd reply

Call the relevant callback associated to the current request.

FlushSendQueue(self)

source code 

Send out all pending requests.

Can be used for synchronous client use.

ReceiveReply(self, timeout=1)

source code 

Receive one reply.

Parameters:
  • timeout (float) - how long to wait for the reply
Returns: boolean
True if some data has been handled, False otherwise

_NeededReplies(peer_cnt)
Static Method

source code 

Compute the minimum safe number of replies for a query.

The algorithm is designed to work well for both small and big number of peers:

  • for less than three, we require all responses
  • for less than five, we allow one miss
  • otherwise, half the number plus one

This guarantees that we progress monotonically: 1->1, 2->2, 3->2, 4->2, 5->3, 6->3, 7->4, etc.

Parameters:
  • peer_cnt (int) - the number of peers contacted
Returns: int
the number of replies which should give a safe coverage

WaitForReply(self, salt, timeout=constants.CONFD_CLIENT_EXPIRE_TIMEOUT)

source code 

Wait for replies to a given request.

This method will wait until either the timeout expires or a minimum number (computed using _NeededReplies) of replies are received for the given salt. It is useful when doing synchronous calls to this library.

Parameters:
  • salt - the salt of the request we want responses for
  • timeout - the maximum timeout (should be less or equal to ganeti.constants.CONFD_CLIENT_EXPIRE_TIMEOUT
Returns: tuple
a tuple of (timed_out, sent_cnt, recv_cnt); if the request is unknown, timed_out will be true and the counters will be zero