class documentation

class ConfdClient(object):

View In Hierarchy

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 ExpireRequests Delete all the expired requests.
Method FlushSendQueue Send out all pending requests.
Method HandleResponse Asynchronous handler for a confd reply
Method ReceiveReply Receive one reply.
Method SendRequest Send a confd request to some MCs
Method UpdatePeerList Update the list of peers
Method WaitForReply Wait for replies to a given request.
Static Method _NeededReplies Compute the minimum safe number of replies for a query.
Method _PackRequest Prepare a request to be sent on the wire.
Method _SetPeersAddressFamily Undocumented
Method _UnpackReply Undocumented
Instance Variable _callback Undocumented
Instance Variable _confd_port Undocumented
Instance Variable _family Undocumented
Instance Variable _hmac_key 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
def __init__(self, hmac_key, peers, callback, port=None, logger=None):

Constructor for ConfdClient

Parameters
hmac_key:stringhmac key to talk to confd
peers:listlist of peer nodes
callback:f(ConfdUpcallPayload)function to call when getting answers
port:integerconfd port (default: use GetDaemonPort)
logger:logging.Loggeroptional logger for internal conditions
def ExpireRequests(self):

Delete all the expired requests.

def FlushSendQueue(self):

Send out all pending requests.

Can be used for synchronous client use.

def HandleResponse(self, payload, ip, port):

Asynchronous handler for a confd reply

Call the relevant callback associated to the current request.

def ReceiveReply(self, timeout=1):

Receive one reply.

Parameters
timeout:floathow long to wait for the reply
Returns
booleanTrue if some data has been handled, False otherwise
def SendRequest(self, request, args=None, coverage=0, async_=True):

Send a confd request to some MCs

Parameters
request:objects.ConfdRequestthe request to send
args:tupleadditional callback arguments
coverage:integernumber 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_:booleanhandle the write asynchronously
def UpdatePeerList(self, peers):

Update the list of peers

Parameters
peers:listlist of peer nodes
def WaitForReply(self, salt, timeout=constants.CONFD_CLIENT_EXPIRE_TIMEOUT):

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
saltthe salt of the request we want responses for
timeoutthe maximum timeout (should be less or equal to ganeti.constants.CONFD_CLIENT_EXPIRE_TIMEOUT
Returns
tuplea tuple of (timed_out, sent_cnt, recv_cnt); if the request is unknown, timed_out will be true and the counters will be zero
@staticmethod
def _NeededReplies(peer_cnt):

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:intthe number of peers contacted
Returns
intthe number of replies which should give a safe coverage
def _PackRequest(self, request, now=None):

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.

def _SetPeersAddressFamily(self):

Undocumented

def _UnpackReply(self, payload):

Undocumented

_callback =

Undocumented

_confd_port =

Undocumented

_family =

Undocumented

_hmac_key =

Undocumented

_logger =

Undocumented

_peers =

Undocumented

_requests: dict =

dictionary indexes by salt, which contains data about the outstanding requests; the values are objects of type _Request

_socket =

Undocumented