Add uuid utils
Change-Id: Iae18676b91218dc5d7f0f74aa64056811cd82776
This commit is contained in:
parent
716083ac95
commit
1aeb503b1d
@ -18,6 +18,7 @@ import jsonrpclib
|
|||||||
import six
|
import six
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
|
||||||
def safe_decode(text, incoming=None, errors='strict'):
|
def safe_decode(text, incoming=None, errors='strict'):
|
||||||
@ -134,3 +135,32 @@ def get_ip_from_agent(node, net_type):
|
|||||||
return 1
|
return 1
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print "Can't get ip! Because: %s" % e
|
print "Can't get ip! Because: %s" % e
|
||||||
|
|
||||||
|
|
||||||
|
def generate_uuid():
|
||||||
|
"""Creates a random uuid string.
|
||||||
|
|
||||||
|
:returns: string
|
||||||
|
"""
|
||||||
|
return str(uuid.uuid4())
|
||||||
|
|
||||||
|
|
||||||
|
def _format_uuid_string(string):
|
||||||
|
return (string.replace('urn:', '')
|
||||||
|
.replace('uuid:', '')
|
||||||
|
.strip('{}')
|
||||||
|
.replace('-', '')
|
||||||
|
.lower())
|
||||||
|
|
||||||
|
|
||||||
|
def is_uuid_like(val):
|
||||||
|
"""Returns validation of a value as a UUID.
|
||||||
|
|
||||||
|
:param val: Value to verify
|
||||||
|
:type val: string
|
||||||
|
:returns: bool
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
return str(uuid.UUID(val)).replace('-', '') == _format_uuid_string(val)
|
||||||
|
except (TypeError, ValueError, AttributeError):
|
||||||
|
return False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user