diff options
author | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2022-06-27 12:59:33 +0000 |
---|---|---|
committer | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2022-06-28 08:21:07 +0000 |
commit | 04e8c7658c0ed31a334cf64fcfd4aa5f1962b39d (patch) | |
tree | d015899d69ad3cf178fb737c9e7794265cd2bfd7 /onap_data_provider/resources/tenant_resource.py | |
parent | 0565394ecbd96730bf982909693514ab88703708 (diff) |
[Data provider] Add relationships between some A&AI resources0.6.0
Create relationship between:
Tenant <-> Line of business
Tenant <-> Owning entity
Cloud region <-> Project
Issue-ID: INT-2126
Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl>
Change-Id: I3523c02b28b5fe972c0fbba112c8ffa532feadb8
Diffstat (limited to 'onap_data_provider/resources/tenant_resource.py')
-rw-r--r-- | onap_data_provider/resources/tenant_resource.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/onap_data_provider/resources/tenant_resource.py b/onap_data_provider/resources/tenant_resource.py index 13d003f..b4bca68 100644 --- a/onap_data_provider/resources/tenant_resource.py +++ b/onap_data_provider/resources/tenant_resource.py @@ -17,7 +17,9 @@ import logging from typing import Any, Dict, Optional +from onapsdk.aai.aai_element import Relationship # type: ignore from onapsdk.aai.cloud_infrastructure import CloudRegion, Tenant # type: ignore +from onapsdk.aai.business import LineOfBusiness, OwningEntity # type: ignore from .resource import Resource from onapsdk.exceptions import ResourceNotFound # type: ignore @@ -54,6 +56,33 @@ class TenantResource(Resource): tenant_context=self.data.get("tenant-context"), ) + for lines_of_business_data in self.data.get("lines-of-business", []): + try: + line_of_business: LineOfBusiness = LineOfBusiness.get_by_name(lines_of_business_data["line-of-business"]["name"]) + except ResourceNotFound: + line_of_business = LineOfBusiness.create(lines_of_business_data["line-of-business"]["name"]) + line_of_business.add_relationship( + Relationship( + related_to="tenant", + related_link=self.tenant.url, + relationship_data=[] + ) + ) + + for owning_entities_data in self.data.get("owning-entities", []): + try: + owning_entity: OwningEntity = OwningEntity.get_by_owning_entity_name(owning_entities_data["owning-entity"]["name"]) + except ResourceNotFound: + owning_entity = OwningEntity.create(owning_entities_data["owning-entity"]["name"], + owning_entities_data["owning-entity"]["id"]) + owning_entity.add_relationship( + Relationship( + related_to="tenant", + related_link=self.tenant.url, + relationship_data=[] + ) + ) + @property def exists(self) -> bool: """Determine if resource already exists or not. |