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/cloud_region_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/cloud_region_resource.py')
-rw-r--r-- | onap_data_provider/resources/cloud_region_resource.py | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/onap_data_provider/resources/cloud_region_resource.py b/onap_data_provider/resources/cloud_region_resource.py index 7bcc3b4..9f66b48 100644 --- a/onap_data_provider/resources/cloud_region_resource.py +++ b/onap_data_provider/resources/cloud_region_resource.py @@ -21,6 +21,8 @@ from onap_data_provider.resources.esr_system_info_resource import ( import logging from typing import Any, Dict +from onapsdk.aai.aai_element import Relationship # type: ignore +from onapsdk.aai.business import Project # type: ignore from onapsdk.aai.cloud_infrastructure import CloudRegion, Complex # type: ignore from onapsdk.msb.k8s.connectivity_info import ConnectivityInfo # type: ignore from onapsdk.so.so_db_adapter import SoDbAdapter, IdentityService # type: ignore @@ -122,6 +124,20 @@ class CloudRegionResource(Resource): IdentityService("DEFAULT_KEYSTONE"), ) + # Link with project + for project_data in self.data.get("projects", []): + try: + project: Project = Project.get_by_name(project_data["project"]["name"]) + except ResourceNotFound: + project = Project.create(project_data["project"]["name"]) + project.add_relationship( + Relationship( + related_to="cloud-region", + related_link=self.cloud_region.url, + relationship_data=[] + ) + ) + @property def exists(self) -> bool: """Determine if resource already exists or not. @@ -156,21 +172,16 @@ class CloudRegionResource(Resource): return self._cloud_region def _link_to_complex(self, complex_physical_id: str) -> None: - try: # TODO: change it when https://gitlab.com/Orange-OpenSource/lfn/onap/python-onapsdk/-/issues/120 is fixed - if self.cloud_region.complex: - logging.info( - "Cloud region has relationship with complex: %s. New relationship can't be created", - self.cloud_region.complex.physical_location_id, - ) - return - except ResourceNotFound: - logging.debug("Cloud region has no complex linked with") - try: - complex: Complex = next( - Complex.get_all(physical_location_id=complex_physical_id) + if self.cloud_region.complex: + logging.info( + "Cloud region has relationship with complex: %s. New relationship can't be created", + self.cloud_region.complex.physical_location_id, ) - self.cloud_region.link_to_complex(complex) - except StopIteration: + return + try: + cmplx: Complex = Complex.get_by_physical_location_id(complex_physical_id) + self.cloud_region.link_to_complex(cmplx) + except ResourceNotFound: logging.error( "Complex %s does not exist, please create it before cloud region creation", complex_physical_id, |