def checkPathUsageParameter(): """ """ if (g_opts.newUser == ""): GaussLog.exitWithError("Parameter input error, need '-u' parameter.") if (g_opts.configfile == ""): GaussLog.exitWithError("Parameter input error, need '-X' parameter.")
def main(): """ main function """ try: opts, args = getopt.getopt(sys.argv[1:], "U:R:i:n:l:", ["help"]) except getopt.GetoptError, e: GaussLog.exitWithError("Parameter input error: " + e.msg)
def __checkParameters(self): ''' check input parameters ''' try: opts, args = getopt.getopt(sys.argv[1:], "U:R:l:du", ["help"]) except getopt.GetoptError, e: GaussLog.exitWithError("Parameter input error: " + e.msg)
def parseCommandLine(): """ """ try: (opts, args) = getopt.getopt(sys.argv[1:], "c:p:h", ["help"]) except Exception, e: usage() GaussLog.exitWithError(str(e))
def main(): """ main function """ try: opts, args = getopt.getopt(sys.argv[1:], "U:P:l:pbh", ["position=", "parameter", "binary_file", "logpath=", "help"]) except getopt.GetoptError, e: GaussLog.exitWithError("Parameter input error: " + e.msg)
def parseCommandLine(): """ Parse command line and save to global variables """ try: opts, args = getopt.getopt(sys.argv[1:], "t:u:U:X:l:", ["password_policy_value=", "support_extended_features=", "help"]) except Exception, e: usage() GaussLog.exitWithError("Error: %s" % str(e))
def parseCommandLine(): """ Parse command line and save to global variable """ try: opts, args = getopt.getopt(sys.argv[1:], "u:U:l:", ["help"]) except Exception, e: usage() GaussLog.exitWithError("Error: %s" % str(e))
def parseCommandLine(): """ Parse command line """ try: (opts, args) = getopt.getopt(sys.argv[1:], "U:l:O?", ["help"]) except Exception, e: usage() GaussLog.exitWithError("Error: %s" % str(e))
def importOldVersionModules(): """ import some needed modules from the old cluster. currently needed are: DbClusterInfo """ installDir = DefaultValue.getInstallDir(g_opts.oldUser) if(installDir == ""): GaussLog.exitWithError("get install of user %s failed." % g_opts.oldUser) global g_oldVersionModules g_oldVersionModules = OldVersionModules() sys.path.append("%s/bin/script/util" % installDir) g_oldVersionModules.oldDbClusterInfoModule = __import__('DbClusterInfo')
def checkParameter(): """ check parameter for different ation """ if (g_opts.action == ""): GaussLog.exitWithError("Parameter input error, need '-t' parameter.") if (g_opts.logFile == ""): g_opts.logFile = DefaultValue.getOMLogPath(DefaultValue.DEFAULT_LOG_FILE, g_opts.user, "") if (g_opts.user == ""): GaussLog.exitWithError("Parameter input error, need '-u' parameter.")
def main(): """ main function """ if os.getgid() == 0: GaussLog.exitWithError("Can not use root privilege user run this script") # parse cmd lines parseCommandLine() # init globals initGlobal() # execute command executeCommand() sys.exit(0)
def initGlobal(): """ Init logger """ global g_clusterInfo global g_sshTool global g_user try: cmd = "id -un" (status, output) = commands.getstatusoutput(cmd) if status != 0: GaussLog.exitWithError("Get user info failed") g_user = output g_clusterInfo = dbClusterInfo() g_clusterInfo.initFromStaticConfig(output) g_sshTool = SshTool(g_clusterInfo.getClusterNodeNames()) except Exception, e: GaussLog.exitWithError(str(e))
def checkParameter(): """ check parameter for different ation """ if (g_opts.action == ""): GaussLog.exitWithError("Parameter input error, need '-t' parameter.") if (g_opts.logFile == ""): g_opts.logFile = DefaultValue.getOMLogPath(DefaultValue.DEFAULT_LOG_FILE, g_opts.newUser, "") if (g_opts.action == ACTION_CLEAN_ENV): checkCleanEnvParameter() elif (g_opts.action == ACTION_CHECK_PATH_USAGE): checkPathUsageParameter() elif(g_opts.action == ACTION_START_IN_UPGRADE_MODE): checkStartInUpgradeModeParameter() elif (g_opts.action == ACTION_REPAIR_OLD_CLUSTER): checkRepairOldClusterParameter() elif (g_opts.action == ACTION_SET_GUC_PARAMETER): checkSetNodeGUCParameters() else: GaussLog.exitWithError("Invalid Action : %s" % g_opts.action)
def checkSetNodeGUCParameters(): """ """ if (g_opts.newUser == ""): GaussLog.exitWithError("Parameter input error, need '-u' parameter.") if (g_opts.password_policy_value == None): GaussLog.exitWithError("Parameter input error, need '--password_policy_value' parameter.") else: if(not g_opts.password_policy_value.isdigit()): GaussLog.exitWithError("Parameter input error, '--password_policy_value' parameter should be integer.") #should convert it to int g_opts.password_policy_value = int(g_opts.password_policy_value) if (g_opts.support_extended_features_value == None): GaussLog.exitWithError("Parameter input error, need '--support_extended_features' parameter.")
def checkParameter(): """ Check parameter for create os user """ if (g_opts.userInfo == ""): GaussLog.exitWithError("Parameter input error, need '-U' parameter.") strList = g_opts.userInfo.split(":") if (len(strList) != 2): GaussLog.exitWithError("Parameter input error: -U " + g_opts.userInfo) if (strList[0] == "" or strList[1] == ""): GaussLog.exitWithError("Parameter input error: -U " + g_opts.userInfo) g_opts.user = strList[0] g_opts.group = strList[1] if (g_opts.logFile == ""): g_opts.logFile = DefaultValue.getOMLogPath(DefaultValue.DEFAULT_LOG_FILE, g_opts.user, "") if (not os.path.isabs(g_opts.logFile)): GaussLog.exitWithError("Parameter input error, log path need absolute path.")
""" print usage.__doc__ def parseCommandLine(): """ Parse command line """ try: (opts, args) = getopt.getopt(sys.argv[1:], "U:l:O?", ["help"]) except Exception, e: usage() GaussLog.exitWithError("Error: %s" % str(e)) if(len(args) > 0): GaussLog.exitWithError("Parameter input error: %s" % str(args[0])) for (key, value) in opts: if (key == "-?" or key == "--help"): usage() sys.exit(0) elif (key == "-U"): g_opts.userInfo = value elif (key == "-l"): g_opts.logFile = value elif (key == "-O"): g_opts.deployAll = True def checkParameter(): """ Check parameter for create os user
--help show this help, then exit """ print usage.__doc__ def parseCommandLine(): """ Parse command line and save to global variable """ try: opts, args = getopt.getopt(sys.argv[1:], "u:U:l:", ["help"]) except Exception, e: usage() GaussLog.exitWithError("Error: %s" % str(e)) if(len(args) > 0): GaussLog.exitWithError("Parameter input error: %s" % str(args[0])) for (key, value) in opts: if (key == "--help"): usage() sys.exit(0) elif (key == "-u"): g_opts.newUser = value elif (key == "-U"): g_opts.oldUser = value elif (key == "-l"): g_opts.logFile = os.path.abspath(value) else: GaussLog.exitWithError("Unknown parameter:%s" % key) if (g_opts.oldUser == ""):
def main(): try: opts, args = getopt.getopt(sys.argv[1:], "U:C:D:i:l:h", ["help"]) except Exception, e: usage() GaussLog.exitWithError("Error: %s" % str(e))
Usage: python CheckConfig.py -h | --help python CheckConfig.py -U user [-i instId [...]] [-C "PARAMETER=VALUE" [...]] [-D "PARAMETER=VALUE" [...]] [-l logfile] """ print usage.__doc__ def main(): try: opts, args = getopt.getopt(sys.argv[1:], "U:C:D:i:l:h", ["help"]) except Exception, e: usage() GaussLog.exitWithError("Error: %s" % str(e)) if(len(args) > 0): GaussLog.exitWithError("Parameter input error: %s" % str(args[0])) global g_clusterUser logFile = "" cooParams = [] dataParams = [] instanceIds = [] for (key, value) in opts: if (key == "-h" or key == "--help"): usage() sys.exit(0) elif (key == "-U"): g_clusterUser = value elif (key == "-C"): cooParams.append(value)
--help show this help, then exit """ print usage.__doc__ def parseCommandLine(): """ Parse command line and save to global variable """ try: opts, args = getopt.getopt(sys.argv[1:], "u:U:N:l:", ["help"]) except Exception, e: usage() GaussLog.exitWithError("Error: %s" % str(e)) if(len(args) > 0): GaussLog.exitWithError("Parameter input error: %s" % str(args[0])) for (key, value) in opts: if (key == "--help"): usage() sys.exit(0) elif (key == "-u"): g_opts.newUser = value elif (key == "-U"): g_opts.oldUser = value elif (key == "-N"): g_opts.bucketNum = value elif (key == "-l"): g_opts.logFile = os.path.abspath(value) else: GaussLog.exitWithError("Unknown parameter:%s" % key)
python -h | -help python ConfigInstance.py -U user [-T config_type] [-P gs_config_path] [-C "PARAMETER=VALUE" [...]] [-D "PARAMETER=VALUE" [...]] [-L log] target file: pg_config, gs_config, all """ print usage.__doc__ def main(): try: opts, args = getopt.getopt(sys.argv[1:], "U:C:D:T:P:l:h", ["help", "alarm="]) except Exception, e: usage() GaussLog.exitWithError("Error: %s" % str(e)) if(len(args) > 0): GaussLog.exitWithError("Parameter input error: %s" % str(args[0])) global g_clusterUser logFile = "" cooParams = [] dataParams = [] confType = ConfigInstance.CONFIG_ALL_FILE gsPath = "" alarm_component = "" for (key, value) in opts: if (key == "-h" or key == "--help"): usage() sys.exit(0) elif (key == "-U"): g_clusterUser = value
Write pid to file """ pid = "%d" % os.getpid() tmpDir = DefaultValue.getTmpDirFromEnv() clusterLockFilePath = "%s/%s" % (tmpDir, DefaultValue.CLUSTER_LOCK_PID) PlatformCommand.WriteInfoToFile(clusterLockFilePath, pid) def main(): try: (opts, args) = getopt.getopt(sys.argv[1:], "T:U:l:h", ["help"]) except Exception, e: usage() GaussLog.exitWithError("Error: %s" % str(e)) if(len(args) > 0): GaussLog.exitWithError("Parameter input error: %s" % str(args[0])) time_out = 0 user = "" logFile = "" for (key, value) in opts: if (key == "-h" or key == "--help"): usage() sys.exit(0) elif (key == "-T"): try: time_out = int(value) except Exception, e: GaussLog.exitWithError("Parameter input error: %s" % str(e)) elif (key == "-U"):
def main(): try: (opts, args) = getopt.getopt(sys.argv[1:], "X:l:h", ["target=", "help"]) except Exception, e: usage() GaussLog.exitWithError(str(e))
(status, output) = commands.getstatusoutput(cmd) if (status != 0): self.logger.logExit("set parameter failed!Error:%s" % output) def usage(): pass def main(): try: (opts, args) = getopt.getopt(sys.argv[1:], "X:l:h", ["target=", "help"]) except Exception, e: usage() GaussLog.exitWithError(str(e)) if(len(args) > 0): GaussLog.exitWithError("Parameter input error: %s" % str(args[0])) confFile = DefaultValue.CLUSTER_CONFIG_PATH logFile = "" target = "" for (key, value) in opts: if (key == "-h" or key == "--help"): usage() sys.exit(0) elif (key == "-X"): confFile = value elif (key == "-l"): logFile = value elif (key == "--target"): target = value else:
python GaussStat.py -p installpath -u user -c ip:port [-f output] [-d] [-l log] options: -p install path -u database user name -c host information -d --detail show the detail info about performance check -l --logpath=logfile the log file of operation -h --help show this help, then exit """ print usage.__doc__ try: (opts, args) = getopt.getopt(sys.argv[1:], "p:u:c:l:dh", ["logpath=", "detail", "help"]) except Exception, e: GaussLog.exitWithError("Parameter input error for GaussStat: %s" % str(e)) if(len(args) > 0): GaussLog.exitWithError("Parameter input error for GaussStat: %s" % str(args[0])) installPath = "" user = "" logFile = "" localPort = [] detail = False for (key, value) in opts: if (key == "-h" or key == "--help"): usage() sys.exit(0) elif (key == "-p"):
Usage: python UpgradeConfig.py --help python UpgradeConfig.py -U user [-l log] """ print usage.__doc__ def main(): try: (opts, args) = getopt.getopt(sys.argv[1:], "U:l:", ["help"]) except Exception, e: usage() GaussLog.exitWithError("Error: %s" % str(e)) if(len(args) > 0): GaussLog.exitWithError("Parameter input error: %s" % str(args[0])) global g_clusterUser logFile = "" for (key, value) in opts: if (key == "--help"): usage() sys.exit(0) elif (key == "-U"): g_clusterUser = value elif (key == "-l"): logFile = value else: GaussLog.exitWithError("Parameter input error, unknown options %s." % key)
-B the backup path of old cluster """ print usage.__doc__ def parseCommandLine(): """ Parse command line and save to global variable """ try: opts, args = getopt.getopt(sys.argv[1:], "t:R:B:U:X:l:", ["help"]) except Exception, e: usage() GaussLog.exitWithError("Error: %s" % str(e)) if(len(args) > 0): GaussLog.exitWithError("Parameter input error: %s" % str(args[0])) for (key, value) in opts: if (key == "--help"): usage() sys.exit(0) elif (key == "-t"): g_opts.action = value elif (key == "-R"): g_opts.appPath = value elif (key == "-B"): g_opts.bakDir = value elif (key == "-U"): g_opts.user = value elif (key == "-X"): g_opts.configfile = value
def checkRepairOldClusterParameter(): """ """ if (g_opts.oldUser == ""): GaussLog.exitWithError("Parameter input error, need '-U' parameter.")
def checkStartInUpgradeModeParameter(): """ """ if((g_opts.newUser == "" and g_opts.oldUser == "") or (g_opts.newUser != "" and g_opts.oldUser != "")): GaussLog.exitWithError("Parameter input error, '-U' and '-u' should provide only one in current action!")
def executeCommand(): """ """ failedNodes = "" succeedNodes = "" try: command = (g_opts.cmd.strip()).split(" ") if len(command) > 1: GaussLog.exitWithError("Parameter -c input error, only need command.") checkCmd = "which %s" % command[0] (status, output) = g_sshTool.getSshStatusOutput(checkCmd) for node in status.keys(): if status[node] != 0: failedNodes += "%s " % node else: succeedNodes += "%s " % node if failedNodes != "": GaussLog.exitWithError( "Command %s not exist or not have executable permissions on %s." % (command, failedNodes) ) failedNodes = "" succeedNodes = "" executeCmd = g_opts.cmd + " " + g_opts.parameterlist ############################################################# cmdFile = "%s/ClusterCall_%d.sh" % (DefaultValue.getTmpDirFromEnv(), os.getpid()) cmdCreateFile = "touch %s" % cmdFile (status, output) = commands.getstatusoutput(cmdCreateFile) if status != 0: GaussLog.exitWithError("Touch file %s failed!" % cmdFile) cmdFileMod = "chmod 640 %s" % cmdFile (status, output) = commands.getstatusoutput(cmdFileMod) if status != 0: GaussLog.exitWithError("Chmod file %s failed!" % cmdFile) fp = open(cmdFile, "a") fp.write("#!/bin/sh") fp.write(os.linesep) fp.write("%s" % (executeCmd)) fp.write(os.linesep) fp.flush() fp.close() ############################################################## cmdDir = DefaultValue.getTmpDirFromEnv() g_sshTool.scpFiles(cmdFile, cmdDir) cmdExecute = "sh %s" % cmdFile (status, output) = g_sshTool.getSshStatusOutput(cmdExecute) for node in status.keys(): if status[node] != 0: failedNodes += "%s " % node else: succeedNodes += "%s " % node if failedNodes != "" and succeedNodes != "": GaussLog.printMessage("Execute command failed on %s." % failedNodes) GaussLog.printMessage("Execute command succeed on %s.\n" % succeedNodes) elif failedNodes == "": GaussLog.printMessage("Execute command succeed on all nodes.\n") elif succeedNodes == "": GaussLog.printMessage("Execute command failed on all nodes.\n") GaussLog.printMessage("Output:\n%s" % output) cmdFileRm = "rm %s" % cmdFile g_sshTool.executeCommand(cmdFileRm, "rm cmdFile") except Exception, e: if fp: fp.close() cmdFileRm = "rm %s" % cmdFile g_sshTool.executeCommand(cmdFileRm, "rm cmdFile") GaussLog.exitWithError(str(e))