summaryrefslogtreecommitdiffstats
path: root/onap_data_provider/resources/tenant_resource.py
diff options
context:
space:
mode:
Diffstat (limited to 'onap_data_provider/resources/tenant_resource.py')
-rw-r--r--onap_data_provider/resources/tenant_resource.py29
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.