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


Python Agent.getNodesList方法代码示例

本文整理汇总了Python中agent.Agent.getNodesList方法的典型用法代码示例。如果您正苦于以下问题:Python Agent.getNodesList方法的具体用法?Python Agent.getNodesList怎么用?Python Agent.getNodesList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在agent.Agent的用法示例。


在下文中一共展示了Agent.getNodesList方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ctl_listnodes

# 需要导入模块: from agent import Agent [as 别名]
# 或者: from agent.Agent import getNodesList [as 别名]
def ctl_listnodes(*args):
	"""List current connected nodes."""
	def success(result):
		assert type(result) == list, "Result should be a list"
		for node in sorted(result):
			print node

	agent=Agent()
	d=agent.getNodesList()
	d.addCallback(success)
	
	return d
开发者ID:nagius,项目名称:cxm,代码行数:14,代码来源:clid.py

示例2: getDeferInstance

# 需要导入模块: from agent import Agent [as 别名]
# 或者: from agent.Agent import getNodesList [as 别名]
    def getDeferInstance(nodeslist=None):
        """Instantiate a XenCluster object and associated Nodes.

		This function open SSH and XenAPI connections to all actives nodes.
		It take a (string) list of node's hostname as optionnal argument, if not given, 
		the list will fetched from cxm'master.

		Return a deferred that will be fired when all nodes are ready.
		If a node is not online, the deferred will fail.
		"""

        log.info("Loading cluster...")
        nodes = dict()

        def instantiate(results):
            failedNodes = dict()
            for result in results:
                if not result[0]:
                    failedNodes[nodeslist[results.index(result)]] = result[1].getErrorMessage()

            if len(failedNodes) > 0:
                raise InstantiationError(failedNodes)

            return XenCluster(nodes)

        def add_node(result, hostname):
            nodes[hostname] = result

        def create_nodes(result):
            ds = list()
            for hostname in result:
                d = threads.deferToThread(lambda x: Node(x), hostname)
                d.addCallback(add_node, hostname)
                ds.append(d)

            dl = defer.DeferredList(ds, consumeErrors=1)
            dl.addCallback(instantiate)
            return dl

        def failed(reason):
            raise Exception("Can't connect to local master: %s" % reason.getErrorMessage())

        if not nodeslist:
            agent = Agent()
            d = agent.getNodesList()
            d.addCallback(create_nodes)
            d.addErrback(failed)
            return d
        else:
            return create_nodes(nodeslist)
开发者ID:nagius,项目名称:cxm,代码行数:52,代码来源:xencluster.py

示例3: run

# 需要导入模块: from agent import Agent [as 别名]
# 或者: from agent.Agent import getNodesList [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.getNodesList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。