etcd3gw(1)
| ETCD3-GATEWAY(1) | etcd3gw | ETCD3-GATEWAY(1) |
NAME
etcd3-gateway - etcd3-gateway Documentation
INSTALLATION
At the command line:
$ pip install etcd3-gateway
Or, if you have virtualenvwrapper installed:
$ mkvirtualenv etcd3-gateway $ pip install etcd3-gateway
USAGE
You can find examples in etcd3gw/examples and look at etcd3gw/client.py.
Basic usage example:
from etcd3gw.client import Etcd3Client client = Etcd3Client(host='localhost', port=2379) # Put key client.put(key='foo', value='bar') # Get key client.get(key='foo') # Get all keys client.get_all() # Create lease and use it lease = client.lease(ttl=100) client.put(key='foo', value='bar', lease=lease) # Get lease keys lease.keys() # Refresh lease lease.refresh() # Use watch watcher, watch_cancel = client.watch(key='KEY') for event in watcher: # blocks until event comes, cancel via watch_cancel()
print(event)
# modify event: {'kv': {'mod_revision': '8', 'version': '3', 'value': 'NEW_VAL', 'create_revision': '2', 'key': 'KEY', 'lease': '7587847878767953426'}}
CONTRIBUTING
If you would like to contribute to the development of OpenStack, you must follow the steps in this page:
If you already have a good understanding of how the system works and your OpenStack accounts are set up, you can skip to the development workflow section of this documentation to learn how changes to OpenStack should be submitted for review via the Gerrit tool:
Pull requests submitted through GitHub will be ignored.
Bugs should be filed on Launchpad, not GitHub:
THE ETCD3GW.CLIENT MODULE
- class etcd3gw.client.Etcd3Client(host='localhost', port=2379, protocol='http', ca_cert=None, cert_key=None, cert_cert=None, timeout=None, api_path=None)
- Bases: object
- property api_path
- property base_url
- create(key, value, lease=None)
- Atomically create the given key only if the key doesn't exist.
This verifies that the create_revision of a key equales to 0, then creates the key with the value. This operation takes place in a transaction.
- Parameters
- key -- key in etcd to create
- value (bytes or string) -- value of the key
- lease -- lease to connect with, optional
- Returns
- status of transaction, True if the create was successful, False otherwise
- Return type
- bool
- delete(key, **kwargs)
- DeleteRange deletes the given range from the key-value store.
A delete request increments the revision of the key-value store and generates a delete event in the event history for every deleted key.
- Parameters
- key
- kwargs
- Returns
- delete_prefix(key_prefix)
- Delete a range of keys with a prefix in etcd.
- get(key, metadata=False, sort_order=None, sort_target=None, **kwargs)
- Range gets the keys in the range from the key-value store.
- Parameters
- key
- metadata
- sort_order -- 'ascend' or 'descend' or None
- sort_target -- 'key' or 'version' or 'create' or 'mod' or 'value'
- kwargs
- Returns
- get_all(sort_order=None, sort_target='key')
- Get all keys currently stored in etcd.
- Returns
- sequence of (value, metadata) tuples
- get_prefix(key_prefix, sort_order=None, sort_target=None)
- Get a range of keys with a prefix.
- Parameters
- sort_order -- 'ascend' or 'descend' or None
- key_prefix -- first key in range
- Returns
- sequence of (value, metadata) tuples
- get_url(path)
- Construct a full url to the v3 API given a specific path
- Parameters
- path
- Returns
- url
- lease(ttl=30)
- Create a Lease object given a timeout
- Parameters
- ttl -- timeout
- Returns
- Lease object
- lock(id=None, ttl=30)
- Create a Lock object given an ID and timeout
- Parameters
- id -- ID for the lock, creates a new uuid if not provided
- ttl -- timeout
- Returns
- Lock object
- members()
- Lists all the members in the cluster.
- Returns
- json response
- post(*args, **kwargs)
- helper method for HTTP POST
- Parameters
- args
- kwargs
- Returns
- json response
- put(key, value, lease=None)
- Put puts the given key into the key-value store.
A put request increments the revision of the key-value store and generates one event in the event history.
- Parameters
- key
- value
- lease
- Returns
- boolean
- replace(key, initial_value, new_value)
- Atomically replace the value of a key with a new value.
This compares the current value of a key, then replaces it with a new value if it is equal to a specified value. This operation takes place in a transaction.
- Parameters
- key -- key in etcd to replace
- initial_value (bytes or string) -- old value to replace
- new_value (bytes or string) -- new value of the key
- Returns
- status of transaction, True if the replace was successful, False otherwise
- Return type
- bool
- status()
- Status gets the status of the etcd cluster member.
- Returns
- json response
- transaction(txn)
- Txn processes multiple requests in a single transaction.
A txn request increments the revision of the key-value store and generates events with the same revision for every completed request. It is not allowed to modify the same key several times within one txn.
- Parameters
- txn
- Returns
- watch(key, **kwargs)
- Watch a key.
- Parameters
- key -- key to watch
- Returns
- tuple of events_iterator and cancel. Use events_iterator to get the events of key changes and cancel to cancel the watch request
- watch_once(key, timeout=None, **kwargs)
- Watch a key and stops after the first event.
- Parameters
- key -- key to watch
- timeout -- (optional) timeout in seconds.
- Returns
- event
- watch_prefix(key_prefix, **kwargs)
- The same as watch, but watches a range of keys with a prefix.
- watch_prefix_once(key_prefix, timeout=None, **kwargs)
- Watches a range of keys with a prefix, similar to watch_once
- etcd3gw.client.client(host='localhost', port=2379, ca_cert=None, cert_key=None, cert_cert=None, timeout=None, protocol='http', api_path=None)
- Return an instance of an Etcd3Client.
THE ETCD3GW.LEASE MODULE
- class etcd3gw.lease.Lease(id, client=None)
- Bases: object
- keys()
- Get the keys associated with this lease.
- Returns
- refresh()
- LeaseKeepAlive keeps the lease alive
By streaming keep alive requests from the client to the server and streaming keep alive responses from the server to the client. This method makes a synchronous HTTP request by default.
- Returns
- returns new TTL for lease. If lease was already expired then TTL field is absent in response and the function returns -1 according to etcd documentation. https://etcd.io/docs/v3.5/dev-guide/apispec/swagger/rpc.swagger.json
- revoke()
- LeaseRevoke revokes a lease.
All keys attached to the lease will expire and be deleted. This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please define a callback function to be invoked when receiving the response.
- Returns
- ttl()
- LeaseTimeToLive retrieves lease information.
This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please define a callback function to be invoked when receiving the response.
- Returns
THE ETCD3GW.LOCK MODULE
- class etcd3gw.lock.Lock(name, ttl=30, client=None)
- Bases: object
- acquire()
- Acquire the lock.
- is_acquired()
- Check if the lock is acquired
- refresh()
- Refresh the lease on the lock
- Returns
- release()
- Release the lock
- property uuid
- The unique id of the lock
THE ETCD3GW.UTILS MODULE
- Index
- Module Index
- Search Page
AUTHOR
Davanum Srinivas
COPYRIGHT
2024, Davanum Srinivas
| October 3, 2024 | 2.4.2 |
