POLL_TIME_INCR = 0.5
def run_in_thread(target, args, timeout=0):
- import sys
interrupt = False
countdown = timeout
class Rados(object):
"""librados python wrapper"""
def require_state(self, *args):
- """
+ """
Checks if the Rados object is in a special state
:raises: RadosStateError
def version(self):
"""
Get the version number of the ``librados`` C library.
-
+
:returns: a tuple of ``(major, minor, extra)`` components of the
librados version
"""
def get_cluster_stats(self):
"""
Read usage info about the cluster
-
+
This tells you total space, space used, space available, and number
of objects. These are not updated immediately when data is written,
they are eventually consistent.
:returns: dict - contains the following keys:
- - ``kb`` (int) - total space
+ - ``kb`` (int) - total space
- ``kb_used`` (int) - space used
The pool is removed from the cluster immediately,
but the actual data is deleted in the background.
- :param pool_name: name of the pool to delete
+ :param pool_name: name of the pool to delete
:type pool_name: str
:raises: :class:`TypeError`, :class:`Error`
def list_pools(self):
"""
- Gets a list of pool names.
+ Gets a list of pool names.
:returns: list - of pool names.
"""
Create an io context
The io context allows you to perform operations within a particular
- pool.
+ pool.
- :param ioctx_name: name of the pool
+ :param ioctx_name: name of the pool
:type ioctx_name: str
:raises: :class:`TypeError`, :class:`Error`
- :returns: Ioctx - Rados Ioctx object
+ :returns: Ioctx - Rados Ioctx object
"""
self.require_state("connected")
if not isinstance(ioctx_name, str):
mon_command[_target](cmd, inbuf, outbuf, outbuflen, outs, outslen)
returns (int ret, string outbuf, string outs)
"""
- import sys
self.require_state("connected")
outbufp = pointer(pointer(c_char()))
outbuflen = c_long()
osd_command(osdid, cmd, inbuf, outbuf, outbuflen, outs, outslen)
returns (int ret, string outbuf, string outs)
"""
- import sys
self.require_state("connected")
outbufp = pointer(pointer(c_char()))
outbuflen = c_long()
pg_command(pgid, cmd, inbuf, outbuf, outbuflen, outs, outslen)
returns (int ret, string outbuf, string outs)
"""
- import sys
self.require_state("connected")
outbufp = pointer(pointer(c_char()))
outbuflen = c_long()
"""
Get the next Snapshot
- :raises: :class:`Error`, StopIteration
+ :raises: :class:`Error`, StopIteration
:returns: Snap - next snapshot
"""
if (self.cur_snap >= self.max_snap):
(self.rados_comp,))
def __del__(self):
- """
- Release a completion
+ """
+ Release a completion
Call this when you no longer need the completion. It may not be
freed immediately if the operation is not acked and committed.
self.close()
def __aio_safe_cb(self, completion, _):
- """
- Callback to onsafe() for asynchronous operations
+ """
+ Callback to onsafe() for asynchronous operations
"""
cb = None
with self.lock:
return 0
def __aio_complete_cb(self, completion, _):
- """
- Callback to oncomplete() for asynchronous operations
+ """
+ Callback to oncomplete() for asynchronous operations
"""
cb = None
with self.lock:
:type onsafe: completion
:raises: :class:`Error`
- :returns: completion object
+ :returns: completion object
"""
completion = c_void_p(0)
complete_cb = None
:type onsafe: completion
:raises: :class:`Error`
- :returns: completion object
+ :returns: completion object
"""
completion = self.__get_completion(oncomplete, onsafe)
ret = run_in_thread(self.librados.rados_aio_write,
:type onsafe: completion
:raises: :class:`Error`
- :returns: completion object
+ :returns: completion object
"""
completion = self.__get_completion(oncomplete, onsafe)
ret = run_in_thread(self.librados.rados_aio_write_full,
:type onsafe: completion
:raises: :class:`Error`
- :returns: completion object
+ :returns: completion object
"""
completion = self.__get_completion(oncomplete, onsafe)
ret = run_in_thread(self.librados.rados_aio_append,
:raises: :class:`TypeError`
:raises: :class:`LogicError`
- :returns: int - number of bytes written
+ :returns: int - number of bytes written
"""
self.require_ioctx_open()
if not isinstance(key, str):
:param key: name of the object
:type key: str
:param length: the number of bytes to read (default=8192)
- :type length: int
+ :type length: int
:param offset: byte offset in the object to begin reading at
:type offset: int
:raises: :class:`Error`
:returns: int - 0 on success, otherwise raises error
"""
-
+
self.require_ioctx_open()
if not isinstance(key, str):
raise TypeError('key must be a string')
def stat(self, key):
"""
Get object stats (size/mtime)
-
+
:param key: the name of the object to get stats from
:type key: str
def get_xattr(self, key, xattr_name):
"""
Get the value of an extended attribute on an object.
-
+
:param key: the name of the object to get xattr from
:type key: str
:param xattr_name: which extended attribute to read
def get_xattrs(self, oid):
"""
Start iterating over xattrs on an object.
-
+
:param oid: the name of the object to get xattrs from
:type key: str
def set_xattr(self, key, xattr_name, xattr_value):
"""
Set an extended attribute on an object.
-
+
:param key: the name of the object to set xattr to
:type key: str
:param xattr_name: which extended attribute to set
def rm_xattr(self, key, xattr_name):
"""
Removes an extended attribute on from an object.
-
+
:param key: the name of the object to remove xattr from
:type key: str
:param xattr_name: which extended attribute to remove
return True
def list_objects(self):
- """
+ """
Get ObjectIterator on rados.Ioctx object.
:returns: ObjectIterator
return ObjectIterator(self)
def list_snaps(self):
- """
+ """
Get SnapIterator on rados.Ioctx object.
:returns: SnapIterator
"debug",
"info",
"warn", "warning",
- "err", "error",
+ "err", "error",
"sec",
]