etcd.node_ops module

class etcd.node_ops.NodeOps(client)[source]

Bases: etcd.common_ops.CommonOps

Common key-value functions.

compare_and_swap(path, value, current_value=None, current_index=None, prev_exists=None, ttl=None)[source]

The base compare-and-swap function for atomic comparisons. A combination of criteria may be used if necessary.

Parameters:
  • path (string) – Node key
  • value (scalar) – Value to assign
  • current_value (scalar or None) – Current value to check
  • current_index (int or None) – Current index to check
  • prev_exists (bool or None) – Whether the node should exist or not
  • ttl (int or None) – The number of seconds until the node expires
Returns:

Response object

Return type:

etcd.response.ResponseV2

Raises:

etcd.exceptions.EtcdPreconditionException

create_only(path, value, ttl=None)[source]

A convenience function that will only set a node if it doesn’t already exist.

Parameters:
  • path (string) – Node key
  • value (scalar) – Value to assign
  • ttl (int or None) – The number of seconds until the node expires
Returns:

Response object

Return type:

etcd.response.ResponseV2

delete(path, current_value=None, current_index=None)[source]

Delete the given node.

Parameters:
  • path (string) – Node key
  • current_value (string or None) – Current value to check
  • current_index (int or None) – Current index to check
Returns:

Response object

Return type:

etcd.response.ResponseV2

delete_if_index(path, current_index)[source]

Only delete the given node if it’s at the given index.

Parameters:
  • path (string) – Key
  • current_index (int or None) – Current index to check
Returns:

Response object

Return type:

etcd.response.ResponseV2

delete_if_value(path, current_value)[source]

Only delete the given node if it’s at the given value.

Parameters:
  • path (string) – Key
  • current_value (string) – Current value to check
Returns:

Response object

Return type:

etcd.response.ResponseV2

get(path, recursive=False)[source]

Get the given node.

Parameters:
  • path (string) – Node key
  • recursive (bool) – Node is a directory, and we want to read it recursively.
Returns:

Response object

Return type:

etcd.response.ResponseV2

Raises:

KeyError

set(path, value, ttl=None)[source]

Set the given node.

Parameters:
  • path (string) – Node key
  • value (scalar) – Value to assign
  • ttl (int or None) – Number of seconds until expiration
Returns:

Response object

Return type:

etcd.response.ResponseV2

update_if_index(path, value, current_index, ttl=None)[source]

A convenience function that will only set a node if its existing “modified index” matches.

Parameters:
  • path (string) – Node key
  • value (scalar) – Value to assign
  • current_index (int) – Current index to check
  • ttl (int or None) – The number of seconds until the node expires
Returns:

Response object

Return type:

etcd.response.ResponseV2

update_if_value(path, value, current_value, ttl=None)[source]

A convenience function that will only set a node if its existing value matches.

Parameters:
  • path (string) – Node key
  • value (scalar) – Value to assign
  • current_value (scalar or None) – Current value to check
  • ttl (int or None) – The number of seconds until the node expires
Returns:

Response object

Return type:

etcd.response.ResponseV2

update_only(path, value, ttl=None)[source]

A convenience function that will only set a node if it already exists.

Parameters:
  • path (string) – Node key
  • value (scalar) – Value to assign
  • ttl (int or None) – The number of seconds until the node expires
Returns:

Response object

Return type:

etcd.response.ResponseV2

wait(path, recursive=False)[source]

Long-poll on the given path until it changes.

Parameters:
  • path (string) – Node key
  • recursive (bool) – Wait on any change in the given directory or any of its descendants.
Returns:

Response object

Return type:

etcd.response.ResponseV2

Raises:

KeyError