Check orchestration status during instantiation and deletion vFW_CNF_CDS usecase
[demo.git] / heat / vFW_CNF_CDS / automation / delete.py
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
7 #
8 #      http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15 #
16 # ============LICENSE_END=========================================================
17
18 import logging
19 from time import sleep
20
21 from onapsdk.aai.business import Customer
22 from onapsdk.so.so_element import OrchestrationRequest
23
24 from config import Config
25
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)
31 logger.addHandler(fh)
32
33 logger.info("******** Get Customer *******")
34 customer = None
35 try:
36     customer = Customer.get_by_global_customer_id(Config.GLOBAL_CUSTOMER_ID)
37 except:
38     logger.error("Customer not found")
39     exit(1)
40
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
47         break
48 if not service_subscription:
49     logger.error("Service Subscription not found")
50     exit(1)
51
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
57         break
58 if not service_instance:
59     logger.error("Service Instance not found")
60     exit(1)
61
62 logger.info("******** Delete Service %s *******", service_instance.instance_name)
63 service_deletion = service_instance.delete()
64 status = None
65 while not (status == OrchestrationRequest.StatusEnum.COMPLETED
66            or status == OrchestrationRequest.StatusEnum.FAILED):
67     sleep(10)
68     status = service_deletion.status
69     logger.info(f"Orchestration status is: {status.value}")