-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathwls_full_setup.py
executable file
·182 lines (169 loc) · 7.62 KB
/
wls_full_setup.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/python3
## wls_full_setup.py script version 1.0.
##
## Copyright (c) 2025 Oracle and/or its affiliates
## Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
##
### This script runs the following operations in order:
###
### 1. Data pull from primary:
### Retrieve WLS and OHS data from primary environment
### 2. Discovery:
### Parse and analyze retrieved data to gather systems information automatically
### 3. OCI provisioning of resources:
### Create and configure all required OCI resources
### 4. Data push to OCI:
### Push all WLS and OHS required data to OCI environment
### 5. tnsnames.ora operations:
### 5.1 - retrieval of tnsnames.ora file from primary environment
### 5.2 - update of file with OCI details
### 5.3 - push file to OCI environment
###
### NOTE:
### i) In order to properly run this script, the following files are expected to be properly filled in with the
### requested information:
### - config/prem.env
### - config/replication.properties
### - the sysconfig_discovery.xlsx file saved as .csv (comma-separated values)
###
### ii) If the server this script is run on does not have connectivity to the primary system, the optional
### argument -n/--no-connectivity should be used (more details below). In this case, it is assumed that all the
### required data - WLS and OHS data as well as tnsnames.ora file - have been manually staged on the server in the
### proper locations and operations (1) and (5.1) will be skipped.
###
### This script should be executed in a bastion node with connectivity to (at least) OCI environment
### Usage:
###
### ./wls_full_setup.py -i/--input-file INPUT_FILE [-d/--debug] [-n/--no-connectivity] [-c/--oci-config OCI_CONFIG_PATH]
###
### Where:
### -i/--input-file INPUT_FILE:
### INPUT_FILE is the .csv file filled in with system details - this should be the discovery variant
### of the sysconfig.xlsx template file
###
### -n/--no-connectivity
### To be used when there is no connectivity to the primary system
### In this case, the initial data and tnsnames pull operations from primary are omitted and the data is assumed
### to have been manually staged in the proper locations.
###
### -d/--debug:
### Print more verbose information to console
###
### -v/--version:
### Show script version and exit
###
### -c/--oci-config OCI_CONFIG_PATH:
### To specify a path for the OCI config file if not in the default location (/home/<user>/.oci/config)
###
###
### Examples:
### To run all operations (DATA pull -> discovery -> provisioning -> DATA push -> tnsnames pull/update/push):
### ./wls_full_setup.py -i sysconfig_discovery.csv
###
### Same operation as above, but in debug mode:
### ./wls_full_setup.py -i sysconfig_discovery.csv -d
###
### Same operation as above, but with custom OCI config path:
### ./wls_full_setup.py -i sysconfig_discovery.csv -d -c /path/to/oci/config
###
### To not attempt to connect to the primary server when there is no connectivity:
### ./wls_full_setup.py -i sysconfig_discovery.csv -n
### NOTE: As already mentioned above, this option assumes that all required files (including tnsnames.ora) have
### been manually staged in the proper locations.
###
###
__version__ = "1.0"
__author__ = "mibratu"
try:
import argparse
import sys
from lib.Logger import Logger
import lib.DataReplication as DataReplication
from lib.Utils import Constants as CONSTANTS
import pathlib
import datetime
import shlex
import subprocess
import time
except ImportError as e:
raise ImportError (str(e) + """
Failed to import module
Make sure all required modules are installed before running this script""")
def custom_exit(code):
sys.exit(code)
arg_parser = argparse.ArgumentParser(description="Weblogic Hybrid DR full set-up utility")
required = arg_parser.add_argument_group("required arguments")
required.add_argument("-i", "--input-file", required=True, type=pathlib.Path,
help="CSV input file path with systems information")
arg_parser.add_argument("-n", "--no-connectivity", action="store_true",
help="use if there is no connectivity to the primary environment")
arg_parser.add_argument("-d", "--debug", action="store_true",
help="set logging to debug")
arg_parser.add_argument("-v", "--version", action='version', version=__version__)
arg_parser.add_argument("-c", "--oci-config", required=False, type=pathlib.Path,
help="OCI config file path")
args = arg_parser.parse_args()
if args.debug:
log_level = 'DEBUG'
else:
log_level = 'INFO'
now = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M")
log_file = f"full_setup_{now}.log"
logger = Logger(__file__, log_file, log_level)
logger.writelog("info", "Starting full WLS Hybrid DR set-up")
if args.no_connectivity:
logger.writelog("info", "No connectivity to primary environment - assuming data manually staged - running discovery")
else:
logger.writelog("info", "Pulling data from primary environment")
try:
DataReplication.run(args.debug, "pull")
except Exception as e:
logger.writelog("error", "Pulling data from primary environment failed - please check specific logs for more information and help")
custom_exit(1)
logger.writelog("info", "Running discovery")
cmd = f"{CONSTANTS.DISCOVERY_SCRIPT}"
if args.debug:
cmd += " -d"
if args.no_connectivity:
cmd += " -n"
discovery_exec = subprocess.Popen(shlex.split(cmd))
discovery_exec.wait()
if discovery_exec.returncode != 0:
logger.writelog("error", "Discovery failed - please check specific logs for more information and help")
custom_exit(1)
wait_time = 15
print(f"Waiting {wait_time} seconds before continuing")
time.sleep(wait_time)
logger.writelog("info", "Provisioning OCI resources")
cmd = f"{CONSTANTS.PROVISIONING_SCRIPT} -i {args.input_file} -a"
if args.debug:
cmd += " -d"
if args.oci_config:
cmd += f" -c {args.oci_config}"
provision_exec = subprocess.Popen(shlex.split(cmd))
provision_exec.wait()
if provision_exec.returncode != 0:
logger.writelog("error", "Failed during provisioning phase - please check specific logs for more information and help")
custom_exit(0)
logger.writelog("info", "Pushing data to newly created OCI resources")
try:
DataReplication.run(args.debug, "push")
except Exception as e:
logger.writelog("error", "Pushing data to secondary environment failed - please check specific logs for more information and help")
custom_exit(1)
if args.no_connectivity:
logger.writelog("info", "No connectivity to primary environment - assuming tnsnames.ora file manually staged")
else:
logger.writelog("info", "Retrieving tnsnames.ora file from primary environment")
try:
DataReplication.run(args.debug, "tnsnames", pull=True)
except Exception as e:
logger.writelog("error", "Pulling tnsnames.ora file from primary environment failed - please check specific logs for more information and help")
custom_exit(1)
logger.writelog("info", "Updating staged tnsnames.ora file and uploading to secondary environment")
try:
DataReplication.run(args.debug, "tnsnames", push=True)
except Exception as e:
logger.writelog("error", "Updating and/or uploading tnsnames.ora file failed - please check specific logs for more information and help")
custom_exit(1)
logger.writelog("info", "All operations completed successfully")