Automation scripts for 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
20 from onapsdk.aai.business import Customer
21
22 from config import Config
23
24 logger = logging.getLogger("")
25 logger.setLevel(logging.DEBUG)
26 fh = logging.StreamHandler()
27 fh_formatter = logging.Formatter('%(asctime)s %(levelname)s %(lineno)d:%(filename)s(%(process)d) - %(message)s')
28 fh.setFormatter(fh_formatter)
29 logger.addHandler(fh)
30
31 logger.info("******** Get Customer *******")
32 customer = None
33 try:
34     customer = Customer.get_by_global_customer_id(Config.GLOBAL_CUSTOMER_ID)
35 except:
36     logger.error("Customer not found")
37     exit(1)
38
39 logger.info("******** Check Service Subscription *******")
40 service_subscription = None
41 for service_sub in customer.service_subscriptions:
42     if service_sub.service_type == Config.SERVICENAME:
43         logger.info("Service %s subscribed", Config.SERVICENAME)
44         service_subscription = service_sub
45         break
46 if not service_subscription:
47     logger.error("Service Subscription not found")
48     exit(1)
49
50 logger.info("******** Get Service Instance details *******")
51 service_instance = None
52 for service in service_subscription.service_instances:
53     if service.instance_name == Config.SERVICE_INSTANCE_NAME:
54         service_instance = service
55         break
56 if not service_instance:
57     logger.error("Service Instance not found")
58     exit(1)
59
60 logger.info("******** Delete Service %s *******", service_instance.instance_name)
61 service_deletion = service_instance.delete()