aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/onapsdk/aai/aai_element.py20
-rw-r--r--src/onapsdk/aai/business/customer.py22
-rw-r--r--src/onapsdk/aai/business/line_of_business.py15
-rw-r--r--src/onapsdk/aai/business/owning_entity.py16
-rw-r--r--src/onapsdk/aai/business/platform.py8
-rw-r--r--src/onapsdk/aai/business/project.py8
-rw-r--r--src/onapsdk/aai/cloud_infrastructure/cloud_region.py3
-rw-r--r--src/onapsdk/aai/cloud_infrastructure/tenant.py16
-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
-rw-r--r--src/onapsdk/aai/network/site_resource.py3
-rw-r--r--src/onapsdk/aai/templates/aai_delete_relationship.json.j211
13 files changed, 245 insertions, 15 deletions
diff --git a/src/onapsdk/aai/aai_element.py b/src/onapsdk/aai/aai_element.py
index 907028d..5b72f95 100644
--- a/src/onapsdk/aai/aai_element.py
+++ b/src/onapsdk/aai/aai_element.py
@@ -215,6 +215,7 @@ class AaiResource(AaiElement):
relationship (Relationship): Relationship to add
"""
+ self._logger.info("Adding relationship to aai resource")
self.send_message(
"PUT",
f"add relationship to {self.__class__.__name__}",
@@ -223,3 +224,22 @@ class AaiResource(AaiElement):
.get_template("aai_add_relationship.json.j2")
.render(relationship=relationship),
)
+
+ def delete_relationship(self, relationship: Relationship) -> None:
+ """Delete relationship from aai resource.
+
+ Delete relationship from resource using A&AI API
+
+ Args:
+ relationship (Relationship): Relationship to delete
+
+ """
+ self._logger.info("Deleting relationship from aai resource")
+ self.send_message(
+ "DELETE",
+ f"delete relationship from {self.__class__.__name__}",
+ f"{self.url}/relationship-list/relationship",
+ data=jinja_env()
+ .get_template("aai_delete_relationship.json.j2")
+ .render(relationship=relationship),
+ )
diff --git a/src/onapsdk/aai/business/customer.py b/src/onapsdk/aai/business/customer.py
index cdefd6f..1df1bc2 100644
--- a/src/onapsdk/aai/business/customer.py
+++ b/src/onapsdk/aai/business/customer.py
@@ -265,8 +265,8 @@ class ServiceSubscription(AaiResource):
yield CloudRegion.get_by_id(cloud_owner=cloud_region_data[0],
cloud_region_id=cloud_region_data[1])
except ResourceNotFound:
- self._logger.error("Can't get cloud region %s %s", cloud_region_data[0], \
- cloud_region_data[1])
+ self._logger.error("Can't get cloud region %s %s", cloud_region_data[0],
+ cloud_region_data[1])
@property
def tenants(self) -> Iterator["Tenant"]:
@@ -560,7 +560,7 @@ class Customer(AaiResource):
)
except ResourceNotFound as exc:
self._logger.info(
- "Subscriptions are not " \
+ "Subscriptions are not "
"found for a customer: %s", exc)
except APIError as exc:
self._logger.error(
@@ -590,6 +590,22 @@ class Customer(AaiResource):
)
return self.get_service_subscription_by_service_type(service_type)
+ def delete_subscribed_service(self, service_sub: ServiceSubscription) -> None:
+ """Delete SDC Service subscription.
+
+ Args:
+ service_sub (str): Value defined by orchestration to identify this service
+ across ONAP.
+ """
+ self.send_message(
+ "DELETE",
+ "Delete service subscription",
+ (f"{self.base_url}{self.api_version}/business/customers/"
+ f"customer/{self.global_customer_id}/service-subscriptions/"
+ f"service-subscription/{service_sub.service_type}?"
+ f"resource-version={service_sub.resource_version}")
+ )
+
def delete(self) -> None:
"""Delete customer.
diff --git a/src/onapsdk/aai/business/line_of_business.py b/src/onapsdk/aai/business/line_of_business.py
index 61fc0f8..a1b807d 100644
--- a/src/onapsdk/aai/business/line_of_business.py
+++ b/src/onapsdk/aai/business/line_of_business.py
@@ -16,11 +16,12 @@
from typing import Any, Dict, Iterator
from onapsdk.utils.jinja import jinja_env
+from onapsdk.aai.mixins.link_to_tenant import AaiResourceLinkToTenantMixin
from ..aai_element import AaiResource
-class LineOfBusiness(AaiResource):
+class LineOfBusiness(AaiResource, AaiResourceLinkToTenantMixin):
"""Line of business class."""
def __init__(self, name: str, resource_version: str) -> None:
@@ -121,3 +122,15 @@ class LineOfBusiness(AaiResource):
f"Get {name} line of business",
url)
return cls(response["line-of-business-name"], response["resource-version"])
+
+ def delete(self) -> None:
+ """Delete line of business.
+
+ Sends request to A&AI to delete line of business object.
+
+ """
+ self.send_message(
+ "DELETE",
+ f"Delete line of business",
+ f"{self.url}?resource-version={self.resource_version}"
+ )
diff --git a/src/onapsdk/aai/business/owning_entity.py b/src/onapsdk/aai/business/owning_entity.py
index bf1e7c1..ebe9b11 100644
--- a/src/onapsdk/aai/business/owning_entity.py
+++ b/src/onapsdk/aai/business/owning_entity.py
@@ -21,8 +21,10 @@ from onapsdk.exceptions import ResourceNotFound
from ..aai_element import AaiResource
+from ..mixins.link_to_tenant import AaiResourceLinkToTenantMixin
-class OwningEntity(AaiResource):
+
+class OwningEntity(AaiResource, AaiResourceLinkToTenantMixin):
"""Owning entity class."""
def __init__(self, name: str, owning_entity_id: str, resource_version: str) -> None:
@@ -152,3 +154,15 @@ class OwningEntity(AaiResource):
)
)
return cls.get_by_owning_entity_id(owning_entity_id)
+
+ def delete(self) -> None:
+ """Delete owning entity.
+
+ Sends request to A&AI to delete owning entity object.
+
+ """
+ self.send_message(
+ "DELETE",
+ f"Delete owning entity",
+ f"{self.url}?resource-version={self.resource_version}"
+ )
diff --git a/src/onapsdk/aai/business/platform.py b/src/onapsdk/aai/business/platform.py
index 5c12ba8..f652e32 100644
--- a/src/onapsdk/aai/business/platform.py
+++ b/src/onapsdk/aai/business/platform.py
@@ -121,3 +121,11 @@ class Platform(AaiResource):
f"Get {name} platform",
url)
return cls(response["platform-name"], response["resource-version"])
+
+ def delete(self) -> None:
+ """Delete platform."""
+ self.send_message(
+ "DELETE",
+ f"Delete platform",
+ f"{self.url}?resource-version={self.resource_version}"
+ )
diff --git a/src/onapsdk/aai/business/project.py b/src/onapsdk/aai/business/project.py
index 989444a..fcab0e8 100644
--- a/src/onapsdk/aai/business/project.py
+++ b/src/onapsdk/aai/business/project.py
@@ -121,3 +121,11 @@ class Project(AaiResource):
f"Get {name} project",
url)
return cls(response["project-name"], response["resource-version"])
+
+ def delete(self) -> None:
+ """Delete project."""
+ self.send_message(
+ "DELETE",
+ "Delete project",
+ f"{self.url}?resource-version={self.resource_version}"
+ )
diff --git a/src/onapsdk/aai/cloud_infrastructure/cloud_region.py b/src/onapsdk/aai/cloud_infrastructure/cloud_region.py
index 997f426..171be34 100644
--- a/src/onapsdk/aai/cloud_infrastructure/cloud_region.py
+++ b/src/onapsdk/aai/cloud_infrastructure/cloud_region.py
@@ -22,6 +22,7 @@ from onapsdk.exceptions import ResourceNotFound
from ..aai_element import AaiResource
from ..mixins.link_to_complex import AaiResourceLinkToComplexMixin
+from ..mixins.link_to_project import AaiResourceLinkToProjectMixin
from .complex import Complex
from .tenant import Tenant
@@ -66,7 +67,7 @@ class EsrSystemInfo: # pylint: disable=too-many-instance-attributes
openstack_region_id: str = None
-class CloudRegion(AaiResource, AaiResourceLinkToComplexMixin): # pylint: disable=too-many-instance-attributes
+class CloudRegion(AaiResource, AaiResourceLinkToComplexMixin, AaiResourceLinkToProjectMixin): # pylint: disable=too-many-instance-attributes
"""Cloud region class.
Represents A&AI cloud region object.
diff --git a/src/onapsdk/aai/cloud_infrastructure/tenant.py b/src/onapsdk/aai/cloud_infrastructure/tenant.py
index 13d9aec..7377b8e 100644
--- a/src/onapsdk/aai/cloud_infrastructure/tenant.py
+++ b/src/onapsdk/aai/cloud_infrastructure/tenant.py
@@ -12,11 +12,11 @@
# 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 onapsdk.aai.cloud_infrastructure.cloud_region import CloudRegion
+#from onapsdk.aai.cloud_infrastructure.cloud_region import CloudRegion
from ..aai_element import AaiResource
-class Tenant(AaiResource):
+class Tenant(AaiResource): # pylint: disable=too-many-instance-attributes
"""Tenant class."""
def __init__(self, # pylint: disable=too-many-arguments
@@ -69,9 +69,12 @@ class Tenant(AaiResource):
str: Url to get all tenants
"""
- return (f"{cls.base_url}{cls.api_version}/cloud-infrastructure/cloud-regions/cloud-region/"
- f"{cloud_region.cloud_owner}/{cloud_region.cloud_region_id}"
- f"/tenants/")
+ return (
+ f"{cls.base_url}{cls.api_version}/cloud-infrastructure/"
+ f"cloud-regions/cloud-region/"
+ f"{cloud_region.cloud_owner}/{cloud_region.cloud_region_id}"
+ f"/tenants/"
+ )
@property
def url(self) -> str:
@@ -82,7 +85,8 @@ class Tenant(AaiResource):
"""
return (
- f"{self.base_url}{self.api_version}/cloud-infrastructure/cloud-regions/cloud-region/"
+ f"{self.base_url}{self.api_version}/cloud-infrastructure/"
+ f"cloud-regions/cloud-region/"
f"{self.cloud_region.cloud_owner}/{self.cloud_region.cloud_region_id}"
f"/tenants/tenant/{self.tenant_id}?"
f"resource-version={self.resource_version}"
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)
diff --git a/src/onapsdk/aai/network/site_resource.py b/src/onapsdk/aai/network/site_resource.py
index 11a50c1..e6916f7 100644
--- a/src/onapsdk/aai/network/site_resource.py
+++ b/src/onapsdk/aai/network/site_resource.py
@@ -19,9 +19,10 @@ from onapsdk.utils.jinja import jinja_env
from ..aai_element import AaiResource, Relationship, RelationshipLabelEnum
from ..cloud_infrastructure import Complex
from ..mixins.link_to_complex import AaiResourceLinkToComplexMixin
+from ..mixins.link_to_project import AaiResourceLinkToProjectMixin
-class SiteResource(AaiResource, AaiResourceLinkToComplexMixin): # pylint: disable=too-many-instance-attributes
+class SiteResource(AaiResource, AaiResourceLinkToComplexMixin, AaiResourceLinkToProjectMixin): # pylint: disable=too-many-instance-attributes
"""Site resource class."""
def __init__(self, # pylint: disable=too-many-locals
diff --git a/src/onapsdk/aai/templates/aai_delete_relationship.json.j2 b/src/onapsdk/aai/templates/aai_delete_relationship.json.j2
new file mode 100644
index 0000000..5d7acb8
--- /dev/null
+++ b/src/onapsdk/aai/templates/aai_delete_relationship.json.j2
@@ -0,0 +1,11 @@
+{
+ "related-to": "{{ relationship.related_to }}",
+ "related-link": "{{ relationship.related_link }}",
+ {% if relationship.relationship_label %}
+ "relationship-label": "{{ relationship.relationship_label }}",
+ {% endif %}
+ {% if relationship.related_to_property %}
+ "related-to-property": {{ relationship.related_to_property | tojson }},
+ {% endif %}
+ "relationship-data": {{ relationship.relationship_data | tojson }}
+} \ No newline at end of file