pyetcd package

Submodules

pyetcd.client module

class pyetcd.client.Client(host='127.0.0.1', port=2379, srv_domain=None, version_prefix='v2', protocol='http', allow_reconnect=True)[source]

Bases: object

Etcd Client class

Parameters:
  • host – etcd node hostname or list of hostnames or list of tuples (hostname, port) (default=‘127.0.0.1’)
  • port – TCP port to connect to (default=2379)
  • srv_domain – Domain name if DNS discovery is used
  • version_prefix – API version prefix (default=’v2’)
  • allow_reconnect – If client fails to connect to a cluster node connect to the next node in the cluster
  • protocol – Protocol to connect to the cluster (default=’http’)
Raises:

ClientException – if any errors

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:

EtcdResult

Raises:

EtcdException

if etcd responds with error or HTTP error.

EtcdNodeExist if any condition fails.

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:

EtcdResult

Raises:

EtcdException

if etcd responds with error or HTTP error.

EtcdNodeExist if condition prev_exist=False fails.

EtcdTestFailed if condition prev_value=’bar’ fails.

delete(key)[source]

Delete a key

Parameters:key – Key
Returns:EtcdResult
Raises:EtcdException – if etcd responds with error or HTTP error
mkdir(directory)[source]

Create directory

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

Read key value

Parameters:key – Key
Returns:EtcdResult
Raises:EtcdException – if etcd responds with error or HTTP error
rmdir(directory, recursive=False)[source]

Delete directory

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

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:

EtcdResult

Raises:

EtcdException

if etcd responds with error or HTTP error.

EtcdKeyNotFound if the key doesn’t exist

version()[source]

Return Etcd server version

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

Return Etcd cluster version

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

Same as .version()

Returns:string with Etcd server version. E.g. ‘2.3.7’
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:

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

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.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.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 – Response from server as requests.(get|post|put) returns.
Raises:EtcdException – if payload is invalid or contains errorCode.
action

Action type

followers

Followers of leader

id
leader

Leader of cluster

leaderInfo
name
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
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)

class pyetcd.ResponseNode(key=None, value=None, created_index=None, modified_index=None)[source]

Bases: object

Etcd response includes information about nodes.

Parameters:
  • key – the HTTP path to which the request was made. We set /message to Hello world, so the key field is /message. etcd uses a file-system-like structure to represent the key-value pairs, therefore all keys start with /.
  • value – the value of the key after resolving the request.
  • created_index – an index is a unique, monotonically-incrementing integer created for each change to etcd. This specific index reflects the point in the etcd state member at which a given key was created
  • modified_index – like node.createdIndex, this attribute is also an etcd index. Actions that cause the value to change include set, delete, update, create, compareAndSwap and compareAndDelete. Since the get and watch commands do not change state in the store, they do not change the value of node.modifiedIndex.