Skip to content

Commit 1cadb4e

Browse files
authored
Merge pull request #38 from oracle-devrel/develop
Develop to main for v10.1
2 parents 4bf675b + 1165708 commit 1cadb4e

File tree

182 files changed

+5954
-2953
lines changed

Some content is hidden

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

182 files changed

+5954
-2953
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@
1818
8. [Creating independent tfstate files for each resource](/cd3_automation_toolkit/documentation/user_guide/RestructuringOutDirectory.md)
1919
9. [Expected Behaviour Of Automation Toolkit](/cd3_automation_toolkit/documentation/user_guide/KnownBehaviour.md)
2020
10. [FAQs](/cd3_automation_toolkit/documentation/user_guide/FAQ.md)
21-
11. Learn More...
21+
11. [Steps to Upgrade Your Toolkit](/cd3_automation_toolkit/documentation/user_guide/Upgrade_Toolkit.md)
22+
12. Learn More...
2223
- CD3 Excel Information
2324
- [Excel Templates](/cd3_automation_toolkit/documentation/user_guide/RunningAutomationToolkit.md#excel-sheet-templates)
2425
- [Toolkit Supported OCI Services](/cd3_automation_toolkit/documentation/user_guide/learn_more/CD3ExcelTabs.md)
2526
- [CD3 Validator Features](/cd3_automation_toolkit/documentation/user_guide/learn_more/SupportForCD3Validator.md)
2627
- [Additional CIS Compliance Features](/cd3_automation_toolkit/documentation/user_guide/learn_more/CISFeatures.md)
2728
- [OCI Resource Manager Upload](/cd3_automation_toolkit/documentation/user_guide/learn_more/ResourceManagerUpload.md)
2829
- [Support for Additional Attributes](/cd3_automation_toolkit/documentation/user_guide/learn_more/SupportforAdditionalAttributes.md)
29-
12. [Automation Toolkit Learning Videos](/cd3_automation_toolkit/documentation/user_guide/LearningVideos.md)
30+
13. [Automation Toolkit Learning Videos](/cd3_automation_toolkit/documentation/user_guide/LearningVideos.md)
3031

3132
## Introduction
3233
CD3 stands for <b>C</b>loud <b>D</b>eployment <b>D</b>esign <b>D</b>eliverable.
@@ -39,7 +40,7 @@ It reads input data in the form of CD3 Excel sheet and generates the terraform f
3940
</kbd>
4041
<br>
4142

42-
#### OCI Services Currently Supported by CD3
43+
#### OCI Services Currently Supported by Automation Toolkit
4344

4445
| OCI Services | Details |
4546
| --------- | ----------- |
@@ -62,7 +63,7 @@ It reads input data in the form of CD3 Excel sheet and generates the terraform f
6263
Appropriate IAM policies must be in place for each of the resources that the user may try to create.
6364
Minimum requirement for the user to get started is to have the ability to read to the tenancy.
6465

65-
[Click here](/cd3_automation_toolkit/documentation/user_guide/Launch_Docker_container.md) to get started and manage your OCI Infra!!!
66+
[Click here](/cd3_automation_toolkit/documentation/user_guide/Launch_Docker_container.md) to get started and manage your OCI Infra!
6667

6768
## Contributing
6869
This project is open source. Please submit your contributions by raising an <b>Issue</b> or through <b>Discussion topic</b> in this repository. Currently, we do not accept any pull requests. Oracle appreciates any contributions that are made by the open source community.

cd3_automation_toolkit/Compute/create_terraform_dedicatedhosts.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ def parse_args():
2828
parser = argparse.ArgumentParser(description='Create Dedicated VM Hosts terraform file')
2929
parser.add_argument('inputfile', help='Full Path of input CD3 excel file')
3030
parser.add_argument('outdir', help='Output directory for creation of TF files')
31+
parser.add_argument("service_dir",help="subdirectory under region directory in case of separate out directory structure")
3132
parser.add_argument('prefix', help='TF files prefix')
3233
parser.add_argument('--config', default=DEFAULT_LOCATION, help='Config file name')
3334
return parser.parse_args()
3435

3536

3637
# If input is CD3 excel file
37-
def create_terraform_dedicatedhosts(inputfile, outdir, prefix, config):
38+
def create_terraform_dedicatedhosts(inputfile, outdir, service_dir,prefix, config):
3839
# Load the template file
3940
file_loader = FileSystemLoader(f'{Path(__file__).parent}/templates')
4041
env = Environment(loader=file_loader, keep_trailing_newline=True, trim_blocks=True, lstrip_blocks=True)
@@ -62,7 +63,7 @@ def create_terraform_dedicatedhosts(inputfile, outdir, prefix, config):
6263
# Take backup of files
6364
for eachregion in ct.all_regions:
6465
resource = sheetName.lower()
65-
srcdir = outdir + "/" + eachregion + "/"
66+
srcdir = outdir + "/" + eachregion + "/" + service_dir + "/"
6667
commonTools.backup_file(srcdir, resource, auto_tfvars_filename)
6768
tfStr[eachregion] = ''
6869

@@ -133,7 +134,7 @@ def create_terraform_dedicatedhosts(inputfile, outdir, prefix, config):
133134

134135
# Write to output
135136
for reg in ct.all_regions:
136-
reg_out_dir = outdir + "/" + reg
137+
reg_out_dir = outdir + "/" + reg + "/" + service_dir
137138
if not os.path.exists(reg_out_dir):
138139
os.makedirs(reg_out_dir)
139140

@@ -158,4 +159,4 @@ def create_terraform_dedicatedhosts(inputfile, outdir, prefix, config):
158159
if __name__ == '__main__':
159160
args = parse_args()
160161
# Execution of the code begins here
161-
create_terraform_dedicatedhosts(args.inputfile, args.outdir, args.prefix, args.config)
162+
create_terraform_dedicatedhosts(args.inputfile, args.outdir, args.service_dir,args.prefix, args.config)

cd3_automation_toolkit/Compute/create_terraform_instances.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ def parse_args():
2424
parser = argparse.ArgumentParser(description='Creates Instances TF file')
2525
parser.add_argument('inputfile', help='Full Path of input CD3 excel file')
2626
parser.add_argument('outdir', help='Output directory for creation of TF files')
27+
parser.add_argument("service_dir",help="subdirectory under region directory in case of separate out directory structure")
2728
parser.add_argument('prefix', help='TF files prefix')
2829
parser.add_argument('--config', default=DEFAULT_LOCATION, help='Config file name')
2930
return parser.parse_args()
3031

3132

3233
# If input is CD3 excel file
33-
def create_terraform_instances(inputfile, outdir, prefix, config):
34+
def create_terraform_instances(inputfile, outdir, service_dir,prefix, config):
3435
boot_policy_tfStr = {}
3536
tfStr = {}
3637
ADS = ["AD1", "AD2", "AD3"]
@@ -59,7 +60,7 @@ def create_terraform_instances(inputfile, outdir, prefix, config):
5960
# Take backup of files
6061
for eachregion in ct.all_regions:
6162
resource = sheetName.lower()
62-
srcdir = outdir + "/" + eachregion + "/"
63+
srcdir = outdir + "/" + eachregion+ "/" + service_dir + "/"
6364
commonTools.backup_file(srcdir, resource, auto_tfvars_filename)
6465
tfStr[eachregion] = ''
6566
boot_policy_tfStr[eachregion] = ''
@@ -106,7 +107,7 @@ def create_terraform_instances(inputfile, outdir, prefix, config):
106107
df.loc[i, 'Availability Domain(AD1|AD2|AD3)']).lower() == 'nan' or str(
107108
df.loc[i, 'Subnet Name']).lower() == 'nan' or str(df.loc[i, 'Source Details']).lower() == 'nan'):
108109
print(
109-
"\nColumn Region, Shape, Compartment Name, Availability Domain, Display Name, Pub Address, Source Details and Subnet Name cannot be left empty in Instances sheet of CD3..exiting...")
110+
"\nOne/All of the Column/Columns from Region, Shape, Compartment Name, Availability Domain, Display Name, Pub Address, Source Details and Subnet Name is empty in Instances sheet of CD3..exiting...Please check.")
110111
exit(1)
111112

