aboutsummaryrefslogtreecommitdiffstats
path: root/src/onapsdk/aai/mixins
diff options
context:
space:
mode:
authorKiran <kiran.mhetre@t-systems.com>2023-10-03 10:46:29 +0530
committerKiran <kiran.mhetre@t-systems.com>2023-10-05 19:44:33 +0530
commit9676519775c5cac40791fa02071301dbb7974c59 (patch)
tree33b67d4d947f293cf3ea04a6300e1fb2eb5f8971 /src/onapsdk/aai/mixins
parent7f61bdf95398b461581a2b0aec043faa24c94ee2 (diff)
updated changes for delete functionality for entities and relationship between entities.
Issue-ID: TEST-407 Change-Id: Ie8abaee76af001260ae999d3e56e886b8f449517 Signed-off-by: Kiran <kiran.mhetre@t-systems.com>
Diffstat (limited to 'src/onapsdk/aai/mixins')
-rw-r--r--src/onapsdk/aai/mixins/link_to_complex.py4
-rw-r--r--src/onapsdk/aai/mixins/link_to_project.py65
-rw-r--r--src/onapsdk/aai/mixins/link_to_tenant.py69
3 files changed, 136 insertions, 2 deletions
diff --git a/src/onapsdk/aai/mixins/link_to_complex.py b/src/onapsdk/aai/mixins/link_to_complex.py
index af43125..178447a 100644
--- a/src/onapsdk/aai/mixins/link_to_complex.py
+++ b/src/onapsdk/aai/mixins/link_to_complex.py
@@ -25,8 +25,8 @@ class AaiResourceLinkToComplexMixin: # pylint: disable=too-few-public-methods
"""Link aai resource to complex mixin."""
def link_to_complex(self, cmplx: "Complex",
- relationship_label: RelationshipLabelEnum =\
- RelationshipLabelEnum.LOCATED_IN) -> None:
+ relationship_label: RelationshipLabelEnum = \
+ RelationshipLabelEnum.LOCATED_IN) -> None:
"""Create a relationship with complex resource.
Args:
diff --git a/src/onapsdk/aai/mixins/link_to_project.py b/src/onapsdk/aai/mixins/link_to_project.py
new file mode 100644
index 0000000..43c2191
--- /dev/null
+++ b/src/onapsdk/aai/mixins/link_to_project.py
@@ -0,0 +1,65 @@
+"""A&AI link to project module."""
+# Copyright 2023 Deutsche Telekom AG
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from typing import TYPE_CHECKING
+
+from ..aai_element import Relationship, RelationshipLabelEnum
+
+if TYPE_CHECKING:
+ from ..business.project import Project
+
+
+class AaiResourceLinkToProjectMixin: # pylint: disable=too-few-public-methods
+ """Link aai resource to project mixin."""
+
+ def link_to_project(self, project: "Project") -> None:
+ """Create a relationship with project resource.
+
+ Args:
+ project (Project): Project object to create relationship with.
+
+ """
+ pro_relationship: Relationship = Relationship(
+ related_to="project",
+ related_link=project.url,
+ relationship_data=[
+ {
+ "relationship-key": "project.project-name",
+ "relationship-value": project.name,
+ }
+ ],
+ relationship_label=RelationshipLabelEnum.PART_OF.value,
+ )
+ self.add_relationship(pro_relationship)
+
+ def delete_relationship_with_project(self, project: "Project") -> None:
+ """Delete relationship with project resource.
+
+ Args:
+ project (Project): Project object to delete relationship with.
+
+ """
+ proj_relationship: Relationship = Relationship(
+ related_to="project",
+ related_link=project.url,
+ relationship_data=[
+ {
+ "relationship-key": "project.project-name",
+ "relationship-value": project.name,
+ }
+ ],
+ relationship_label=RelationshipLabelEnum.PART_OF.value,
+ )
+ self.delete_relationship(proj_relationship)
diff --git a/src/onapsdk/aai/mixins/link_to_tenant.py b/src/onapsdk/aai/mixins/link_to_tenant.py
new file mode 100644
index 0000000..8eef5b3
--- /dev/null
+++ b/src/onapsdk/aai/mixins/link_to_tenant.py
@@ -0,0 +1,69 @@
+"""A&AI link to project module."""
+# Copyright 2023 Deutsche Telekom AG
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from typing import TYPE_CHECKING
+
+from ..aai_element import Relationship, RelationshipLabelEnum
+
+if TYPE_CHECKING:
+ from ..cloud_infrastructure.tenant import Tenant
+
+
+class AaiResourceLinkToTenantMixin: # pylint: disable=too-few-public-methods
+ """Link aai resource to tenant mixin."""
+
+ def link_to_tenant(self, tnant: "Tenant") -> None:
+ """Create a relationship with tenant resource.
+
+ few resources create same relationship with tenant
+
+ Args:
+ tenant (Tenant): Tenant object to create relationship with.
+
+ """
+ tnt_relationship: Relationship = Relationship(
+ related_to="tenant",
+ related_link=tnant.url,
+ relationship_data=[
+ {
+ "relationship-key": "tenant.name",
+ "relationship-value": tnant.name,
+ }
+ ],
+ relationship_label=RelationshipLabelEnum.USES.value,
+ )
+ self.add_relationship(tnt_relationship)
+
+ def delete_relationship_with_tenant(self, tenant: "Tenant") -> None:
+ """Delete relationship with tenant resource.
+
+ as few resources delete same relationship with tenant
+
+ Args:
+ tenant (Tenant): Tenant object to delete relationship with.
+
+ """
+ tenant_relationship: Relationship = Relationship(
+ related_to="tenant",
+ related_link=tenant.url,
+ relationship_data=[
+ {
+ "relationship-key": "tenant.name",
+ "relationship-value": tenant.name,
+ }
+ ],
+ relationship_label=RelationshipLabelEnum.USES.value,
+ )
+ self.delete_relationship(tenant_relationship)