diff options
author | Piotr Stanior <piotr.stanior@t-mobile.pl> | 2022-01-31 08:44:09 +0100 |
---|---|---|
committer | Piotr Stanior <piotr.stanior@t-mobile.pl> | 2022-01-31 14:24:40 +0100 |
commit | e9dbe96626c23204bac7426bba69b4e2aedfbd8f (patch) | |
tree | 3449c37bf36d99d996e5ee7bf328006229ee3318 /onap_data_provider/resources/service_instance_resource.py | |
parent | 9cc10c174cc0be43df44f27fd9a43bb8675695a9 (diff) |
Allow tenant name in service instantiation
Change-Id: I26af41c8a1bf35c21f62d9b252fcd5eb9c7bbaee
Signed-off-by: Piotr Stanior <piotr.stanior@t-mobile.pl>
Issue-ID: INT-2048
Signed-off-by: Piotr Stanior <piotr.stanior@t-mobile.pl>
Diffstat (limited to 'onap_data_provider/resources/service_instance_resource.py')
-rw-r--r-- | onap_data_provider/resources/service_instance_resource.py | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/onap_data_provider/resources/service_instance_resource.py b/onap_data_provider/resources/service_instance_resource.py index b9af670..b23de40 100644 --- a/onap_data_provider/resources/service_instance_resource.py +++ b/onap_data_provider/resources/service_instance_resource.py @@ -69,7 +69,33 @@ class ServiceInstanceResource(Resource): cloud_owner=self.data["cloud_owner"], cloud_region_id=cloud_region_id, ) - tenant: Tenant = cloud_region.get_tenant(self.data["tenant_id"]) + tenant: Tenant = None + if tenant_name := self.data.get("tenant_name"): + # TODO: https://jira.onap.org/browse/INT-2056 refactor below when ONAP SDK 9.2.3 is released + cr_tenants = [ + x for x in cloud_region.tenants if x.name == tenant_name + ] + if len(cr_tenants) > 1: + msg = "\n".join( + [ + "===================", + f"There are more than one tenant with given name '{tenant_name}':", + "\n".join( + f"{t.name}: {t.tenant_id}" for t in cr_tenants + ), + "Use tenant-id instead of tenant-name to specify which tenant should be used during the instantiation.", + "===================", + ] + ) + logging.error(msg) + raise ValueError( + "Value provided for 'tenant_name' is ambiguous." + ) + if not cr_tenants: + raise ValueError(f"Tenant '{tenant_name}' not found.") + tenant = cr_tenants.pop() + else: + tenant = cloud_region.get_tenant(self.data["tenant_id"]) self.service_subscription.link_to_cloud_region_and_tenant( cloud_region, tenant ) |