Skip to content

Commit c74c9a1

Browse files
committed
First drop of quick and dirty conversion tool from old db_home management to the new.
Creates 3 separate filesi (while keeping the original file intact): - <original-filename>_dbhome.yml - <original-filename>_databases.yml - <original-filename>_pdbs.yml They are configured the way the new configuration should look like. NOTE: There is no errorchecking or validation done by this tool. It is merely there to give you an idea of how you convert the old config to the new one.
1 parent f3167f5 commit c74c9a1

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

dbhome-conversion/convert.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import os,yaml,io
2+
from jinja2 import Environment, FileSystemLoader
3+
4+
target_home = 'dbhome.yml'
5+
target_db = 'databases.yml'
6+
target_pdb = 'pdbs.yml'
7+
template_home = 'dbhome-template.j2'
8+
template_db = 'db-template.j2'
9+
template_pdb = 'pdb-template.j2'
10+
base_dir = './group_vars'
11+
12+
file_list_all = []
13+
for root, _, filenames in os.walk(base_dir):
14+
for filename in filenames:
15+
file_list_all.append(os.path.join(root, filename))
16+
17+
18+
env = Environment(loader = FileSystemLoader('./'), trim_blocks=True, lstrip_blocks=True)
19+
template_home = env.get_template(template_home)
20+
template_db = env.get_template(template_db)
21+
template_pdb = env.get_template(template_pdb)
22+
23+
for a in file_list_all:
24+
25+
if 'oracle_databases' in open(a).read():
26+
print "Processing: %s " % (a)
27+
with open(a, 'r') as sourcefile:
28+
config_data = yaml.load(sourcefile)
29+
30+
a_strip = os.path.splitext(a)[0]
31+
32+
targetfile_home = a_strip + '_' + target_home
33+
with open(targetfile_home , 'w') as outfile_home:
34+
print "\tWriting dbhome config to %s " % (targetfile_home)
35+
# print(template.render(config_data))
36+
outfile_home.write(template_home.render(config_data))
37+
38+
targetfile_db = a_strip + '_' + target_db
39+
with open(targetfile_db , 'w') as outfile_db:
40+
print "\tWriting new db config to %s " % (targetfile_db)
41+
# print(template.render(config_data))
42+
outfile_db.write(template_db.render(config_data))
43+
44+
45+
targetfile_pdb = a_strip + '_' + target_pdb
46+
with open(targetfile_pdb , 'w') as outfile_pdb:
47+
print "\tWriting new pdb config to %s " % (targetfile_pdb)
48+
print ''
49+
# print(template.render(config_data))
50+
outfile_pdb.write(template_pdb.render(config_data))
51+

dbhome-conversion/db-template.j2

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
oracle_databases:
2+
{% for a in oracle_databases %}
3+
- home: {{ a.home }}-{{ a.oracle_version_db }}
4+
oracle_db_name: {{ a.oracle_db_name}}
5+
oracle_db_type: {{ a.oracle_db_type }}
6+
is_container: {{ a.is_container }}
7+
storage_type: {{ a.storage_type }}
8+
{% if a.oracle_db_mem_totalmb is defined %}
9+
oracle_db_mem_totalmb: {{ a.oracle_db_mem_totalmb }}
10+
{% endif %}
11+
{% if a.oracle_db_mem_percent is defined %}
12+
oracle_db_mem_percent: {{ a.oracle_db_mem_percent }}
13+
{% endif %}
14+
oracle_database_type: {{ a.oracle_database_type }}
15+
redolog_size: {{ a.redolog_size_in_mb}}M
16+
{% if a.redolog_groups is defined %}
17+
redolog_groups: {{ a.redolog_groups}}
18+
{% endif %}
19+
{% if a.datafile_dest is defined %}
20+
datafile_dest: {{ a.datafile_dest }}
21+
{% endif %}
22+
{% if a.recoveryfile_dest is defined %}
23+
recoveryfile_dest: {{ a.recoveryfile_dest }}
24+
{% endif %}
25+
{% if a.archivelog is defined %}
26+
archivelog: {{ a.archivelog }}
27+
{% endif %}
28+
{% if a.flashback is defined %}
29+
flashback: {{ a.flashback }}
30+
{% endif %}
31+
{% if a.force_logging is defined %}
32+
force_logging: {{ a.force_logging }}
33+
{% endif %}
34+
state: {{ a.state }}
35+
{% endfor %}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
apply_patches_db: False
3+
4+
db_homes_config:
5+
{% for a in oracle_databases %}
6+
{{ a.home }}-{{ a.oracle_version_db }}:
7+
home: {{ a.home}}
8+
{% if a.oracle_home %}
9+
oracle_home: {{ a.oracle_home }}
10+
{% endif %}
11+
version: {{ a.oracle_version_db }}
12+
edition: {{ a.oracle_edition }}
13+
{% endfor %}
14+
15+
db_homes_installed:
16+
{% for a in oracle_databases %}
17+
- home: {{ a.home }}-{{ a.oracle_version_db }}
18+
apply_patches: False
19+
state: present
20+
{% endfor %}

0 commit comments

Comments
 (0)