Add utility to generate tags with api version & project name

Those tags can be used for policy resources, where there is no need
to add the os resource id to the tags, as it is the same as the NSX id.

Change-Id: I4e9644957dbfd16194f556cbff5447f2a2e49669
This commit is contained in:
Adit Sarfaty 2018-10-22 13:32:48 +03:00
parent 5a6252b036
commit 94936bc616
3 changed files with 24 additions and 0 deletions

View File

@ -66,6 +66,17 @@ class TestNsxV3Utils(nsxlib_testcase.NsxClientTestCase):
'tag': nsxlib_testcase.PLUGIN_VER}]
self.assertEqual(expected, result)
def test_build_v3_api_version_project_tag(self):
proj = 'project_x'
result = self.nsxlib.build_v3_api_version_project_tag(proj)
expected = [{'scope': nsxlib_testcase.PLUGIN_SCOPE,
'tag': nsxlib_testcase.PLUGIN_TAG},
{'scope': 'os-api-version',
'tag': nsxlib_testcase.PLUGIN_VER},
{'scope': 'os-project-name',
'tag': proj}]
self.assertEqual(expected, result)
def test_is_internal_resource(self):
project_tag = self.nsxlib.build_v3_tags_payload(
{'id': 'fake_id',

View File

@ -93,6 +93,9 @@ class NsxLibBase(object):
def is_internal_resource(self, nsx_resource):
return self.general_apis.is_internal_resource(nsx_resource)
def build_v3_api_version_project_tag(self, project_name):
return self.general_apis.build_v3_api_version_project_tag(project_name)
def build_v3_tags_payload(self, resource, resource_type, project_name):
return self.general_apis.build_v3_tags_payload(
resource, resource_type, project_name)

View File

@ -494,6 +494,16 @@ class NsxLibApiBase(object):
{'scope': "os-api-version",
'tag': self.nsxlib_config.plugin_ver}]
def build_v3_api_version_project_tag(self, project_name):
if not project_name:
project_name = self.nsxlib_config.plugin_tag
return [{'scope': self.nsxlib_config.plugin_scope,
'tag': self.nsxlib_config.plugin_tag},
{'scope': "os-api-version",
'tag': self.nsxlib_config.plugin_ver},
{'scope': 'os-project-name',
'tag': project_name[:MAX_TAG_LEN]}]
def is_internal_resource(self, nsx_resource):
"""Indicates whether the passed nsx-resource is internal