112113
for columnname in dfcolumns:
@@ -214,7 +215,7 @@ def create_terraform_instances(inputfile, outdir, prefix, config):
214215
# Write TF string to the file in respective region directory
215216
for reg in ct.all_regions:
216217

217-
reg_out_dir = outdir + "/" + reg
218+
reg_out_dir = outdir + "/" + reg + "/" + service_dir
218219
if not os.path.exists(reg_out_dir):
219220
os.makedirs(reg_out_dir)
220221

cd3_automation_toolkit/Compute/export_dedicatedvmhosts_nonGreenField.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#
1010

1111
import argparse
12-
import sys
1312
import oci
1413
import os
1514

@@ -51,12 +50,15 @@ def parse_args():
5150
parser = argparse.ArgumentParser(description="Export Block Volumes on OCI to CD3")
5251
parser.add_argument("inputfile", help="path of CD3 excel file to export Block Volume objects to")
5352
parser.add_argument("outdir", help="path to out directory containing script for TF import commands")
53+
parser.add_argument("service_dir",help="subdirectory under region directory in case of separate out directory structure")
5454
parser.add_argument("--config", default=DEFAULT_LOCATION, help="Config file name")
55-
parser.add_argument("--network-compartments", nargs='*', required=False, help="comma seperated Compartments for which to export Block Volume Objects")
55+
parser.add_argument("--export-compartments", nargs='*', required=False, help="comma seperated Compartments for which to export Block Volume Objects")
56+
parser.add_argument("--export-regions", nargs='*', help="comma seperated Regions for which to export Networking Objects",
57+
required=False)
5658
return parser.parse_args()
5759

