forked from AnykeyNL/OCI-SuperDelete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete.py
113 lines (82 loc) · 3.95 KB
/
delete.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#Use with PYTHON3!
import oci
from ocimodules.functions import *
from ocimodules.EdgeServices import *
from ocimodules.ObjectStorage import *
from ocimodules.Instances import *
from ocimodules.Database import *
from ocimodules.IAM import *
from ocimodules.VCN import *
from ocimodules.BlockStorage import *
from ocimodules.ResourceManager import *
from ocimodules.FileStorage import *
from ocimodules.Monitoring import *
from ocimodules.Notifications import *
from ocimodules.Autoscaling import *
from ocimodules.FunctionsService import *
########## Configuration ####################
# Specify your config file
configfile = "~/.oci/config"
# Specify the compartment OCID that you want to delete
DeleteCompartmentOCID = "ocid1.compartment.oc1..aaaaaaaa456vlgfybg2obpz7hrwjrqcyzme5mtgtqcetgt4tl2bs3kubmmea"
# Search for resources in regions:
regions = ["eu-frankfurt-1", "uk-london-1"]
# Specify your home region
homeregion = "eu-frankfurt-1"
#############################################
config = oci.config.from_file(configfile)
print ("\n--[ Login check and getting all compartments from starting compartment ]--")
compartments = Login(config, DeleteCompartmentOCID)
processCompartments=[]
clear()
print ("\n--[ Compartments to process ]--")
# Add all active compartments, but exclude the ManagementCompartmentForPaas (as this is locked compartment)
for compartment in compartments:
if compartment.lifecycle_state== "ACTIVE" and compartment.name != "ManagedCompartmentForPaaS":
processCompartments.append(compartment)
print (compartment.name)
confirm = input ("\ntype yes to delete all contents from these compartments: ")
if confirm == "yes":
for region in regions:
print ("============[ Deleting resources in {} ]================".format(region))
config["region"] = region
print ("\n--[ Deleting Edge Services ]--")
DeleteWAFs(config,processCompartments)
DeleteHTTPHealthchecks(config, processCompartments)
DeletePINGHealthchecks(config, processCompartments)
DeleteTrafficSteerings(config, processCompartments)
DeleteZones(config, processCompartments)
print ("\n--[ Deleting Object Storage ]--")
DeleteBuckets(config, processCompartments)
print ("\n--[ Deleting Auto Scaling Configurations ]--")
DeleteAutoScalingConfigurations(config, processCompartments)
print ("\n--[ Deleting Compute Instances ]--")
DeleteInstancePools(config,processCompartments)
DeleteInstanceConfigs(config, processCompartments)
DeleteInstances(config,processCompartments)
DeleteImages(config, processCompartments)
DeleteBootVolumes(config, processCompartments)
DeleteDedicatedVMHosts(config, processCompartments)
print("\n--[ Deleting Application Functions ]--")
DeleteApplications(config, processCompartments)
print ("\n--[ Deleting Database Instances ]--")
DeleteDBCS(config,processCompartments)
DeleteAutonomousDB(config,processCompartments)
DeleteDBBackups(config, processCompartments)
print ("\n--[ Deleting Resource Manager Stacks ]--")
DeleteStacks(config, processCompartments)
print ("\n--[ Deleting Block Volumes ]--")
DeleteVolumes(config, processCompartments)
DeleteBlockVolumesBackups(config, processCompartments)
print ("\n--[ Deleting FileSystem and Mount Targets ]--")
DeleteMountTargets(config, processCompartments)
DeleteFileStorage(config, processCompartments)
print ("\n--[ Deleting VCNs ]--")
DeleteVCN(config, processCompartments)
print ("\n--[ Deleting Alarms ]--")
DeleteAlarms(config, processCompartments)
print ("\n--[ Deleting Notifications ]--")
DeleteNotifications(config, processCompartments)
print ("\n--[ Hopefully deleting compartments, if empty ]--")
config["region"] = homeregion
DeleteCompartments(config,processCompartments, DeleteCompartmentOCID)