diff options
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 ) |