diff options
author | Doug Hellmann <doug@doughellmann.com> | 2015-01-05 16:07:24 -0500 |
---|---|---|
committer | Doug Hellmann <doug@doughellmann.com> | 2015-01-06 17:07:36 -0500 |
commit | ca76fdcb52a5149f2b266bfb28c446f652c49128 (patch) | |
tree | 45b76495364cec84888fc5715ba8e3667bdc2bc9 /oslo_utils/uuidutils.py | |
parent | 44f36e35ec47d9ad430676c41749ccd5c6eadad4 (diff) | |
download | oslo-utils-ca76fdcb52a5149f2b266bfb28c446f652c49128.tar.gz |
Move files out of the namespace package
Move the public API out of oslo.utils to oslo_utils. Retain the ability
to import from the old namespace package for backwards compatibility for
this release cycle.
bp/drop-namespace-packages
Change-Id: Ic6dd62097399bf75e3d11b4d8a6400971069c415
Diffstat (limited to 'oslo_utils/uuidutils.py')
-rw-r--r-- | oslo_utils/uuidutils.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/oslo_utils/uuidutils.py b/oslo_utils/uuidutils.py new file mode 100644 index 0000000..62b0b5f --- /dev/null +++ b/oslo_utils/uuidutils.py @@ -0,0 +1,45 @@ +# Copyright (c) 2012 Intel Corporation. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +""" +UUID related utilities and helper functions. +""" + +import uuid + + +def generate_uuid(): + 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 |