5860

59-
def export_dedicatedvmhosts(inputfile, _outdir, _config, network_compartments=[]):
61+
def export_dedicatedvmhosts(inputfile, _outdir, service_dir, _config, ct, export_compartments=[], export_regions=[]):
6062
global tf_import_cmd
6163
global sheet_dict
6264
global importCommands
@@ -78,30 +80,27 @@ def export_dedicatedvmhosts(inputfile, _outdir, _config, network_compartments=[]
7880
config = oci.config.from_file(file_location=configFileName)
7981

8082
sheetName="DedicatedVMHosts"
81-
ct = commonTools()
82-
ct.get_subscribedregions(configFileName)
83-
ct.get_network_compartment_ids(config['tenancy'],"root",configFileName)
83+
if ct==None:
84+
ct = commonTools()
85+
ct.get_subscribedregions(configFileName)
86+
ct.get_network_compartment_ids(config['tenancy'],"root",configFileName)
8487

8588
# Read CD3
8689
df, values_for_column= commonTools.read_cd3(cd3file,sheetName)
8790

8891
# Get dict for columns from Excel_Columns
8992
sheet_dict=ct.sheet_dict[sheetName]
9093

91-
# Check Compartments
92-
global comp_list_fetch
93-
comp_list_fetch = commonTools.get_comp_list_for_export(network_compartments, ct.ntk_compartment_ids)
94-
9594
print("\nCD3 excel file should not be opened during export process!!!")
9695
print("Tabs- DedicatedVMHosts will be overwritten during export process!!!\n")
9796

9897
# Create backups
9998
resource = 'tf_import_' + sheetName.lower()
10099
file_name = 'tf_import_commands_' + sheetName.lower() + '_nonGF.sh'
101-
for reg in ct.all_regions:
102-
script_file = f'{outdir}/{reg}/'+file_name
100+
for reg in export_regions:
101+
script_file = f'{outdir}/{reg}/{service_dir}/'+file_name
103102
if (os.path.exists(script_file)):
104-
commonTools.backup_file(outdir + "/" + reg, resource, file_name)
103+
commonTools.backup_file(outdir + "/" + reg+"/"+service_dir, resource, file_name)
105104
importCommands[reg] = open(script_file, "w")
106105
importCommands[reg].write("#!/bin/bash")
107106
importCommands[reg].write("\n")
@@ -110,14 +109,14 @@ def export_dedicatedvmhosts(inputfile, _outdir, _config, network_compartments=[]
110109
# Fetch Block Volume Details
111110
print("\nFetching details of Dedicated VM Hosts...")
112111

113-
for reg in ct.all_regions:
112+
for reg in export_regions:
114113
importCommands[reg].write("\n\n######### Writing import for Dedicated VM Hosts #########\n\n")
115114
config.__setitem__("region", ct.region_dict[reg])
116115
region = reg.capitalize()
117116

118117
compute_client = oci.core.ComputeClient(config,retry_strategy=oci.retry.DEFAULT_RETRY_STRATEGY)
119118

120-
for ntk_compartment_name in comp_list_fetch:
119+
for ntk_compartment_name in export_compartments:
121120
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")
122121
for dedicatedvmhost in dedicatedvmhosts.data:
123122
dedicatedvmhost=compute_client.get_dedicated_vm_host(dedicatedvmhost.id).data
@@ -131,4 +130,4 @@ def export_dedicatedvmhosts(inputfile, _outdir, _config, network_compartments=[]
131130
if __name__ == '__main__':
132131
args = parse_args()
133132
# Execution of the code begins here
134-
export_dedicatedvmhosts(args.inputfile, args.outdir, args.config, args.network_compartments)
133+
export_dedicatedvmhosts(args.inputfile, args.outdir, args.service_dir,args.config, args.export_compartments, args.export_regions)

0 commit comments

Comments
 (0)