Add optional project id to build_v3_api_version_project_tag

This will allow policy objects to have project id tag even without a
neutron resource id

Change-Id: I58ae385981e020ff3876da9c0ac20afd1ceca3be
This commit is contained in:
Adit Sarfaty 2018-12-24 14:19:12 +02:00
parent f5bafe0ff4
commit 6e61443bd5
3 changed files with 24 additions and 4 deletions

View File

@ -77,6 +77,21 @@ class TestNsxV3Utils(nsxlib_testcase.NsxClientTestCase):
'tag': proj}]
self.assertEqual(expected, result)
def test_build_v3_api_version_project_id_tag(self):
proj = 'project_x'
proj_id = 'project_id'
result = self.nsxlib.build_v3_api_version_project_tag(
proj, project_id=proj_id)
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},
{'scope': 'os-project-id',
'tag': proj_id}]
self.assertEqual(expected, result)
def test_is_internal_resource(self):
project_tag = self.nsxlib.build_v3_tags_payload(
{'id': 'fake_id',

View File

@ -94,8 +94,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_api_version_project_tag(self, project_name, project_id=None):
return self.general_apis.build_v3_api_version_project_tag(
project_name, project_id=project_id)
def build_v3_tags_payload(self, resource, resource_type, project_name):
return self.general_apis.build_v3_tags_payload(

View File

@ -494,15 +494,19 @@ class NsxLibApiBase(object):
{'scope': "os-api-version",
'tag': self.nsxlib_config.plugin_ver}]
def build_v3_api_version_project_tag(self, project_name):
def build_v3_api_version_project_tag(self, project_name, project_id=None):
if not project_name:
project_name = self.nsxlib_config.plugin_tag
return [{'scope': self.nsxlib_config.plugin_scope,
tags = [{'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]}]
if project_id:
tags.append({'scope': 'os-project-id',
'tag': project_id[:MAX_TAG_LEN]})
return tags
def is_internal_resource(self, nsx_resource):
"""Indicates whether the passed nsx-resource is internal