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


Python Client.list_agents方法代码示例

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


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

示例1: NeutronAgent

# 需要导入模块: from neutronclient.v2_0.client import Client [as 别名]
# 或者: from neutronclient.v2_0.client.Client import list_agents [as 别名]
class NeutronAgent():
    def __init__(self, config, plugin_config, agent_type):
        # Config blob for us
        self.config = config

        # Store what type of agent we are
        self.agent_type = agent_type

        # Dict of agent state information, keyed by id
        self.agents = {}

        # Lock for self.agents access
        self.lock = Semaphore()

        # Agent timeout helpers
        self.downtime = timedelta(seconds=int(self.config['agent_down_time']))
        self.timeout = int(self.config['agent_down_time'])

        # Initialize neutron client
        self.client = Client(
            username=self.config['admin_user'],
            password=self.config['admin_password'],
            tenant_name=self.config['admin_tenant_name'],
            auth_url=self.config['auth_url'],
            timeout=int(plugin_config.get('timeout', 20))
        )

        # Populate agents and states
        self.logger.info('Populating agents...')
        agents = dict([(agent['id'], agent) for agent in
                       self.client.list_agents(agent_type=self.agent_type)['agents']])
        for agent in agents.values():
            agent['heartbeat_timestamp'] = dateparse(
                agent['heartbeat_timestamp']
            )
            self.agents[agent['id']] = agent

        self.logger.debug('Agents: %s' % agents.keys())

    # queue we should be listening to (neutron vs quantum)
    # based on imports
    def event_queue(self):
        if is_neutron:
            return 'neutron'
        return 'quantum'

    # Empty default handler
    def handle(self, agent, state):
        pass

    # RPC Callback to update agents and states
    def update(self, body, message):
        if 'oslo.message' in body:
            body = loads(body['oslo.message'])

        if body['method'] == 'report_state':
            state = body['args']['agent_state']['agent_state']
            time = body['args']['time']
            host = state['host']

            # Accept our agent type only; '' for all agent types
            if not self.agent_type or state['agent_type'] == self.agent_type:
                self.lock.acquire()  # Lock inside RPC callback

                # Agents to update if we've seen host/type before
                updates = [
                    agent for agent in self.agents.values()
                    if agent['host'] == host
                    and agent['agent_type'] == state['agent_type']
                ]

                # Haven't seen this host/type before?
                if not updates:
                    # Get full agent info
                    updates = [
                        agent for agent in
                        self.client.list_agents(
                            host=host,
                            agent_type=state['agent_type']
                        )['agents']
                    ]

                self.logger.debug(
                    'Updates: %s' % [
                        str(update['host']) + '/' + str(update['agent_type'])
                        for update in updates
                    ]
                )

                # Update state since we got a message
                for agent in updates:
                    self.agents[agent['id']].update(state)
                    self.agents[agent['id']]['heartbeat_timestamp'] = (
                        dateparse(time)
                    )

                self.lock.release()  # Unlock inside RPC callback

        # Ack that sucker
        message.ack()
#.........这里部分代码省略.........
开发者ID:AsherBond,项目名称:rpcdaemon-buildpackage,代码行数:103,代码来源:neutronagent.py


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