aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsheetal ghadge <sheetal.ghadge@t-systems.com>2024-01-09 12:31:51 +0530
committersheetal ghadge <sheetal.ghadge@t-systems.com>2024-01-09 12:32:18 +0530
commit38a8f5e676c267e91fb017c40de96dd598be88cf (patch)
treedc082bf8c3fac2bb486c92ab202dba94e0ee620a /src
parent042cdc1e6310cddd92f0e60ffc840917a207b570 (diff)
change to delete service instance from aai:Updated service.py & nbi.py module
Issue-ID: TEST-413 Change-Id: If2e670e9ab3e819099376148620b47b36adb051d Signed-off-by: sheetal ghadge <sheetal.ghadge@t-systems.com>
Diffstat (limited to 'src')
-rw-r--r--src/onapsdk/aai/business/service.py54
-rw-r--r--src/onapsdk/nbi/nbi.py12
2 files changed, 52 insertions, 14 deletions
diff --git a/src/onapsdk/aai/business/service.py b/src/onapsdk/aai/business/service.py
index 9c2e7f8..d0f7876 100644
--- a/src/onapsdk/aai/business/service.py
+++ b/src/onapsdk/aai/business/service.py
@@ -131,10 +131,10 @@ class ServiceInstance(Instance): # pylint: disable=too-many-instance-attributes
def _get_related_instance(self,
related_instance_class: Union[Type[NetworkInstance],
- Type[VnfInstance]],
- relationship_related_to_type: str) -> Iterator[\
- Union[NetworkInstance,
- VnfInstance]]:
+ Type[VnfInstance]],
+ relationship_related_to_type: str) -> Iterator[ \
+ Union[NetworkInstance,
+ VnfInstance]]:
"""Iterate through related service instances.
This is method which for given `relationship_related_to_type` creates iterator
@@ -161,7 +161,7 @@ class ServiceInstance(Instance): # pylint: disable=too-many-instance-attributes
raise ParameterError(msg)
for relationship in self.relationships:
if relationship.related_to == relationship_related_to_type:
- yield related_instance_class.create_from_api_response(\
+ yield related_instance_class.create_from_api_response( \
self.send_message_json("GET",
(f"Get {self.instance_id} "
f"{related_instance_class.__class__.__name__}"),
@@ -169,7 +169,8 @@ class ServiceInstance(Instance): # pylint: disable=too-many-instance-attributes
self)
@classmethod
- def create(cls, service_subscription: "ServiceSubscription", # NOSONAR # pylint: disable=too-many-arguments, too-many-locals
+ def create(cls, service_subscription: "ServiceSubscription",
+ # NOSONAR # pylint: disable=too-many-arguments, too-many-locals
instance_id: str,
instance_name: str = None,
service_type: str = None,
@@ -256,9 +257,9 @@ class ServiceInstance(Instance): # pylint: disable=too-many-instance-attributes
input_parameters
)
cls.send_message("PUT",
- f"Create service instance {instance_id} for "\
+ f"Create service instance {instance_id} for " \
f"{service_subscription.service_type} service subscription",
- f"{service_subscription.url}/service-instances/service-instance/"\
+ f"{service_subscription.url}/service-instances/service-instance/" \
f"{instance_id}",
data=jinja_env()
.get_template("aai_service_instance_create.json.j2")
@@ -526,3 +527,40 @@ class ServiceInstance(Instance): # pylint: disable=too-many-instance-attributes
"""
self._logger.debug("Delete %s service instance", self.instance_id)
return ServiceDeletionRequest.send_request(self, a_la_carte)
+
+ def delete_from_aai(self,
+ service_subscription: "ServiceSubscription",
+ instance_id: str,
+ service_type: str = None) -> "ServiceInstance":
+ """Send request to AAI to delete service instance.
+
+ Args:
+ service_subscription (ServiceSubscription): service subscription which is belongs to
+ instance_id (str): Uniquely identifies this instance of a service
+ service_type (str, optional): String capturing type of service.Defaults to None.
+
+ """
+ customer_instance = service_subscription.customer
+ customer_id = customer_instance.global_customer_id
+
+ # calling GET api to get resource_version of service instance
+ response = self.send_message_json("GET",
+ f"GET service instance {instance_id} for ",
+ f"{self.base_url}{self.api_version}/business/"
+ f"customers/customer/"
+ f"{customer_id}/service-subscriptions/"
+ f"service-subscription/"
+ f"{service_type}/service-instances/service-instance/"
+ f"{instance_id}")
+
+ resource_version = str(response.get('resource-version', ''))
+
+ # calling delete api to delete service instance from AAI
+ self.send_message("DELETE",
+ f"Delete service instance {instance_id} for ",
+ f"{self.base_url}{self.api_version}/business/customers/customer/"
+ f"{customer_id}/service-subscriptions/"
+ f"service-subscription/"
+ f"{service_type}/service-instances/service-instance/"
+ f"{instance_id}?"
+ f"resource-version={resource_version}")
diff --git a/src/onapsdk/nbi/nbi.py b/src/onapsdk/nbi/nbi.py
index ffcd62c..3af85f6 100644
--- a/src/onapsdk/nbi/nbi.py
+++ b/src/onapsdk/nbi/nbi.py
@@ -170,9 +170,9 @@ class Service(Nbi):
super().__init__()
self.name: str = name
self.service_id: str = service_id
- self._service_specification_name: str = service_specification_name
+ self.service_specification_name: str = service_specification_name
self._service_specification_id: str = service_specification_id
- self._customer_id: str = customer_id
+ self.customer_id: str = customer_id
self.customer_role: str = customer_role
self.href: str = href
@@ -185,8 +185,8 @@ class Service(Nbi):
"""
return (f"Service(name={self.name}, service_id={self.service_id}, "
f"service_specification_id={self._service_specification_id}, "
- f"service_specification_name={self._service_specification_name}, "
- f"customer_id={self._customer_id}, "
+ f"service_specification_name={self.service_specification_name}, "
+ f"customer_id={self.customer_id}, "
f"customer_role={self.customer_role}, "
f"href={self.href})")
@@ -223,9 +223,9 @@ class Service(Nbi):
Customer: Customer object
"""
- if not self._customer_id:
+ if not self.customer_id:
return None
- return Customer.get_by_global_customer_id(self._customer_id)
+ return Customer.get_by_global_customer_id(self.customer_id)
@property
def service_specification(self) -> Optional[ServiceSpecification]: