Skip to content

Commit fbf558f

Browse files
authored
Merge pull request #141 from oracle-devrel/develop
v2025.1.0
2 parents fc080d6 + 93a62d8 commit fbf558f

File tree

90 files changed

+4916
-421
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+4916
-421
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ ARG USER_GID=$USER_UID
1616
# Whether to download Provider as part of image creation
1717
ARG DOWNLOAD_PROVIDER=YES
1818
# TF Provider version
19-
ARG TF_OCI_PROVIDER=6.15.0
20-
ARG TF_NULL_PROVIDER=3.2.1
19+
ARG TF_OCI_PROVIDER=6.30.0
20+
ARG TF_NULL_PROVIDER=3.2.3
2121

2222
RUN microdnf install -y sudo && \
2323
groupadd --gid $USER_GID $USERNAME && \

cd3_automation_toolkit/Compute/export_dedicatedvmhosts_nonGreenField.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,24 @@
1919
oci_obj_names = {}
2020

2121

22-
def print_dedicatedvmhosts(region, dedicatedvmhost, values_for_column, ntk_compartment_name,state):
22+
def print_dedicatedvmhosts(region, dedicatedvmhost, values_for_column, ntk_compartment_name,export_tags, state):
23+
24+
# Tags filter
25+
defined_tags = dedicatedvmhost.defined_tags
26+
tags_list = []
27+
for tkey, tval in defined_tags.items():
28+
for kk, vv in tval.items():
29+
tag = tkey + "." + kk + "=" + vv
30+
tags_list.append(tag)
31+
32+
if export_tags == []:
33+
check = True
34+
else:
35+
check = any(e in tags_list for e in export_tags)
36+
# None of Tags from export_tags exist on this instance; Dont export this instance
37+
if check == False:
38+
return
39+
2340
dedicatedvmhost_tf_name = commonTools.check_tf_variable(dedicatedvmhost.display_name)
2441
tf_resource = f'module.dedicated-hosts[\\"{dedicatedvmhost_tf_name}\\"].oci_core_dedicated_vm_host.dedicated_vm_host'
2542
if tf_resource not in state["resources"]:
@@ -47,7 +64,7 @@ def print_dedicatedvmhosts(region, dedicatedvmhost, values_for_column, ntk_compa
4764
values_for_column = commonTools.export_extra_columns(oci_objs, col_header, sheet_dict, values_for_column)
4865

4966
# Execution of the code begins here
50-
def export_dedicatedvmhosts(inputfile, outdir, service_dir, config, signer, ct, export_compartments=[], export_regions=[]):
67+
def export_dedicatedvmhosts(inputfile, outdir, service_dir, config, signer, ct, export_compartments=[], export_regions=[],export_tags=[]):
5168
global tf_import_cmd
5269
global sheet_dict
5370
global importCommands
@@ -102,11 +119,12 @@ def export_dedicatedvmhosts(inputfile, outdir, service_dir, config, signer, ct,
102119
compute_client = oci.core.ComputeClient(config=config,retry_strategy=oci.retry.DEFAULT_RETRY_STRATEGY, signer=signer)
103120

104121
for ntk_compartment_name in export_compartments:
122+
105123
dedicatedvmhosts = oci.pagination.list_call_get_all_results(compute_client.list_dedicated_vm_hosts,compartment_id=ct.ntk_compartment_ids[ntk_compartment_name], lifecycle_state="ACTIVE")
106124

107125
for dedicatedvmhost in dedicatedvmhosts.data:
108126
dedicatedvmhost=compute_client.get_dedicated_vm_host(dedicatedvmhost.id).data
109-
print_dedicatedvmhosts(region, dedicatedvmhost,values_for_column, ntk_compartment_name,state)
127+
print_dedicatedvmhosts(region, dedicatedvmhost,values_for_column, ntk_compartment_name,export_tags,state)
110128

111129
# writing data
112130
for reg in export_regions:

cd3_automation_toolkit/Compute/export_instances_nonGreenField.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ def adding_columns_values(region, ad, fd, vs, publicip, privateip, os_dname, sha
3333
values_for_column_instances[col_header].append(os_dname)
3434
elif (col_header == "Shape"):
3535
values_for_column_instances[col_header].append(shape)
36+
elif (col_header == "Boot Volume Size In GBs"):
37+
size = bdet.size_in_gbs
38+
if size < 50:
39+
size=""
40+
values_for_column_instances[col_header].append(size)
3641
elif (col_header == "SSH Key Var Name"):
3742
values_for_column_instances[col_header].append(key_name)
3843
elif (col_header == "Compartment Name"):
@@ -81,7 +86,7 @@ def find_vnic(ins_id, compartment_id):
8186
return net
8287

8388

84-
def __get_instances_info(compartment_name, compartment_id, reg_name, display_names, ad_names, ct,state):
89+
def __get_instances_info(compartment_name, compartment_id, reg_name, display_names, ad_names, export_tags, ct,state):
8590
config.__setitem__("region", ct.region_dict[reg_name])
8691
compute = oci.core.ComputeClient(config=config, retry_strategy=oci.retry.DEFAULT_RETRY_STRATEGY,signer=signer)
8792
network = oci.core.VirtualNetworkClient(config=config, retry_strategy=oci.retry.DEFAULT_RETRY_STRATEGY,signer=signer)
@@ -102,18 +107,34 @@ def __get_instances_info(compartment_name, compartment_id, reg_name, display_nam
102107
if (not any(e in AD_name for e in ad_names)):
103108
continue
104109

105-
# Continue to next one if display names donot match the filter
110+
# Continue to next one if display names do not match the filter
106111
if (display_names is not None):
107112
if (not any(e in ins_dname for e in display_names)):
108113
continue
109114

115+
# Tags filter
116+
ins_defined_tags = ins.defined_tags
117+
tags_list=[]
118+
for tkey,tval in ins_defined_tags.items():
119+
for kk,vv in tval.items():
120+
tag = tkey+"."+kk+"="+vv
121+
tags_list.append(tag)
122+
123+
if export_tags == []:
124+
check = True
125+
else:
126+
check = any(e in tags_list for e in export_tags)
127+
#None of Tags from export_tags exist on this instance; Dont export this instance
128+
if check == False:
129+
continue
130+
110131
# Continue to next one if it's an OKE instance
111132
if 'oke-' in ins_dname:
112133
ins_defined_tags = ins.defined_tags
113134
if 'Oracle-Tags' in ins_defined_tags.keys():
114135
if 'CreatedBy' in ins_defined_tags['Oracle-Tags'].keys():
115136
created_by = ins_defined_tags['Oracle-Tags']['CreatedBy']
116-
if created_by == 'oke':
137+
if ".nodepool." in created_by or created_by == 'oke':
117138
continue
118139

119140
ins_fd = ins.fault_domain # FD
@@ -279,7 +300,7 @@ def __get_instances_info(compartment_name, compartment_id, reg_name, display_nam
279300

280301

281302
# Execution of the code begins here
282-
def export_instances(inputfile, outdir, service_dir,config1, signer1, ct, export_compartments=[], export_regions=[],display_names=[],ad_names=[]):
303+
def export_instances(inputfile, outdir, service_dir,config1, signer1, ct, export_compartments=[], export_regions=[],export_tags=[],display_names=[],ad_names=[]):
283304
cd3file = inputfile
284305

285306
if ('.xls' not in cd3file):
@@ -330,7 +351,7 @@ def export_instances(inputfile, outdir, service_dir,config1, signer1, ct, export
330351
except Exception as e:
331352
pass
332353
for ntk_compartment_name in export_compartments:
333-
__get_instances_info(ntk_compartment_name, ct.ntk_compartment_ids[ntk_compartment_name], reg, display_names, ad_names,ct,state)
354+
__get_instances_info(ntk_compartment_name, ct.ntk_compartment_ids[ntk_compartment_name], reg, display_names, ad_names,export_tags,ct,state)
334355

335356
# writing image ocids and SSH keys into variables file
336357
var_data = {}

cd3_automation_toolkit/CostManagement/Budget/export_budgets_nonGreenField.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def print_budgets(values_for_columns, region, budget,budget_name,budget_alert_ru
104104

105105

106106
# Execution of the code begins here
107-
def export_budgets_nongreenfield(inputfile, outdir, service_dir, config, signer, ct,export_regions=[]):
107+
def export_budgets_nongreenfield(inputfile, outdir, service_dir, config, signer, ct,export_regions=[],export_tags=[]):
108108
global importCommands
109109
global values_for_column_budgets
110110
global sheet_dict_budgets,tf_or_tofu
@@ -155,6 +155,23 @@ def export_budgets_nongreenfield(inputfile, outdir, service_dir, config, signer,
155155
budgets_list = oci.pagination.list_call_get_all_results(budgets_client.list_budgets,compartment_id=tenancy_id,lifecycle_state="ACTIVE",target_type="ALL")
156156
if budgets_list.data != []:
157157
for budget in budgets_list.data:
158+
159+
# Tags filter
160+
defined_tags = budget.defined_tags
161+
tags_list = []
162+
for tkey, tval in defined_tags.items():
163+
for kk, vv in tval.items():
164+
tag = tkey + "." + kk + "=" + vv
165+
tags_list.append(tag)
166+
167+
if export_tags == []:
168+
check = True
169+
else:
170+
check = any(e in tags_list for e in export_tags)
171+
# None of Tags from export_tags exist on this instance; Dont export this instance
172+
if check == False:
173+
continue
174+
158175
budget_name = str(budget.display_name)
159176
budget_id = str(budget.id)
160177
budget_tf_name = commonTools.check_tf_variable(budget_name)

cd3_automation_toolkit/Database/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@
88
from .export_exa_vmclusters_nonGreenField import export_exa_vmclusters
99
from .export_exa_infra_nonGreenField import export_exa_infra
1010
from .export_adb_nonGreenField import export_adbs
11-
11+
from .create_terraform_mysql_db import create_terraform_mysql_db
12+
from .create_terraform_mysql_configuration import create_terraform_mysql_configuration
13+
from .export_mysql_db_nonGreenField import export_mysql_db
14+
from .export_mysql_configuration_nonGreenField import export_mysql_configuration, export_mysql_configurations
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
#!/usr/bin/python3
2+
# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
3+
#
4+
# This script will produce a Terraform file that will be used to set up OCI Database
5+
# MySQL Configuration
6+
#
7+
# Author: Generated by Cascade
8+
# Oracle Consulting
9+
#
10+
11+
import os
12+
import re
13+
from jinja2 import Environment, FileSystemLoader
14+
from oci.config import DEFAULT_LOCATION
15+
from pathlib import Path
16+
from commonTools import *
17+
18+
def create_terraform_mysql_configuration(inputfile, outdir, service_dir, prefix, ct):
19+
filename = inputfile
20+
sheetName = "MySQL-Configurations"
21+
auto_tfvars_filename = prefix + '_' + sheetName.lower() + '.auto.tfvars'
22+
23+
# Initialize tracking variables
24+
prev_values = {
25+
'region': '',
26+
'compartment_name': '',
27+
'display_name': '',
28+
'description': '',
29+
'shape_name': ''
30+
}
31+
32+
tfStr = {}
33+
mysql_config_vars = {}
34+
35+
# Load the template file
36+
file_loader = FileSystemLoader(f'{Path(__file__).parent}/templates')
37+
env = Environment(loader=file_loader, keep_trailing_newline=True, trim_blocks=True, lstrip_blocks=True)
38+
template = env.get_template('mysql-configuration-template')
39+
40+
# Add custom functions to template environment
41+
def make_config_keys(config):
42+
return lambda: config.keys()
43+
def make_config_value(config):
44+
return lambda key: config.get(key, '')
45+
env.globals['config_keys'] = None
46+
env.globals['config_value'] = None
47+
48+
# Read cd3 using pandas dataframe
49+
df, col_headers = commonTools.read_cd3(filename, sheetName)
50+
df = df.dropna(how='all')
51+
df = df.reset_index(drop=True)
52+
53+
# List of column headers
54+
dfcolumns = df.columns.values.tolist()
55+
56+
# Initialize empty TF string for each region
57+
for reg in ct.all_regions:
58+
tfStr[reg] = ''
59+
srcdir = outdir + "/" + reg + "/" + service_dir + "/"
60+
resource = sheetName.lower()
61+
commonTools.backup_file(srcdir, resource, auto_tfvars_filename)
62+
mysql_config_vars[reg] = {}
63+
64+
# Process each row
65+
for i in df.index:
66+
# Get values from row
67+
region = str(df.loc[i, 'Region']).strip()
68+
compartment_name = str(df.loc[i, 'Compartment Name']).strip()
69+
display_name = str(df.loc[i, 'Display Name']).strip()
70+
description = str(df.loc[i, 'Description']).strip()
71+
shape_name = str(df.loc[i, 'Shape Name']).strip()
72+
73+
# Handle empty values using previous values
74+
if region.lower() == 'nan' or region == '':
75+
region = prev_values['region']
76+
if compartment_name.lower() == 'nan' or compartment_name == '':
77+
compartment_name = prev_values['compartment_name']
78+
if display_name.lower() == 'nan' or display_name == '':
79+
display_name = prev_values['display_name']
80+
if description.lower() == 'nan' or description == '':
81+
description = prev_values['description']
82+
if shape_name.lower() == 'nan' or shape_name == '':
83+
shape_name = prev_values['shape_name']
84+
85+
# Update previous values
86+
prev_values.update({
87+
'region': region,
88+
'compartment_name': compartment_name,
89+
'display_name': display_name,
90+
'description': description,
91+
'shape_name': shape_name
92+
})
93+
94+
# Skip if essential values are missing
95+
if region.lower() == 'nan' or display_name.lower() == 'nan':
96+
continue
97+
98+
# Initialize region if needed
99+
region = region.strip().lower()
100+
if region not in ct.all_regions:
101+
print("\nERROR!!! Invalid Region; It should be one of the regions tenancy is subscribed to..Exiting!")
102+
exit(1)
103+
104+
# Check for variable row
105+
user_var_name = str(df.loc[i, 'users_variable_name']).strip()
106+
user_var_value = str(df.loc[i, 'users_variable_value']).strip()
107+
108+
# Initialize config if needed
109+
config_tf_name = commonTools.check_tf_variable(display_name)
110+
if config_tf_name not in mysql_config_vars[region]:
111+
mysql_config_vars[region][config_tf_name] = {
112+
'config_display_tf_name': config_tf_name,
113+
'compartment_tf_name': commonTools.check_tf_variable(compartment_name),
114+
'display_name': display_name,
115+
'description': description,
116+
'shape_name': shape_name
117+
}
118+
119+
# Only process variable if both name and value are present and not empty
120+
if (user_var_name.lower() != 'nan' and user_var_name != '' and
121+
user_var_value.lower() != 'nan' and user_var_value != ''):
122+
# Add variable with mysql_configuration_ prefix
123+
var_name = f"mysql_configuration_variables_{user_var_name}"
124+
# Handle boolean values
125+
if user_var_value.lower() in ['true', 'false']:
126+
mysql_config_vars[region][config_tf_name][var_name] = user_var_value.capitalize()
127+
else:
128+
mysql_config_vars[region][config_tf_name][var_name] = user_var_value
129+
130+
# Generate terraform configuration for each region
131+
for region in mysql_config_vars:
132+
if not mysql_config_vars[region]:
133+
continue
134+
135+
# Start with count = 0 to generate opening
136+
env.globals['count'] = 0
137+
tfStr[region] = template.render()
138+
139+
configs = list(mysql_config_vars[region].items())
140+
for i, (config_name, config) in enumerate(configs):
141+
# Update template functions for this config
142+
env.globals['config_keys'] = make_config_keys(config)
143+
env.globals['config_value'] = make_config_value(config)
144+
config['loop'] = {'last': i == len(configs) - 1}
145+
env.globals['count'] = 1
146+
147+
# Render configuration
148+
rendered_config = template.render(**config)
149+
tfStr[region] += rendered_config
150+
151+
# Add closing brace
152+
env.globals['count'] = 2
153+
tfStr[region] += template.render()
154+
155+
# Write files
156+
for region in tfStr:
157+
if tfStr[region] != '':
158+
srcdir = outdir + "/" + region + "/" + service_dir + "/"
159+
os.makedirs(srcdir, exist_ok=True)
160+
161+
outfile = srcdir + "/" + auto_tfvars_filename
162+
# Clean up the output
163+
tfStr[region] = tfStr[region].strip()
164+
# Fix any potential formatting issues
165+
tfStr[region] = re.sub(r'\s+mysql_configuration_variables_', '\n mysql_configuration_variables_', tfStr[region])
166+
tfStr[region] = re.sub(r'}\s*,\s*', '},\n', tfStr[region])
167+
tfStr[region] = re.sub(r'\n\s*\n\s*\n', '\n\n', tfStr[region])
168+
169+
with open(outfile, 'w') as f:
170+
f.write(tfStr[region])
171+
print(f"Created MySQL configuration for region {region} in {outfile}")

0 commit comments

Comments
 (0)