当前位置: 首页>>代码示例>>Python>>正文


Python Agent.getState方法代码示例

本文整理汇总了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
开发者ID:nagius,项目名称:cxm,代码行数:25,代码来源:clid.py

示例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
开发者ID:nagius,项目名称:cxm,代码行数:26,代码来源:clid.py

示例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])
开发者ID:nagius,项目名称:cxm,代码行数:104,代码来源:cli.py


注:本文中的agent.Agent.getState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。