diff options
author | Akarsha Rai <akrai@redhat.com> | 2019-01-24 11:29:32 +0530 |
---|---|---|
committer | Akarsha Rai <akrai@redhat.com> | 2019-01-24 11:31:02 +0530 |
commit | bc1e30c3ef6c374dbbd97154906ae5996f739c55 (patch) | |
tree | 011f461bc9e493376ee6353da22f63b5d2fd8e40 /glustolibs-gluster-gd2/glustolibs/gluster/lib_utils.py | |
parent | 55101fe0d9ba81e21b50e85c898e63bca2decfa1 (diff) |
Module contains the python glusterd2 volume api's implementation
Change-Id: I4560e39c5e8ae03d5a70271fb536023c506b1a5c
Signed-off-by: Akarsha Rai <akrai@redhat.com>
Diffstat (limited to 'glustolibs-gluster-gd2/glustolibs/gluster/lib_utils.py')
-rw-r--r-- | glustolibs-gluster-gd2/glustolibs/gluster/lib_utils.py | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/glustolibs-gluster-gd2/glustolibs/gluster/lib_utils.py b/glustolibs-gluster-gd2/glustolibs/gluster/lib_utils.py index 473f140..ebcdd9d 100644 --- a/glustolibs-gluster-gd2/glustolibs/gluster/lib_utils.py +++ b/glustolibs-gluster-gd2/glustolibs/gluster/lib_utils.py @@ -23,9 +23,44 @@ import random import copy import datetime import socket +from uuid import UUID from glusto.core import Glusto as g from glustolibs.gluster.mount_ops import create_mount_objs -from glustolibs.gluster.expections import ConfigError +from glustolibs.gluster.expections import ( + ConfigError, GlusterApiInvalidInputs) + + +def validate_uuid(brick_id, version=4): + """ + Validates the uuid + Args: + brick_id (str) : Brick_id to be validated + version (int) + Returns: + True (bool) on if the uuid is valid hex code, + else false + """ + try: + UUID(brick_id, version=version) + except ValueError: + # If it's a value error, then the string + # is not a valid hex code for a UUID. + g.log.error("Invalid brick_id %s", brick_id) + return False + return True + + +def validate_peer_id(peerid): + """ + Validates the peer id + Args: + peer id (str) : peer id to be validated + Returns: + Exceptions on failure + """ + if not validate_uuid(peerid): + g.log.error("Invalid peer id %s speceified", peerid) + raise GlusterApiInvalidInputs("Invalid peer id specified") def inject_msg_in_logs(nodes, log_msg, list_of_dirs=None, list_of_files=None): |