本文整理汇总了Python中script.util.GaussLog.GaussLog.printMessage方法的典型用法代码示例。如果您正苦于以下问题:Python GaussLog.printMessage方法的具体用法?Python GaussLog.printMessage怎么用?Python GaussLog.printMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类script.util.GaussLog.GaussLog
的用法示例。
在下文中一共展示了GaussLog.printMessage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: executeCommand
# 需要导入模块: from script.util.GaussLog import GaussLog [as 别名]
# 或者: from script.util.GaussLog.GaussLog import printMessage [as 别名]
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))