pyetcd package

Submodules

pyetcd.client module

module to connect to an etcd node and perform low rest API requests.

class pyetcd.client.Client(**kwargs)[source]

Bases: object

Etcd Client class.

Parameters:

kwargs

Keyword arguments:

  • host (str, list(str), list(tuple)) - etcd node hostname
    or list of hostnames or list of tuples (hostname, port). Default is ‘127.0.0.1’.
  • port (int) - TCP port to connect to. Default is 2379.
  • srv_domain (str) - Domain name if DNS discovery is used
  • version_prefix (str) - API version prefix. Default is ‘v2’.
  • allow_reconnect (bool) - If client fails to connect to
    a cluster node connect to the next node in the cluster. Default is True.
  • protocol (str) - Protocol to connect to the cluster.
    Default is ‘http’.

Raises:
  • ClientException – if any errors
  • NotImplementedError – if there is an attempt to use unsupported DNS discovery.
add_member(peer_urls)[source]

Add a node to the cluster.

Parameters:peer_urls

List of URL for inter-peer communication. For example:

["http://10.0.0.10:2380"]
Returns:Information about the newly added node.
Return type:EtcdResult
compare_and_delete(key, prev_value=None, prev_index=None)[source]

This command will delete a key only if the client-provided conditions are equal to the current conditions.

Parameters:
  • key – the key
  • prev_value – checks the previous value of the key.
  • prev_index – checks the previous modifiedIndex of the key.
Returns:

Result of operation.

Return type:

EtcdResult

Raises:
compare_and_swap(key, value, prev_value=None, prev_index=None, prev_exist=None, ttl=None)[source]

This command will set the value of a key only if the client-provided conditions are equal to the current conditions.

Parameters:
  • key – key string
  • value – key value
  • prev_value – checks the previous value of the key.
  • prev_index – checks the previous modifiedIndex of the key.
  • prev_exist – checks existence of the key: if prevExist is True, it is an update request; if prevExist is False, it is a create request.
  • ttl – set ttl on the key in seconds
Returns:

Result of operation.

Return type:

EtcdResult

Raises:
delete(key)[source]

Delete a key

Parameters:key – Key
Returns:Result of operation.
Return type:EtcdResult
Raises:EtcdException – if etcd responds with error or HTTP error
health
Returns:True if the node is healthy
Return type:bool
mkdir(directory)[source]

Create directory

Parameters:directory – string with directory name
Returns:Result of operation.
Return type:EtcdResult
Raises:EtcdException – if etcd responds with error or HTTP error
read(key, **kwargs)[source]

Read key value

Parameters:key – Key
Returns:Result of operation.
Return type:EtcdResult
Raises:EtcdException – if etcd responds with error or HTTP error
remove_member(member_id)[source]

Remove a node from the cluster.

Parameters:member_id – etcd identifier of the node. For example, 272e204152.
rmdir(directory, recursive=False)[source]

Delete directory

Parameters:
  • directory – string with directory name
  • recursive – recursively delete directory if not empty
Returns:

Result of operation.

Return type:

EtcdResult

Raises:

EtcdException – if etcd responds with error or HTTP error

update_ttl(key, ttl)[source]

Update key’s ttl

Parameters:
  • key – the key
  • ttl – new ttl
Returns:

Result of operation.

Return type:

EtcdResult

Raises:
version()[source]

Return Etcd server version

Returns:string with Etcd server version. E.g. ‘2.3.7’
Return type:str
version_cluster()[source]

Return Etcd cluster version

Returns:string with Etcd cluster version. E.g. ‘2.3.0’
Return type:str
version_server()[source]

Same as .version()

Returns:string with Etcd server version. E.g. ‘2.3.7’
Return type:str
write(key, value, ttl=None)[source]

Write value to a key

Parameters:
  • key – Key
  • value – Value
  • ttl – Keys in etcd can be set to expire after a specified number of seconds. You can do this by setting a TTL (time to live) on the key.
Returns:

Result of operation.

Return type:

EtcdResult

Raises:

EtcdException – if etcd responds with error or HTTP error

exception pyetcd.client.ClientException[source]

Bases: exceptions.Exception

Exception for errors in Client class

Module contents

pyetcd is a module to work with etcd cluster

exception pyetcd.EtcdClientInternal[source]

Bases: pyetcd.EtcdException

Error ecodeClientInternal (http code 500)

exception pyetcd.EtcdDirNotEmpty[source]

Bases: pyetcd.EtcdException

Error EcodeDirNotEmpty (http code 108)

exception pyetcd.EtcdEmptyResponse[source]

Bases: pyetcd.EtcdInvalidResponse

Error that raises if response from etcd is empty

exception pyetcd.EtcdEventIndexCleared[source]

Bases: pyetcd.EtcdException

Error EcodeEventIndexCleared (http code 401)

exception pyetcd.EtcdException[source]

Bases: exceptions.Exception

Generic Etcd error.

exception pyetcd.EtcdExistingPeerAddr[source]

Bases: pyetcd.EtcdException

