oio.account package

Submodules

oio.account.backend module

class oio.account.backend.AccountBackend(conf, connection=None)[source]

Bases: oio.common.redis_conn.RedisConn

static ckey(account, name)[source]

Build the key of a container description

create_account(account_id)[source]
delete_account(account_id)[source]
flush_account(account_id)[source]
get_account_metadata(account_id)[source]
info_account(account_id)[source]
list_account()[source]
list_containers(account_id, limit=1000, marker=None, end_marker=None, prefix=None, delimiter=None)[source]
lua_flush_account = "\n local account_id = redis.call('HGET', KEYS[1], 'id');\n if not account_id then\n return redis.error_reply('no_account');\n end;\n\n redis.call('HMSET', KEYS[1], 'bytes', 0, 'objects', 0)\n\n local containers = redis.call('ZRANGE', KEYS[2], 0, -1);\n redis.call('DEL', KEYS[2]);\n\n for _,container in ipairs(containers) do\n redis.call('DEL', KEYS[3] .. container);\n end;\n "
lua_is_sup = '\n -- With lua float we are losing precision for this reason\n -- we keep the number as a string\n local is_sup = function(a,b)\n local int_a = string.match(a,"%d+")\n local int_b = string.match(b,"%d+")\n if string.len(int_a) > string.len(int_b) then\n return true;\n end;\n return a > b;\n end;\n '
lua_refresh_account = "\n local account_id = redis.call('HGET', KEYS[1], 'id');\n if not account_id then\n return redis.error_reply('no_account');\n end;\n\n local containers = redis.call('ZRANGE', KEYS[2], 0, -1);\n local container_key = ''\n local bytes_sum = 0;\n local objects_sum = 0;\n for _,container in ipairs(containers) do\n container_key = KEYS[3] .. container;\n bytes_sum = bytes_sum + redis.call('HGET', container_key, 'bytes')\n objects_sum = objects_sum + redis.call('HGET', container_key,\n 'objects')\n end;\n\n redis.call('HMSET', KEYS[1], 'bytes', bytes_sum,\n 'objects', objects_sum)\n "
lua_update_container = '\n -- With lua float we are losing precision for this reason\n -- we keep the number as a string\n local is_sup = function(a,b)\n local int_a = string.match(a,"%d+")\n local int_b = string.match(b,"%d+")\n if string.len(int_a) > string.len(int_b) then\n return true;\n end;\n return a > b;\n end;\n \n local account_id = redis.call(\'HGET\', KEYS[4], \'id\');\n if not account_id then\n if ARGV[6] == \'True\' then\n redis.call(\'HSET\', \'accounts:\', KEYS[1], 1);\n redis.call(\'HMSET\', KEYS[4], \'id\', KEYS[1],\n \'bytes\', 0, \'objects\', 0, \'ctime\', ARGV[7]);\n else\n return redis.error_reply(\'no_account\');\n end;\n end;\n\n if ARGV[9] == \'False\' then\n local container_name = redis.call(\'HGET\', KEYS[2], \'name\');\n if not container_name then\n return redis.error_reply(\'no_container\');\n end;\n end;\n\n local objects = redis.call(\'HGET\', KEYS[2], \'objects\');\n local name = ARGV[1];\n local mtime = redis.call(\'HGET\', KEYS[2], \'mtime\');\n local dtime = redis.call(\'HGET\', KEYS[2], \'dtime\');\n local bytes = redis.call(\'HGET\', KEYS[2], \'bytes\');\n\n -- When the keys do not exist redis return false and not nil\n if objects == false then\n objects = 0\n end\n if dtime == false then\n dtime = \'0\'\n end\n if mtime == false then\n mtime = \'0\'\n end\n if bytes == false then\n bytes = 0\n end\n\n if ARGV[9] == \'False\' and is_sup(dtime, mtime) then\n return redis.error_reply(\'no_container\');\n end;\n\n local old_mtime = mtime;\n local inc_objects;\n local inc_bytes;\n\n if not is_sup(ARGV[3],dtime) and\n not is_sup(ARGV[2],mtime) then\n return redis.error_reply(\'no_update_needed\');\n end;\n\n if is_sup(ARGV[2],mtime) then\n mtime = ARGV[2];\n end;\n\n if is_sup(ARGV[3],dtime) then\n dtime = ARGV[3];\n end;\n if is_sup(dtime,mtime) then\n inc_objects = -objects;\n inc_bytes = -bytes;\n redis.call(\'HMSET\', KEYS[2], \'bytes\', 0, \'objects\', 0);\n redis.call(\'EXPIRE\', KEYS[2], tonumber(ARGV[8]));\n redis.call(\'ZREM\', KEYS[3], name);\n elseif is_sup(mtime,old_mtime) then\n redis.call(\'PERSIST\', KEYS[2]);\n inc_objects = tonumber(ARGV[4]) - objects\n inc_bytes = tonumber(ARGV[5]) - bytes\n redis.call(\'HMSET\', KEYS[2], \'bytes\', tonumber(ARGV[5]),\n \'objects\', tonumber(ARGV[4]));\n redis.call(\'ZADD\', KEYS[3], \'0\', name);\n else\n return redis.error_reply(\'no_update_needed\');\n end;\n\n redis.call(\'HMSET\', KEYS[2], \'mtime\', mtime,\n \'dtime\', dtime, \'name\', name)\n if inc_objects ~= 0 then\n redis.call(\'HINCRBY\', KEYS[4], \'objects\', inc_objects);\n end;\n if inc_bytes ~= 0 then\n redis.call(\'HINCRBY\', KEYS[4], \'bytes\', inc_bytes);\n end;\n '
refresh_account(account_id)[source]
status()[source]
update_account_metadata(account_id, metadata, to_delete=None)[source]
update_container(account_id, name, mtime, dtime, object_count, bytes_used, autocreate_account=None, autocreate_container=True)[source]

