Skip to content

Commit 943329b

Browse files
authored
Merge pull request #2 from oracle-devrel/feature
Automation Toolkit Release v9.2.1
2 parents c1d95fc + 405890e commit 943329b

File tree

424 files changed

+43976
-3
lines changed

Some content is hidden

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

424 files changed

+43976
-3
lines changed

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
.DS_Store
33
.AppleDouble
44
.LSOverride
5+
.terraform*
6+
.idea
7+
*.log
8+
tmp/
59

10+
__pycache__/
611
# Icon must end with two \r
712
Icon
813

@@ -30,4 +35,4 @@ Temporary Items
3035
.key
3136
.crt
3237
.csr
33-
.pem
38+
.pem

Dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
FROM oraclelinux:7-slim
2+
LABEL maintainer="Team at Oracle"
3+
LABEL description="OCI format to generate CD3 image"
4+
5+
ARG USERNAME=cd3user
6+
ARG USER_UID=1001
7+
ARG USER_GID=$USER_UID
8+
9+
10+
RUN yum install sudo -y && groupadd --gid $USER_GID $USERNAME \
11+
&& useradd --uid $USER_UID --gid $USER_GID -d /$USERNAME -m $USERNAME \
12+
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
13+
&& chmod 0440 /etc/sudoers.d/$USERNAME \
14+
&& mkdir /cd3user/tenancies/ && sudo chown -R $USERNAME:$USERNAME /cd3user/tenancies/
15+
16+
17+
USER $USERNAME
18+
WORKDIR /cd3user/oci_tools/
19+
COPY . .
20+
21+
RUN sudo yum install -y oracle-softwarecollection-release-el7 \
22+
&& sudo chown -R $USER:$USER /cd3user/ \
23+
&& sudo chmod -R 777 /cd3user/
24+
25+
26+
WORKDIR /cd3user/
27+
RUN sed -i -e 's/\r$//' /cd3user/oci_tools/cd3_automation_toolkit/shell_script.sh \
28+
&& /cd3user/oci_tools/cd3_automation_toolkit/shell_script.sh \
29+
&& sudo chown -R cd3user:cd3user /cd3user/ && sudo yum clean all && sudo rm -rf /var/cache/yum /root/ocswork \
30+
&& sudo rm -rf /cd3user/oci_tools/Dockerfile && sudo rm -rf /cd3user/oci_tools/Readme.md \
31+
&& sudo rm -rf /cd3user/oci_tools/.git && sudo rm -rf /cd3user/oci_tools/.gitignore
32+
33+
34+
CMD ["bash"]

README.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,36 @@
55
## THIS IS A NEW, BLANK REPO THAT IS NOT READY FOR USE YET. PLEASE CHECK BACK SOON!
66

77
## Introduction
8-
MISSING
8+
The CD3 Automation toolkit has been developed to help in automating the OCI resource object management.
9+
<br>
10+
It reads input data in the form of CD3 Excel sheets and generates the terraform files instead of handling the task through the OCI console manually. This simplifies the management of the company's infrastructure as code.
11+
<br>
12+
<img width="434" alt="image" src="https://user-images.githubusercontent.com/103475219/199982639-3b78c9cc-1b30-4a78-bafb-75ceb05309c0.png">
13+
<br><br>
914

1015
## Getting Started
11-
MISSING
16+
17+
### To build an image
18+
19+
* Change directory to cd3-automation-toolkit(i.e. cloned repo).
20+
* Run docker build -t cd3toolkit:${image_tag} -f Dockerfile --pull --no-cache .
21+
<br><br>
22+
### To save the image (Optional)
23+
24+
* Run docker save cd3toolkit:${image_tag} | gzip > cd3toolkit_${image_tag}.tar.gz
25+
<br><br>
26+
### To run the CD3 container and exec into it
27+
* Run docker run -it -d -v <path_in_local_system_where_the_files_must_be_generated>:/cd3user/tenancies <image_name>:<image_tag>
28+
* Run docker ps
29+
* Run docker exec -it <container_id> bash
30+
<br><br>
31+
Follow the toolkit docs i.e. from section "Configuring the Docker Container to connect to OCI Tenancy" of "01 CD3 Automation Tookit - End to End Process" inside cd3_automation_toolkit/documentation/user_guide to know HOW TO use to toolkit further.
32+
<br><br>
33+
https://github.com/oracle-devrel/cd3-automation-toolkit/blob/develop/cd3_automation_toolkit/documentation/user_guide/01%20CD3%20Automation%20Toolkit%20-%20End%20to%20End%20Process.pdf
34+
<br><br>
35+
Note : ${image_tag} should be replaced with suitable tag as per your requirements/standards.
36+
37+
The above steps have been tested on Windows (Git Bash) and MacOS.
1238

1339
### Prerequisites
1440
MISSING
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env python3
2+
3+
from .create_terraform_instances import create_terraform_instances
4+
from .create_terraform_dedicatedhosts import create_terraform_dedicatedhosts
5+
from .export_instances_nonGreenField import export_instances
6+
from .export_dedicatedvmhosts_nonGreenField import export_dedicatedvmhosts
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
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 core components
5+
# Dedicated Hosts
6+
#
7+
# Author: Suruchi Singla
8+
# Oracle Consulting
9+
# Modified (TF Upgrade): Shruthi Subramanian
10+
#
11+
12+
import sys
13+
import argparse
14+
import os
15+
from oci.config import DEFAULT_LOCATION
16+
from pathlib import Path
17+
18+
sys.path.append(os.getcwd() + "/../..")
19+
from commonTools import *
20+
from jinja2 import Environment, FileSystemLoader
21+
22+
23+
######
24+
# Required Inputs-CD3 excel file, Config file, prefix AND outdir
25+
######
26+
def parse_args():
27+
# Read input arguments
28+
parser = argparse.ArgumentParser(description='Create Dedicated VM Hosts terraform file')
29+
parser.add_argument('inputfile', help='Full Path of input CD3 excel file')
30+
parser.add_argument('outdir', help='Output directory for creation of TF files')
31+
parser.add_argument('prefix', help='TF files prefix')
32+
parser.add_argument('--config', default=DEFAULT_LOCATION, help='Config file name')
33+
return parser.parse_args()
34+
35+
36+
# If input is CD3 excel file
37+
def create_terraform_dedicatedhosts(inputfile, outdir, prefix, config):
38+
# Load the template file
39+
file_loader = FileSystemLoader(f'{Path(__file__).parent}/templates')
40+
env = Environment(loader=file_loader, keep_trailing_newline=True, trim_blocks=True, lstrip_blocks=True)
41+
template = env.get_template('dedicatedvmhosts-template')
42+
43+
filename = inputfile
44+
configFileName = config
45+
46+
sheetName = "DedicatedVMHosts"
47+
auto_tfvars_filename = prefix + '_' + sheetName.lower() + '.auto.tfvars'
48+
ct = commonTools()
49+
ct.get_subscribedregions(configFileName)
50+
51+
outfile = {}
52+
oname = {}
53+
tfStr = {}
54+
ADS = ["AD1", "AD2", "AD3"]
55+
56+
# Read cd3 using pandas dataframe
57+
df, col_headers = commonTools.read_cd3(filename, sheetName)
58+
59+
df = df.dropna(how='all')
60+
df = df.reset_index(drop=True)
61+
62+
# Take backup of files
63+
for eachregion in ct.all_regions:
64+
resource = sheetName.lower()
65+
srcdir = outdir + "/" + eachregion + "/"
66+
commonTools.backup_file(srcdir, resource, auto_tfvars_filename)
67+
tfStr[eachregion] = ''
68+
69+
# List of column headers
70+
dfcolumns = df.columns.values.tolist()
71+
72+
for i in df.index:
73+
region = str(df.loc[i, 'Region'])
74+
75+
if (region in commonTools.endNames):
76+
break
77+
78+
region = region.strip().lower()
79+
if region not in ct.all_regions:
80+
print("\nERROR!!! Invalid Region; It should be one of the regions tenancy is subscribed to..Exiting!")
81+
exit(1)
82+
83+
# temporary dictionary1 and dictionary2
84+
tempStr = {}
85+
tempdict = {}
86+
87+
# Check if values are entered for mandatory fields
88+
if (str(df.loc[i, 'Region']).lower() == 'nan' or str(df.loc[i, 'Shape']).lower() == 'nan' or str(
89+
df.loc[i, 'Compartment Name']).lower() == 'nan' or str(
90+
df.loc[i, 'Availability Domain(AD1|AD2|AD3)']).lower() == 'nan' or str(
91+
df.loc[i, 'Display Name']).lower() == 'nan'):
92+
print("\nAll Fields are mandatory except Fault Domain. Exiting...")
93+
exit(1)
94+
95+
for columnname in dfcolumns:
96+
97+
# Column value
98+
columnvalue = str(df[columnname][i]).strip()
99+
100+
# Check for boolean/null in column values
101+
columnvalue = commonTools.check_columnvalue(columnvalue)
102+
103+
# Check for multivalued columns
104+
tempdict = commonTools.check_multivalues_columnvalue(columnvalue, columnname, tempdict)
105+
106+
# Process Defined and Freeform Tags
107+
if columnname.lower() in commonTools.tagColumns:
108+
tempdict = commonTools.split_tag_values(columnname, columnvalue, tempdict)
109+
110+
if columnname == 'Display Name':
111+
columnvalue = columnvalue.strip()
112+
host_tf_name = commonTools.check_tf_variable(columnvalue)
113+
tempdict = {'dedicated_vm_host_tf': host_tf_name, 'dedicated_vm_host': columnvalue}
114+
115+
if columnname == 'Compartment Name':
116+
compartment_var_name = columnvalue.strip()
117+
compartment_var_name = commonTools.check_tf_variable(compartment_var_name)
118+
tempdict = {'compartment_tf_name': compartment_var_name}
119+
120+
if columnname == 'Availability Domain(AD1|AD2|AD3)':
121+
columnname = 'availability_domain'
122+
AD = columnvalue.upper()
123+
ad = ADS.index(AD)
124+
columnvalue = str(ad)
125+
tempdict = {'availability_domain': columnvalue}
126+
127+
columnname = commonTools.check_column_headers(columnname)
128+
tempStr[columnname] = str(columnvalue).strip()
129+
tempStr.update(tempdict)
130+
131+
# Write all info to TF string; Render template
132+
tfStr[region] = tfStr[region] + template.render(tempStr) + "\n"
133+
134+
# Write to output
135+
for reg in ct.all_regions:
136+
reg_out_dir = outdir + "/" + reg
137+
if not os.path.exists(reg_out_dir):
138+
os.makedirs(reg_out_dir)
139+
140+
if (tfStr[reg] != ''):
141+
src = "##Add New Dedicated VM Host for " + reg.lower() + " here##"
142+
tfStr[reg] = template.render(count=0, region=reg).replace(src, tfStr[reg] + "\n" + src)
143+
tfStr[reg] = "".join([s for s in tfStr[reg].strip().splitlines(True) if s.strip("\r\n").strip()])
144+
145+
resource = sheetName.lower()
146+
commonTools.backup_file(reg_out_dir + "/", resource, auto_tfvars_filename)
147+
148+
# Write to TF file
149+
outfile = reg_out_dir + "/" + auto_tfvars_filename
150+
tfStr[reg] = "".join([s for s in tfStr[reg].strip().splitlines(True) if s.strip("\r\n").strip()])
151+
oname = open(outfile, "w+")
152+
print(outfile + " for dedicated vm hosts has been created for region " + reg)
153+
oname.write(tfStr[reg])
154+
oname.close()
155+
156+
157+
158+
if __name__ == '__main__':
159+
args = parse_args()
160+
# Execution of the code begins here
161+
create_terraform_dedicatedhosts(args.inputfile, args.outdir, args.prefix, args.config)

0 commit comments

Comments
 (0)