1 # ============LICENSE_START=======================================================
2 # Copyright (C) 2020 Orange
3 # ================================================================================
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # ============LICENSE_END=========================================================
19 from time import sleep
21 from onapsdk.aai.business import Customer
22 from onapsdk.so.so_element import OrchestrationRequest
24 from config import Config
26 logger = logging.getLogger("")
27 logger.setLevel(logging.DEBUG)
28 fh = logging.StreamHandler()
29 fh_formatter = logging.Formatter('%(asctime)s %(levelname)s %(lineno)d:%(filename)s(%(process)d) - %(message)s')
30 fh.setFormatter(fh_formatter)
33 logger.info("******** Get Customer *******")
36 customer = Customer.get_by_global_customer_id(Config.GLOBAL_CUSTOMER_ID)
38 logger.error("Customer not found")
41 logger.info("******** Check Service Subscription *******")
42 service_subscription = None
43 for service_sub in customer.service_subscriptions:
44 if service_sub.service_type == Config.SERVICENAME:
45 logger.info("Service %s subscribed", Config.SERVICENAME)
46 service_subscription = service_sub
48 if not service_subscription:
49 logger.error("Service Subscription not found")
52 logger.info("******** Get Service Instance details *******")
53 service_instance = None
54 for service in service_subscription.service_instances:
55 if service.instance_name == Config.SERVICE_INSTANCE_NAME:
56 service_instance = service
58 if not service_instance:
59 logger.error("Service Instance not found")
62 logger.info("******** Delete Service %s *******", service_instance.instance_name)
63 service_deletion = service_instance.delete()
65 while not (status == OrchestrationRequest.StatusEnum.COMPLETED
66 or status == OrchestrationRequest.StatusEnum.FAILED):
68 status = service_deletion.status
69 logger.info(f"Orchestration status is: {status.value}")