Add setting ``max_objects`` quota and retrieving erasure code profile
Also fix a few missing redirects of STDERR. Depends-On: I243328af5db202f092c53b4d48e0d293378d2ca0 Change-Id: Ia204468ecf5de6bb4d74ec9fcb68393d5b18b4f1
This commit is contained in:
parent
f6d9a61cb6
commit
06af59f022
|
@ -369,7 +369,8 @@ def handle_erasure_pool(request, service):
|
|||
"""
|
||||
pool_name = request.get('name')
|
||||
erasure_profile = request.get('erasure-profile')
|
||||
quota = request.get('max-bytes')
|
||||
max_bytes = request.get('max-bytes')
|
||||
max_objects = request.get('max-objects')
|
||||
weight = request.get('weight')
|
||||
group_name = request.get('group')
|
||||
|
||||
|
@ -409,8 +410,9 @@ def handle_erasure_pool(request, service):
|
|||
pool.create()
|
||||
|
||||
# Set a quota if requested
|
||||
if quota is not None:
|
||||
set_pool_quota(service=service, pool_name=pool_name, max_bytes=quota)
|
||||
if max_bytes or max_objects:
|
||||
set_pool_quota(service=service, pool_name=pool_name,
|
||||
max_bytes=max_bytes, max_objects=max_objects)
|
||||
|
||||
|
||||
def handle_replicated_pool(request, service):
|
||||
|
@ -422,7 +424,8 @@ def handle_replicated_pool(request, service):
|
|||
"""
|
||||
pool_name = request.get('name')
|
||||
replicas = request.get('replicas')
|
||||
quota = request.get('max-bytes')
|
||||
max_bytes = request.get('max-bytes')
|
||||
max_objects = request.get('max-objects')
|
||||
weight = request.get('weight')
|
||||
group_name = request.get('group')
|
||||
|
||||
|
@ -469,8 +472,9 @@ def handle_replicated_pool(request, service):
|
|||
level=DEBUG)
|
||||
|
||||
# Set a quota if requested
|
||||
if quota is not None:
|
||||
set_pool_quota(service=service, pool_name=pool_name, max_bytes=quota)
|
||||
if max_bytes or max_objects:
|
||||
set_pool_quota(service=service, pool_name=pool_name,
|
||||
max_bytes=max_bytes, max_objects=max_objects)
|
||||
|
||||
|
||||
def handle_create_cache_tier(request, service):
|
||||
|
|
|
@ -2533,7 +2533,8 @@ def list_pools(client='admin'):
|
|||
try:
|
||||
pool_list = []
|
||||
pools = subprocess.check_output(['rados', '--id', client, 'lspools'],
|
||||
universal_newlines=True)
|
||||
universal_newlines=True,
|
||||
stderr=subprocess.STDOUT)
|
||||
for pool in pools.splitlines():
|
||||
pool_list.append(pool)
|
||||
return pool_list
|
||||
|
@ -2558,8 +2559,8 @@ def get_pool_param(pool, param, client='admin'):
|
|||
"""
|
||||
try:
|
||||
output = subprocess.check_output(
|
||||
['ceph', '--id', client, 'osd', 'pool', 'get',
|
||||
pool, param], universal_newlines=True)
|
||||
['ceph', '--id', client, 'osd', 'pool', 'get', pool, param],
|
||||
universal_newlines=True, stderr=subprocess.STDOUT)
|
||||
except subprocess.CalledProcessError as cp:
|
||||
if cp.returncode == 2 and 'ENOENT: option' in cp.output:
|
||||
return None
|
||||
|
@ -2568,6 +2569,27 @@ def get_pool_param(pool, param, client='admin'):
|
|||
return output.split(':')[1].lstrip().rstrip()
|
||||
|
||||
|
||||
def get_pool_erasure_profile(pool, client='admin'):
|
||||
"""Get erasure code profile for pool.
|
||||
|
||||
:param pool: Name of pool to get variable from
|
||||
:type pool: str
|
||||
:param client: (Optional) client id for ceph key to use
|
||||
Defaults to ``admin``
|
||||
:type cilent: str
|
||||
:returns: Erasure code profile of pool or None
|
||||
:rtype: str or None
|
||||
:raises: subprocess.CalledProcessError
|
||||
"""
|
||||
try:
|
||||
return get_pool_param(pool, 'erasure_code_profile', client=client)
|
||||
except subprocess.CalledProcessError as cp:
|
||||
if cp.returncode == 13 and 'EACCES: pool' in cp.output:
|
||||
# Not a Erasure coded pool
|
||||
return None
|
||||
raise
|
||||
|
||||
|
||||
def get_pool_quota(pool, client='admin'):
|
||||
"""Get pool quota.
|
||||
|
||||
|
@ -2582,7 +2604,7 @@ def get_pool_quota(pool, client='admin'):
|
|||
"""
|
||||
output = subprocess.check_output(
|
||||
['ceph', '--id', client, 'osd', 'pool', 'get-quota', pool],
|
||||
universal_newlines=True)
|
||||
universal_newlines=True, stderr=subprocess.STDOUT)
|
||||
rc = re.compile(r'\s+max\s+(\S+)\s*:\s+(\d+)')
|
||||
result = {}
|
||||
for line in output.splitlines():
|
||||
|
@ -2610,7 +2632,9 @@ def get_pool_applications(pool='', client='admin'):
|
|||
if pool:
|
||||
cmd.append(pool)
|
||||
try:
|
||||
output = subprocess.check_output(cmd, universal_newlines=True)
|
||||
output = subprocess.check_output(cmd,
|
||||
universal_newlines=True,
|
||||
stderr=subprocess.STDOUT)
|
||||
except subprocess.CalledProcessError as cp:
|
||||
if cp.returncode == 2 and 'ENOENT' in cp.output:
|
||||
return {}
|
||||
|
@ -2623,7 +2647,7 @@ def list_pools_detail():
|
|||
|
||||
Structure:
|
||||
{'pool_name_1': {'applications': {'application': {}},
|
||||
'parameters': {'pg_num': 42, 'size': 42},
|
||||
'parameters': {'pg_num': '42', 'size': '42'},
|
||||
'quota': {'max_bytes': '1000',
|
||||
'max_objects': '10'},
|
||||
},
|
||||
|
@ -2646,6 +2670,10 @@ def list_pools_detail():
|
|||
for param in get_params:
|
||||
result[pool]['parameters'].update({
|
||||
param: get_pool_param(pool, param)})
|
||||
erasure_profile = get_pool_erasure_profile(pool)
|
||||
if erasure_profile:
|
||||
result[pool]['parameters'].update({
|
||||
'erasure_code_profile': erasure_profile})
|
||||
return result
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue