summaryrefslogtreecommitdiffstats
path: root/glustolibs-gluster/glustolibs/gluster
diff options
context:
space:
mode:
authorhari gowtham <hgowtham>2018-01-31 10:15:13 +0530
committerNigel Babu <nigelb@redhat.com>2018-02-02 10:15:15 +0000
commit896389e4b529367021dcd90e7e3a1d1a2b1f006a (patch)
tree6d76a5537fa611d3545963e03f0387a37c441e8e /glustolibs-gluster/glustolibs/gluster
parent94822dbb06d4f1a54bcd46c501e1116113192775 (diff)
quota: lib to check if hard and soft limit are exceed.
This is a library to check if quota' hard and soft limit are exceeded from the output of the quota list xml command. Change-Id: Ie02ab9fcbf2aa2d248e0cb6385ab3d3f0554dec0 Signed-off-by: hari gowtham <hgowtham>
Diffstat (limited to 'glustolibs-gluster/glustolibs/gluster')
-rw-r--r--glustolibs-gluster/glustolibs/gluster/exceptions.py14
-rw-r--r--glustolibs-gluster/glustolibs/gluster/quota_ops.py88
2 files changed, 102 insertions, 0 deletions
diff --git a/glustolibs-gluster/glustolibs/gluster/exceptions.py b/glustolibs-gluster/glustolibs/gluster/exceptions.py
index 71591bf..42ee484 100644
--- a/glustolibs-gluster/glustolibs/gluster/exceptions.py
+++ b/glustolibs-gluster/glustolibs/gluster/exceptions.py
@@ -15,3 +15,17 @@ class ExecutionError(Exception):
'''
pass
+
+
+class ExecutionParseError(Exception):
+ '''
+ Custom exception thrown when parsing a command executed by Glusto
+ results in an unexpected error.
+
+ For example, the output of a command when has to be parsed, can have three
+ states. First, the output was as expected. Second, didn't get the expected
+ ouput after the parsing result and Third, didn't get the expected result as
+ the command itself failed.
+
+ '''
+ pass
diff --git a/glustolibs-gluster/glustolibs/gluster/quota_ops.py b/glustolibs-gluster/glustolibs/gluster/quota_ops.py
index 5a7f50f..3a6ca89 100644
--- a/glustolibs-gluster/glustolibs/gluster/quota_ops.py
+++ b/glustolibs-gluster/glustolibs/gluster/quota_ops.py
@@ -20,6 +20,7 @@
"""
from glusto.core import Glusto as g
+from glustolibs.gluster.exceptions import ExecutionError, ExecutionParseError
try:
import xml.etree.cElementTree as etree
@@ -224,6 +225,93 @@ def get_quota_list(mnode, volname, path=None):
return quotalist
+def is_hard_limit_exceeded(mnode, volname, path=None):
+ """Parse the output of 'gluster quota list' command.
+
+ Args:
+ mnode (str): Node on which command has to be executed.
+ volname (str): volume name
+
+ Kwargs:
+ path (str): Quota path
+
+ Returns:
+ boolean: True if exceeded, False if not.
+
+ Examples:
+ >>> get_quota_list('abc.lab.eng.xyz.com', "testvol")
+ {'/': {'used_space': '0', 'hl_exceeded': 'No', 'soft_limit_percent':
+ '60%', 'avail_space': '2147483648', 'soft_limit_value': '1288490188',
+ 'sl_exceeded': 'No', 'hard_limit': '2147483648'}}
+ """
+ if not path:
+ path = ''
+
+ cmd = "gluster volume quota %s list %s --xml" % (volname, path)
+ ret, out, _ = g.run(mnode, cmd)
+ if ret != 0:
+ g.log.error("Failed to execute 'quota list' on node %s. "
+ "Hence failed to get the quota list." %
+ mnode)
+ raise ExecutionError("Quota list --xml command failed")
+ else:
+ try:
+ root = etree.XML(out)
+ except etree.ParseError:
+ raise ExecutionParseError("Failed to parse the gluster quota "
+ "list xml output.")
+ else:
+ for path in root.findall("volQuota/limit"):
+ for elem in path.getchildren():
+ if elem.tag == 'hl_exceeded':
+ if elem.text == 'Yes':
+ return True
+ return False
+
+
+def is_soft_limit_exceeded(mnode, volname, path=None):
+ """Parse the output of 'gluster quota list' command.
+
+ Args:
+ mnode (str): Node on which command has to be executed.
+ volname (str): volume name
+
+ Kwargs:
+ path (str): Quota path
+
+ Returns:
+ boolean: True if exceeded, False if not.
+ Examples:
+ >>> get_quota_list('abc.lab.eng.xyz.com', "testvol")
+ {'/': {'used_space': '0', 'hl_exceeded': 'No', 'soft_limit_percent':
+ '60%', 'avail_space': '2147483648', 'soft_limit_value': '1288490188',
+ 'sl_exceeded': 'No', 'hard_limit': '2147483648'}}
+ """
+ if not path:
+ path = ''
+
+ cmd = "gluster volume quota %s list %s --xml" % (volname, path)
+ ret, out, _ = g.run(mnode, cmd)
+ if ret != 0:
+ g.log.error("Failed to execute 'quota list' on node %s. "
+ "Hence failed to get the quota list." %
+ mnode)
+ raise ExecutionError("Quota list --xml command failed")
+ if ret == 0:
+ try:
+ root = etree.XML(out)
+ except etree.ParseError:
+ raise ExecutionParseError("Failed to parse the gluster quota "
+ "list xml output.")
+ else:
+ for path in root.findall("volQuota/limit"):
+ for elem in path.getchildren():
+ if elem.tag == 'sl_exceeded':
+ if elem.text == 'Yes':
+ return True
+ return False
+
+
def set_quota_limit_objects(mnode, volname, path='/', limit='10',
soft_limit=''):
"""Sets limit-objects on the path of the specified volume to