class ConfdClient(object):
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.
Method | __init__ |
Constructor for ConfdClient |
Method |
|
Delete all the expired requests. |
Method |
|
Send out all pending requests. |
Method |
|
Asynchronous handler for a confd reply |
Method |
|
Receive one reply. |
Method |
|
Send a confd request to some MCs |
Method |
|
Update the list of peers |
Method |
|
Wait for replies to a given request. |
Static Method | _ |
Compute the minimum safe number of replies for a query. |
Method | _ |
Prepare a request to be sent on the wire. |
Method | _ |
Undocumented |
Method | _ |
Undocumented |
Instance Variable | _callback |
Undocumented |
Instance Variable | _confd |
Undocumented |
Instance Variable | _family |
Undocumented |
Instance Variable | _hmac |
Undocumented |
Instance Variable | _logger |
Undocumented |
Instance Variable | _peers |
Undocumented |
Instance Variable | _requests |
dictionary indexes by salt, which contains data about the outstanding requests; the values are objects of type _Request |
Instance Variable | _socket |
Undocumented |
Constructor for ConfdClient
Parameters | |
hmac | 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 |
Asynchronous handler for a confd reply
Call the relevant callback associated to the current request.
Receive one reply.
Parameters | |
timeout:float | how long to wait for the reply |
Returns | |
boolean | True if some data has been handled, False otherwise |
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 |
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 |
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 | the number of peers contacted |
Returns | |
int | the number of replies which should give a safe coverage |
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.