Error ecodeExistingPeerAddr (http code 109)

exception pyetcd.EtcdIndexNaN[source]

Bases: pyetcd.EtcdException

Error EcodeIndexNaN (http code 203)

exception pyetcd.EtcdIndexOrValueRequired[source]

Bases: pyetcd.EtcdException

Error ecodeIndexOrValueRequired (http code 207)

exception pyetcd.EtcdIndexValueMutex[source]

Bases: pyetcd.EtcdException

Error ecodeIndexValueMutex (http code 208)

exception pyetcd.EtcdInvalidActiveSize[source]

Bases: pyetcd.EtcdException

Error ecodeInvalidActiveSize (http code 403)

exception pyetcd.EtcdInvalidField[source]

Bases: pyetcd.EtcdException

Error EcodeInvalidField (http code 209)

exception pyetcd.EtcdInvalidForm[source]

Bases: pyetcd.EtcdException

Error EcodeInvalidForm (http code 210)

exception pyetcd.EtcdInvalidRemoveDelay[source]

Bases: pyetcd.EtcdException

Error ecodeInvalidRemoveDelay (http code 404)

exception pyetcd.EtcdInvalidResponse[source]

Bases: pyetcd.EtcdException

Error that raises if response from etcd is invalid

exception pyetcd.EtcdKeyIsPreserved[source]

Bases: pyetcd.EtcdException

Error ecodeKeyIsPreserved (http code 106)

exception pyetcd.EtcdKeyNotFound[source]

Bases: pyetcd.EtcdException

Error EcodeKeyNotFound (http code 100)

exception pyetcd.EtcdLeaderElect[source]

Bases: pyetcd.EtcdException

Error EcodeLeaderElect (http code 301)

exception pyetcd.EtcdNameRequired[source]

Bases: pyetcd.EtcdException

Error ecodeNameRequired (http code 206)

exception pyetcd.EtcdNoMorePeer[source]

Bases: pyetcd.EtcdException

Error ecodeNoMorePeer (http code 103)

exception pyetcd.EtcdNodeExist[source]

Bases: pyetcd.EtcdException

Error EcodeNodeExist (http code 105)

exception pyetcd.EtcdNotDir[source]

Bases: pyetcd.EtcdException

Error EcodeNotDir (http code 104)

exception pyetcd.EtcdNotFile[source]

Bases: pyetcd.EtcdException

Error EcodeNotFile (http code 102)

exception pyetcd.EtcdPrevValueRequired[source]

Bases: pyetcd.EtcdException

Error EcodePrevValueRequired (http code 201)

exception pyetcd.EtcdRaftInternal[source]

Bases: pyetcd.EtcdException

Error EcodeRaftInternal (http code 300)

exception pyetcd.EtcdRefreshTTLRequired[source]

Bases: pyetcd.EtcdException

Error EcodeRefreshTTLRequired (http code 212)

exception pyetcd.EtcdRefreshValue[source]

Bases: pyetcd.EtcdException

Error EcodeRefreshValue (http code 211)

class pyetcd.EtcdResult(response)[source]

Bases: object

Response from Etcd API.

Parameters:

response (requests.Response) – Response from server as requests.(get|post|put) returns.

Raises:
action

Action type

followers

Followers of leader

health

name

id

etcd identifier of the etcd node.

leader

Leader of cluster

leaderInfo
name

etcd name of the node.

node

Node class instance. It holds the current key value.

prevNode

Node class instance. It holds the previous key value.

recvAppendRequestCnt
sendAppendRequestCnt
startTime
state
version_etcdcluster

Version of Etcd cluster

version_etcdserver

Version of Etcd server

x_etcd_index

current etcd index that represents key modification version.

exception pyetcd.EtcdRootROnly[source]

Bases: pyetcd.EtcdException

Error EcodeRootROnly (http code 107)

exception pyetcd.EtcdStandbyInternal[source]

Bases: pyetcd.EtcdException

Error ecodeStandbyInternal (http code 402)

exception pyetcd.EtcdTTLNaN[source]

Bases: pyetcd.EtcdException

Error EcodeTTLNaN (http code 202)

exception pyetcd.EtcdTestFailed[source]

Bases: pyetcd.EtcdException

Error EcodeTestFailed (http code 101)

exception pyetcd.EtcdTimeoutNaN[source]

Bases: pyetcd.EtcdException

Error ecodeTimeoutNaN (http code 205)

exception pyetcd.EtcdUnauthorized[source]

Bases: pyetcd.EtcdException

Error EcodeUnauthorized (http code 110)

exception pyetcd.EtcdValueOrTTLRequired[source]

Bases: pyetcd.EtcdException

Error ecodeValueOrTTLRequired (http code 204)

exception pyetcd.EtcdValueRequired[source]

Bases: pyetcd.EtcdException

Error ecodeValueRequired (http code 200)

exception pyetcd.EtcdWatcherCleared[source]

Bases: pyetcd.EtcdException

Error EcodeWatcherCleared (http code 400)