2022-11-13 02:15:47 +00:00
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
# Copyright (C) 2022 Intel Corporation.
|
|
|
|
# All rights reserved.
|
|
|
|
|
2022-01-05 09:32:09 +00:00
|
|
|
import uuid
|
|
|
|
|
|
|
|
|
|
|
|
def format_volume_id(volume_id):
|
|
|
|
"""Verifies volume_id and returns it as a str
|
|
|
|
|
|
|
|
Args:
|
|
|
|
volume_id: either a str (in which case it's only validated) or bytes object
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
if type(volume_id) is bytes:
|
|
|
|
return str(uuid.UUID(bytes=volume_id))
|
|
|
|
elif type(volume_id) is str:
|
|
|
|
return str(uuid.UUID(hex=volume_id))
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
return None
|
2022-08-03 03:19:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
def volume_id_to_nguid(uuid):
|
|
|
|
return uuid.replace('-', '')
|