Skip to content

Commit

Permalink
common scripts added (oracle#2776)
Browse files Browse the repository at this point in the history
* common scripts added

* updated license and python3 packages as per feedback from Avi
  • Loading branch information
s1saurabh authored Mar 28, 2024
1 parent ff78d02 commit 73fc5e4
Show file tree
Hide file tree
Showing 22 changed files with 8,126 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

#############################
# Copyright (c) 2024, Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
# Author: [email protected]
############################

TIMESTAMP=$(date "+%Y-%m-%d")
LOGFILE="/tmp/oracle_rac_cmd_${TIMESTAMP}.log"
# shellcheck disable=SC2145
echo "$(date -u) : $@" >> "$LOGFILE"

cmd=("$@")
# shellcheck disable=SC2128
$cmd
# shellcheck disable=SC2181
if [ $? -eq 0 ]; then
exit 0
else
exit 127
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
#!/usr/bin/python3

#############################
# Copyright (c) 2024, Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
# Author: [email protected]
############################

"""
This is the main file which calls other file to setup the sharding.
"""

from oralogger import *
from orafactory import *
from oraenv import *
from oracommon import *


def main():

# Checking Comand line Args
opts=""
try:
opts, args = getopt.getopt(sys.argv[1:], '', ['help','resetpassword=','delracnode=','addtns=', 'checkracinst=', 'checkgilocal=','checkdbrole=','checkracdb=','checkconnstr=','checkpdbconnstr=','setupdblsnr=','setuplocallsnr='])
except getopt.GetoptError:
pass

# Initializing oraenv instance
oenv=OraEnv()
file_name = os.path.basename(__file__)
funcname = sys._getframe(1).f_code.co_name

log_file_name = oenv.logfile_name("NONE")

# Initialiing logger instance
oralogger = OraLogger(log_file_name)
console_handler = CHandler()
file_handler = FHandler()
stdout_handler = StdHandler()
# Setting next log handlers
stdout_handler.nextHandler = file_handler
file_handler.nextHandler = console_handler
console_handler.nextHandler = PassHandler()

ocommon = OraCommon(oralogger,stdout_handler,oenv)

for opt, arg in opts:
if opt in ('--help'):
oralogger.msg_ = '''{:^17}-{:^17} : You can pass parameter --help'''
stdout_handler.handle(oralogger)
elif opt in ('--resetpassword'):
file_name = oenv.logfile_name("RESET_PASSWORD")
oralogger.filename_ = file_name
ocommon.log_info_message("=======================================================================",file_name)
oenv.add_custom_variable("RESET_PASSWORD",arg)
elif opt in ('--delracnode'):
file_name = oenv.logfile_name("DEL_PARAMS")
oralogger.filename_ = file_name
ocommon.log_info_message("=======================================================================",file_name)
oenv.add_custom_variable("DEL_PARAMS",arg)
oenv.add_custom_variable("CUSTOM_RUN_FLAG","true")
oenv.add_custom_variable("DEL_RACHOME","true")
oenv.add_custom_variable("DEL_GIHOME","true")
if ocommon.check_key("OP_TYPE",oenv.get_env_dict()):
oenv.update_key("OP_TYPE","racdelnode")
else:
oenv.add_custom_variable("OP_TYPE","miscops")
elif opt in ('--addtns'):
file_name = oenv.logfile_name("ADD_TNS")
oralogger.filename_ = file_name
ocommon.log_info_message("=======================================================================",file_name)
oenv.add_custom_variable("TNS_PARAMS",arg)
oenv.add_custom_variable("CUSTOM_RUN_FLAG","true")
if ocommon.check_key("OP_TYPE",oenv.get_env_dict()):
oenv.update_key("OP_TYPE","racdelnode")
else:
oenv.add_custom_variable("OP_TYPE","miscops")
elif opt in ('--checkracinst'):
file_name = oenv.logfile_name("CHECK_RAC_INST")
oralogger.filename_ = file_name
ocommon.log_info_message("=======================================================================",file_name)
oenv.add_custom_variable("CHECK_RAC_INST",arg)
oenv.add_custom_variable("CUSTOM_RUN_FLAG","true")
if ocommon.check_key("OP_TYPE",oenv.get_env_dict()):
oenv.update_key("OP_TYPE","miscops")
else:
oenv.add_custom_variable("OP_TYPE","miscops")
elif opt in ('--checkgilocal'):
file_name = oenv.logfile_name("CHECK_GI_LOCAL")
oralogger.filename_ = file_name
ocommon.log_info_message("=======================================================================",file_name)
oenv.add_custom_variable("CHECK_GI_LOCAL",arg)
oenv.add_custom_variable("CUSTOM_RUN_FLAG","true")
if ocommon.check_key("OP_TYPE",oenv.get_env_dict()):
oenv.update_key("OP_TYPE","miscops")
else:
oenv.add_custom_variable("OP_TYPE","miscops")
elif opt in ('--checkracdb'):
file_name = oenv.logfile_name("CHECK_RAC_DB")
oralogger.filename_ = file_name
ocommon.log_info_message("=======================================================================",file_name)
oenv.add_custom_variable("CHECK_RAC_DB",arg)
oenv.add_custom_variable("CUSTOM_RUN_FLAG","true")
if ocommon.check_key("OP_TYPE",oenv.get_env_dict()):
oenv.update_key("OP_TYPE","miscops")
else:
oenv.add_custom_variable("OP_TYPE","miscops")
elif opt in ('--checkdbrole'):
file_name = oenv.logfile_name("CHECK_DB_ROLE")
oralogger.filename_ = file_name
ocommon.log_info_message("=======================================================================",file_name)
oenv.add_custom_variable("CHECK_DB_ROLE",arg)
oenv.add_custom_variable("CUSTOM_RUN_FLAG","true")
if ocommon.check_key("OP_TYPE",oenv.get_env_dict()):
oenv.update_key("OP_TYPE","miscops")
else:
oenv.add_custom_variable("OP_TYPE","miscops")
elif opt in ('--checkconnstr'):
file_name = oenv.logfile_name("CHECK_CONNECT_STR")
oralogger.filename_ = file_name
ocommon.log_info_message("=======================================================================",file_name)
oenv.add_custom_variable("CHECK_CONNECT_STR",arg)
oenv.add_custom_variable("CUSTOM_RUN_FLAG","true")
if ocommon.check_key("OP_TYPE",oenv.get_env_dict()):
oenv.update_key("OP_TYPE","miscops")
else:
oenv.add_custom_variable("OP_TYPE","miscops")
elif opt in ('--checkpdbconnstr'):
file_name = oenv.logfile_name("CHECK_PDB_CONNECT_STR")
oralogger.filename_ = file_name
ocommon.log_info_message("=======================================================================",file_name)
oenv.add_custom_variable("CHECK_PDB_CONNECT_STR",arg)
oenv.add_custom_variable("CUSTOM_RUN_FLAG","true")
if ocommon.check_key("OP_TYPE",oenv.get_env_dict()):
oenv.update_key("OP_TYPE","miscops")
else:
oenv.add_custom_variable("OP_TYPE","miscops")
elif opt in ('--setupdblsnr'):
file_name = oenv.logfile_name("SETUP_DB_LSNR")
oralogger.filename_ = file_name
ocommon.log_info_message("=======================================================================",file_name)
oenv.add_custom_variable("NEW_DB_LSNR_ENDPOINTS",arg)
oenv.add_custom_variable("CUSTOM_RUN_FLAG","true")
if ocommon.check_key("OP_TYPE",oenv.get_env_dict()):
oenv.update_key("OP_TYPE","miscops")
elif opt in ('--setuplocallsnr'):
file_name = oenv.logfile_name("SETUP_LOCAL_LSNR")
oralogger.filename_ = file_name
ocommon.log_info_message("=======================================================================",file_name)
oenv.add_custom_variable("NEW_LOCAL_LISTENER",arg)
oenv.add_custom_variable("CUSTOM_RUN_FLAG","true")
if ocommon.check_key("OP_TYPE",oenv.get_env_dict()):
oenv.update_key("OP_TYPE","miscops")
else:
oenv.add_custom_variable("OP_TYPE","miscops")
else:
pass

# Initializing orafactory instances
oralogger.msg_ = '''{:^17}-{:^17} : Calling OraFactory to start the setup'''.format(file_name,funcname)
stdout_handler.handle(oralogger)
orafactory = OraFactory(oralogger,stdout_handler,oenv,ocommon)

# Get the ora objects
ofactory=orafactory.get_ora_objs()

# Traverse through returned factory objects and execute the setup function
for obj in ofactory:
obj.setup()

# Using the special variable
if __name__=="__main__":
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#!/usr/bin/python3

#############################
# Copyright (c) 2024, Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
# Author: [email protected]
############################

"""
This file contains to the code call different classes objects based on setup type
"""

from oralogger import *
from oraenv import *
from oracommon import *
from oramachine import *
from orasetupenv import *
from orasshsetup import *
from oraracadd import *

import os
import sys

class OraAsmca:
"""
This class performs the ASMCA operations
"""
def __init__(self,oralogger,orahandler,oraenv,oracommon,oracvu,orasetupssh):
try:
self.ologger = oralogger
self.ohandler = orahandler
self.oenv = oraenv.get_instance()
self.ocommon = oracommon
self.ocvu = oracvu
self.orasetupssh = orasetupssh
self.ora_env_dict = oraenv.get_env_vars()
self.file_name = os.path.basename(__file__)
except BaseException as ex:
ex_type, ex_value, ex_traceback = sys.exc_info()
trace_back = traceback.extract_tb(ex_traceback)
stack_trace = list()
for trace in trace_back:
stack_trace.append("File : %s , Line : %d, Func.Name : %s, Message : %s" % (trace[0], trace[1], trace[2], trace[3]))
self.ocommon.log_info_message(ex_type.__name__,self.file_name)
self.ocommon.log_info_message(ex_value,self.file_name)
self.ocommon.log_info_message(stack_trace,self.file_name)

def setup(self):
"""
This function setup the grid on this machine
"""
pass

def validate_dg(self,device_list,device_prop,type):
"""
Check dg if it exist
"""
giuser,gihome,gbase,oinv=self.ocommon.get_gi_params()
device_prop,cname,cred,casm,crdbms,asdvm,cuasize=self.get_device_prop(device_prop,type)
self.ocommon.log_info_message("device prop set to :" + device_prop + " DG Name: " + cname + " Redudancy : " + cred, self.file_name)
cmd='''su - {0} -c "{1}/bin/asmcmd lsdg {2}"'''.format(giuser,gihome,cname)
output,error,retcode=self.ocommon.execute_cmd(cmd,None,None)
self.ocommon.check_os_err(output,error,retcode,None)
if self.ocommon.check_substr_match(output,cname):
return True
else:
return False

def create_dg(self,device_list,device_prop,type):
"""
This function creates the disk group
"""
giuser,gihome,gbase,oinv=self.ocommon.get_gi_params()
disk_lst=self.get_device_list(device_list)
self.ocommon.log_info_message("The type is set to :" + type,self.file_name)
device_prop,cname,cred,casm,crdbms,asdvm,cuasize=self.get_device_prop(device_prop,type)
self.ocommon.log_info_message("device prop set to :" + device_prop + " DG Name: " + cname + " Redudancy : " + cred, self.file_name)
cmd='''su - {0} -c "{1}/bin/asmca -silent -createDiskGroup {3} {2}"'''.format(giuser,gihome,disk_lst,device_prop)
output,error,retcode=self.ocommon.execute_cmd(cmd,None,None)
self.ocommon.check_os_err(output,error,retcode,True)

def get_device_list(self,device_list):
"""
This function returns the device_list
"""
disklst=""
for disk in device_list.split(','):
disklst +=""" -disk '{0}'""".format(disk)

if disklst:
return disklst
else:
self.ocommon.log_error_message("disk string is set to None for diskgroup creation. Exiting..",self.file_name)
self.prog_exit("127")

def get_device_prop(self,device_prop,type):
"""
This function returns the device_props
"""
cname=""
cred=""
casm=""
crdbms=""
cadvm=""
causize=""
cmd=""

self.ocommon.log_info_message("The type is set to :" + type,self.file_name)
if device_prop:
cvar_dict=dict(item.split("=") for item in device_prop.split(";"))
for ckey in cvar_dict.keys():
if ckey == 'name':
cname = cvar_dict[ckey]
if ckey == 'redundancy':
cred = cvar_dict[ckey]
if ckey == 'compatibleasm':
casm = cvar_dict[ckey]
if ckey == 'compatiblerdbms':
crdbms = cvar_dict[ckey]
if ckey == 'compatibleadvm':
cadvm = cvar_dict[ckey]
if ckey == 'au_size':
causize = cvar_dict[ckey]

if not cname:
cmd +=''' -diskGroupName {0}'''.format(type)
cname=type
else:
cmd +=''' -diskGroupName {0}'''.format(cname)
if not cred:
cmd +=''' -redundancy {0}'''.format("EXTERNAL")
cred="EXTERNAL"
else:
cmd +=''' -redundancy {0}'''.format(cred)
if casm:
cmd +=""" -compatible.asm '{0}'""".format(casm)
if crdbms:
cmd +=""" -compatible.rdbms '{0}'""".format(crdbms)
if cadvm:
cmd +=""" -compatible.advm '{0}'""".format(cadvm)
if causize:
cmd +=""" -au_size '{0}'""".format(causize)

if cmd:
return cmd,cname,cred,casm,crdbms,cadvm,causize
else:
self.ocommon.log_error_message("CMD is set to None for diskgroup creation. Exiting..",self.file_name)
self.ocommon.prog_exit("127")
Loading

0 comments on commit 73fc5e4

Please sign in to comment.