oio.account.client module

class oio.account.client.AccountClient(conf, endpoint=None, proxy_endpoint=None, refresh_delay=3600.0, logger=None, **kwargs)[source]

Bases: oio.api.base.HttpApi

Simple client API for the account service.

account_create(account, **kwargs)[source]

Create an account.

Parameters:account (str) – name of the account to create
Returns:True if the account has been created
account_delete(account, **kwargs)[source]

Delete an account.

Parameters:account (str) – name of the account to delete
account_flush(account, **kwargs)[source]

Flush all containers of an account

Parameters:account (str) – name of the account to flush
account_list(**kwargs)[source]

List accounts.

account_refresh(account, **kwargs)[source]

Refresh counters of an account

Parameters:account (str) – name of the account to refresh
account_request(account, method, action, params=None, **kwargs)[source]

Make a request to the account service.

account_show(account, **kwargs)[source]

Get information about an account.

account_update(account, metadata, to_delete, **kwargs)[source]
container_list(account, limit=None, marker=None, end_marker=None, prefix=None, delimiter=None, **kwargs)[source]

Get the list of containers of an account.

Parameters:
  • account (str) – account from which to get the container list
  • limit (int) – maximum number of results to return
  • marker (str) – name of the container from where to start the listing
  • end_marker
  • prefix
  • delimiter
Return type:

dict with ‘ctime’ (float), ‘bytes’ (int), ‘objects’ (int), ‘containers’ (int), ‘id’ (str), ‘metadata’ (dict) and ‘listing’ (list). ‘listing’ contains lists of container metadata (name, number of objects, number of bytes, whether it is a prefix, and modification time).

container_reset(account, container, mtime, **kwargs)[source]

Reset container of an account

Parameters:
  • account (str) – name of the account
  • container (str) – name of the container to reset
  • mtime – time of the modification
container_update(account, container, metadata=None, **kwargs)[source]

Update account with container-related metadata.

Parameters:
  • account (str) – name of the account to update
  • container (str) – name of the container whose metadata has changed
  • metadata – container metadata (“bytes”, “objects”,

“mtime”, “dtime”) :type metadata: dict

oio.account.server module

class oio.account.server.Account(conf, backend, logger=None)[source]

Bases: oio.common.wsgi.WerkzeugApp

on_account_container_reset(req)[source]
on_account_container_update(req)[source]
on_account_containers(*args, **kwargs)[source]
on_account_create(req)[source]
on_account_delete(req)[source]
on_account_flush(req)[source]
on_account_list(*args, **kwargs)[source]
on_account_refresh(req)[source]
on_account_show(*args, **kwargs)[source]
on_account_update(req)[source]
on_status(req)[source]
oio.account.server.access_log(func)[source]
oio.account.server.create_app(conf, **kwargs)[source]

Module contents