From bc1e30c3ef6c374dbbd97154906ae5996f739c55 Mon Sep 17 00:00:00 2001 From: Akarsha Rai Date: Thu, 24 Jan 2019 11:29:32 +0530 Subject: Module contains the python glusterd2 volume api's implementation Change-Id: I4560e39c5e8ae03d5a70271fb536023c506b1a5c Signed-off-by: Akarsha Rai --- .../glustolibs/gluster/lib_utils.py | 37 +++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'glustolibs-gluster-gd2/glustolibs/gluster/lib_utils.py') 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): -- cgit