-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete.py
166 lines (134 loc) · 7.55 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# coding: utf-8
import sys, os, argparse, configparser, json
import oci, utils
from modules import *
### Read arguments ###
parser = argparse.ArgumentParser()
parser.add_argument("-p",
"--profile",
default="DEFAULT",
help="profile name in settings.ini file. Default: DEFAULT")
args = parser.parse_args()
profile = args.profile
### Load parameters from settings.ini file ###
basedir = os.path.dirname(os.path.abspath(__file__))
ini_file_path = os.path.join(basedir, 'settings.ini')
if not os.path.exists(ini_file_path):
#logger.error('設定ファイルがありません')
print("settings.ini file does not exist")
exit(-1)
inifile = configparser.SafeConfigParser()
inifile.read(ini_file_path, encoding='utf-8')
if not inifile.has_section(profile):
print('could not find profile {0} in settings.ini file'.format(profile))
exit(-1)
### Load profile from OCI CLI config file ###
oci_config_file = inifile.get(profile, 'oci_config_file', fallback='~/.oci/config')
oci_profile = inifile.get(profile, 'oci_profile', fallback='DEFAULT')
use_instance_principal = inifile.getboolean(profile, 'use_instance_principal', fallback=False)
target_compartment_ids = json.loads(inifile.get(profile, 'target_compartment_ids', fallback='[]'))
excluded_compartment_names = json.loads(inifile.get(profile, 'excluded_compartment_names', fallback='[]'))
target_region_names = json.loads(inifile.get(profile, 'target_region_names', fallback='[]'))
config = oci.config.from_file(oci_config_file, oci_profile)
signer = utils.oci.init_signer(config, use_instance_principal)
print ("\n===========================[ Login check ]=============================")
user = utils.oci.try_login(config, signer)
print("Logged in as: {} @ {}".format(user.description, config['region']))
print ("\n==========================[ Target regions ]===========================")
regions, home_region = utils.oci.list_target_regions(config, signer, target_region_names)
for region in regions: print(region.region_name)
print("Home region: {}".format(home_region))
print ("\n========================[ Target compartments ]========================")
compartments = utils.oci.list_target_compartments(config, signer, target_compartment_ids, excluded_compartment_names)
for compartment in compartments: print(compartment.name)
for region in regions:
print ("\n============[ {} ]================".format(region.region_name))
config["region"] = region.region_name
###Database###
database.purge_autonomous_dbs(config, signer, compartments)
database.purge_db_systems(config, signer, compartments)
database.purge_db_backups(config, signer, compartments)
###Load Balancer###
load_balancer.purge_load_balancers(config, signer, compartments)
###Compute & Compute Operation###
auto_scaling.purge_auto_scaling_configurations(config, signer, compartments)
compute_management.purge_instance_pools(config, signer, compartments)
compute_management.purge_instance_configurations(config, signer, compartments)
compute.purge_compute_instances(config, signer, compartments)
compute.purge_dedicated_vm_hosts(config, signer, compartments)
compute.purge_images(config, signer, compartments)
###Block Volume###
blockstorage.purge_volume_group_backups(config, signer, compartments)
blockstorage.purge_volume_groups(config, signer, compartments)
blockstorage.purge_volume_backup_policies(config, signer, compartments)
blockstorage.purge_volume_backups(config, signer, compartments)
blockstorage.purge_volumes(config, signer, compartments)
blockstorage.purge_boot_volume_backups(config, signer, compartments)
##blockstorage.purge_boot_volumes(config, signer, compartments) #AD Required
###File Storage###
file_storage.purge_exports(config, signer, compartments)
file_storage.purge_snapshots(config, signer, compartments)
file_storage.purge_file_systems(config, signer, compartments) #AD Required
file_storage.purge_mount_targets(config, signer, compartments) #AD Required
###Object Storage###
object_storage.purge_preauthenticated_requests(config, signer, compartments)
object_storage.purge_multipart_uploads(config, signer, compartments)
object_storage.purge_objects(config, signer, compartments)
object_storage.purge_buckets(config, signer, compartments)
###Virtual Network###
virtual_network.purge_subnets(config, signer, compartments)
virtual_network.clear_route_rules(config, signer, compartments)
virtual_network.purge_route_tables(config, signer, compartments)
virtual_network.purge_drg_attachments(config, signer, compartments)
virtual_network.purge_local_peering_gateways(config, signer, compartments)
virtual_network.purge_internet_gateways(config, signer, compartments)
virtual_network.purge_nat_gateways(config, signer, compartments)
virtual_network.purge_service_gateways(config, signer, compartments)
virtual_network.purge_network_security_groups(config, signer, compartments)
virtual_network.purge_security_lists(config, signer, compartments)
virtual_network.purge_dhcp_options(config, signer, compartments)
#virtual_network.purge_ipv6s(config, signer, compartments)
#virtual_network.purge_vlans(config, signer, compartments)
virtual_network.purge_vcns(config, signer, compartments)
virtual_network.purge_remote_peering_connections(config, signer, compartments)
virtual_network.purge_ip_sec_connections(config, signer, compartments)
#virtual_network.purge_cross_connects(config, signer, compartments)
#virtual_network.purge_cross_connect_groups(config, signer, compartments)
#virtual_network.purge_virtual_circuits(config, signer, compartments)
virtual_network.purge_drgs(config, signer, compartments)
virtual_network.purge_cpes(config, signer, compartments)
virtual_network.purge_public_ips(config, signer, compartments)
###Streaming###
streaming.purge_streams(config, signer, compartments)
streaming.purge_stream_pools(config, signer, compartments)
###Notification###
ons.purge_subscriptions(config, signer, compartments)
ons.purge_topics(config, signer, compartments)
###Logging###
logging.purge_log_groups(config, signer, compartments)
###Events###
events.purge_rules(config, signer, compartments)
###Healthcheck###
healthcheck.purge_http_monitors(config, signer, compartments, region.region_name)
healthcheck.purge_ping_monitors(config, signer, compartments, region.region_name)
###API Gateway###
api_gateway.purge_deployments(config, signer, compartments)
api_gateway.purge_gateways(config, signer, compartments)
###Resource Manager###
resource_manager.purge_configuration_source_providers(config, signer, compartments)
resource_manager.purge_stacks(config, signer, compartments)
#resource_manager.purge_templates(config, signer, compartments)
###Data Science###
data_science.purge_projects(config, signer, compartments)
if region.region_name == home_region:
###Web Application Firewall###
waas.purge_address_lists(config, signer, compartments)
waas.purge_certificates(config, signer, compartments)
waas.purge_custom_protection_rules(config, signer, compartments)
waas.purge_waas_policies(config, signer, compartments)
###DNS###
dns.purge_dns_zones(config, signer, compartments)
###IAM###
identity.purge_policies(config, signer, compartments)
identity.purge_compartments(config, signer, compartments)
print ("\n=====================[ Script Completed ]=====================")