Ejemplo n.º 1
0
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.")
Ejemplo n.º 2
0
def parseCommandLine():
    """
    """
    try:
        (opts, args) = getopt.getopt(sys.argv[1:], "c:p:h", ["help"])
    except Exception, e:
        usage()
        GaussLog.exitWithError(str(e))
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
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))
Ejemplo n.º 7
0
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))
Ejemplo n.º 8
0
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))
Ejemplo n.º 9
0
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')
Ejemplo n.º 10
0
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.")
Ejemplo n.º 11
0
class LocalBackup():
    '''
    classdocs
    '''   
    def __init__(self, user = "", backupDir = "", backupPara = False, backupBin = False, logFile = ""):
        '''
        Constructor
        '''
        self.backupDir = backupDir
        self.backupPara = backupPara
        self.backupBin = backupBin
        self.logFile = logFile
        
        self.installPath = ""
        self.user = user
        self.group = ""
        self.nodeInfo = None
        
        self.logger = None
        self.__hostnameFile = None
        
        ##static parameter
        self.defaultLogDir = ""
        self.logName = "gs_local_backup.log"
        self.envirName = "GAUSS_VERSION"
        self.binTarName = "binary.tar"
        self.paraTarName = "parameter.tar"
        self.hostnameFileName = "HOSTNAME"
        
    ####################################################################################
    # This is the main install flow.  
    ####################################################################################
    
    def run(self):
        '''
        check install 
        '''
        self.logger = GaussLog(self.logFile, "LocalBackup") 
        try:
            self.parseConfigFile()
            self.checkBackupDir()
            self.doBackup()
        except Exception,e:
            self.logger.closeLog()
            raise Exception(str(e))     
            
        self.logger.closeLog()
Ejemplo n.º 12
0
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)
Ejemplo n.º 13
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))
Ejemplo n.º 14
0
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)
Ejemplo n.º 15
0
 def run(self):
     '''
     check install 
     '''
     self.logger = GaussLog(self.logFile, "LocalBackup") 
     try:
         self.parseConfigFile()
         self.checkBackupDir()
         self.doBackup()
     except Exception,e:
         self.logger.closeLog()
         raise Exception(str(e))     
Ejemplo n.º 16
0
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.")
Ejemplo n.º 17
0
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.")
Ejemplo n.º 18
0
    """
    
    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
Ejemplo n.º 19
0
  --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 == ""):
Ejemplo n.º 20
0
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))
Ejemplo n.º 21
0
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)
Ejemplo n.º 22
0
  --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)
Ejemplo n.º 23
0
    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
Ejemplo n.º 24
0
    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"):
Ejemplo n.º 25
0
def main():
    try:
        (opts, args) = getopt.getopt(sys.argv[1:], "X:l:h", ["target=", "help"])
    except Exception, e:
        usage()
        GaussLog.exitWithError(str(e))
Ejemplo n.º 26
0
            (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:
Ejemplo n.º 27
0
    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"):
Ejemplo n.º 28
0
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)
Ejemplo n.º 29
0
  -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
Ejemplo n.º 30
0
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))