Add api to get the shorten uuid suffix of resources names utility

Change-Id: Ide203770bd6d56559d06b7848ed6f6bacbc9a5b5
This commit is contained in:
asarfaty 2020-05-27 15:59:35 +02:00 committed by Adit Sarfaty
parent 00a72d996f
commit b45fcf19b5
2 changed files with 11 additions and 1 deletions

View File

@ -118,6 +118,12 @@ class TestNsxV3Utils(nsxlib_testcase.NsxClientTestCase):
short_name = utils.get_name_and_uuid(name, uuid)
self.assertEqual(expected, short_name)
def test_get_name_short_uuid(self):
uuid = 'afc40f8a-4967-477e-a17a-9d560d1786c7'
suffix = '_afc40...786c7'
short_uuid = utils.get_name_short_uuid(uuid)
self.assertEqual(suffix, short_uuid)
def test_build_v3_tags_max_length_payload(self):
result = self.nsxlib.build_v3_tags_payload(
{'id': 'X' * 255,

View File

@ -242,8 +242,12 @@ def dict_match(dict1, dict2):
return True
def get_name_short_uuid(uuid):
return '_' + uuid[:5] + '...' + uuid[-5:]
def get_name_and_uuid(name, uuid, tag=None, maxlen=80):
short_uuid = '_' + uuid[:5] + '...' + uuid[-5:]
short_uuid = get_name_short_uuid(uuid)
maxlen = maxlen - len(short_uuid)
if tag:
maxlen = maxlen - len(tag) - 1