本文整理汇总了Python中agent.Agent.getState方法的典型用法代码示例。如果您正苦于以下问题:Python Agent.getState方法的具体用法?Python Agent.getState怎么用?Python Agent.getState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类agent.Agent
的用法示例。
在下文中一共展示了Agent.getState方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ctl_status
# 需要导入模块: from agent import Agent [as 别名]
# 或者: from agent.Agent import getState [as 别名]
def ctl_status(*args):
"""Print status of the local daemon."""
agent=Agent()
def checkMembership(result):
if not socket.gethostname() in result:
print "Warning: Local node is not a cluster member !"
def printStatus(result):
print "Role:", result['role']
print "Master:", result['master']
print "Since:", time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(result['lastTallyDate']))
print "State:", result['state']
d=agent.getNodesList()
d.addCallback(checkMembership)
return d
d=agent.getState()
d.addCallback(printStatus)
return d
示例2: ctl_quit
# 需要导入模块: from agent import Agent [as 别名]
# 或者: from agent.Agent import getState [as 别名]
def ctl_quit(*args):
"""Shutdown local daemon."""
agent=Agent()
def success(result):
print "Daemon shutdown requested..."
def checkState(result):
if result['state']=="recovery" and result['role']=="active":
print "Warning: Local node is the master and a recovery process is running."
print "This is not a good idea to shutdown master now. You may loose some VM."
if(raw_input("Proceed anyway ? [y/N]:").upper() != "Y"):
print "Aborded by user."
raise SystemExit(0)
d=agent.quit()
d.addCallback(success)
return d
# Get cluster state
d=agent.getState()
d.addCallback(checkState)
return d
示例3: run
# 需要导入模块: from agent import Agent [as 别名]
# 或者: from agent.Agent import getState [as 别名]
#.........这里部分代码省略.........
# Check argument length according to subcommand
if reason.check(TypeError):
print "Usage :"
print get_help(args[0]),
returnCode=3
reactor.addSystemEventTrigger('after', 'shutdown', exitWithCode, returnCode)
if not reactor._stopped:
reactor.stop()
def runCmd(result):
# result is a cluster instance
d=defer.maybeDeferred(cmd, result, options, *args[1::])
d.addCallback(lambda _: result.disconnect())
return d
def getCluster(result):
# result is the list of nodes
# Check if local node is in cluster
if not socket.gethostname() in result:
print """
**
******
*** ***
*** ***
*** ** *** WARNING
*** ** ***
*** ** *** ***********************
*** ** *** * NODE NOT IN CLUSTER *
*** ** *** ***********************
*** ***
*** ** *** The node you are working on is
*** ** *** not a cluster member.
*** ***
**************************
**********************
"""
# Instanciate cluster
d=xencluster.XenCluster.getDeferInstance(result)
d.addCallback(runCmd)
d.addCallback(lambda _: reactor.stop())
d.addErrback(fail)
def checkState(result):
if result['state']=="panic":
print """
**
******
*** ***
*** ***
*** ** *** WARNING
*** ** ***
*** ** *** **********************
*** ** *** * PANIC MODE ENGAGED *
*** ** *** **********************
*** ***
*** ** ***
*** ** *** Be careful !
*** ***
**************************
**********************
"""
if result['state']=="recovery":
print """
**
******
*** ***
*** ***
*** ** *** WARNING
*** ** ***
*** ** *** ************************
*** ** *** * RECOVERY IN PROGRESS *
*** ** *** ************************
*** ***
*** ** *** You should watch logs and wait
*** ** *** the end of process before
*** *** doing someting.
**************************
**********************
"""
if cmd:
agent=Agent()
# Get cluster state
d=agent.getState()
d.addCallback(checkState)
d.addErrback(fail)
# Get nodes list to instantiate cluster
d=agent.getNodesList()
d.addCallback(getCluster)
d.addErrback(fail)
reactor.run()
else:
syntax_error('Subcommand %s not found!' % args[0])