compute和schedule通过scheduler_client进行rpc通讯

compute和schedule 节点之前都是通过rpc来通讯的,例如在E:\nova\nova\compute\manager.py 中一般通过self.scheduler_client
来和schedule 通讯,例如下面的例子

    def _update_scheduler_instance_info(self, context, instance):
        """Sends an InstanceList with created or updated Instance objects to
        the Scheduler client.

        In the case of init_host, the value passed will already be an
        InstanceList. Other calls will send individual Instance objects that
        have been created or resized. In this case, we create an InstanceList
        object containing that Instance.
        """
        if not self.send_instance_updates:
            return
        if isinstance(instance, obj_instance.Instance):
            instance = objects.InstanceList(objects=[instance])
        context = context.elevated()
        self.scheduler_client.update_instance_info(context, self.host,
                                                   instance)
这里的scheduler_client在ComputeManager的__init__ 中赋值
class ComputeManager(manager.Manager):
    """Manages the running instances from creation to destruction."""

    target = messaging.Target(version='4.18')

    # How long to wait in seconds before re-issuing a shutdown
    # signal to an instance during power off.  The overall
    # time to wait is set by CONF.shutdown_timeout.
    SHUTDOWN_RETRY_INTERVAL = 10

    def __init__(self, compute_driver=None, *args, **kwargs):
        """Load configuration options and connect to the hypervisor."""
        self.scheduler_client = scheduler_client.SchedulerClient()
而这里的scheduler_client原来是从nova.scheduler.client
from nova.scheduler import client as scheduler_client
到nova.scheduler.client 这个路径下看看E:\nova\nova\scheduler\client\__init__.py
class SchedulerClient(object):
    """Client library for placing calls to the scheduler."""

    def __init__(self):
        self.queryclient = LazyLoader(importutils.import_class(
            'nova.scheduler.client.query.SchedulerQueryClient'))
        self.reportclient = LazyLoader(importutils.import_class(
            'nova.scheduler.client.report.SchedulerReportClient'))

    @utils.retry_select_destinations
    def select_destinations(self, context, spec_obj, instance_uuids):
        return self.queryclient.select_destinations(context, spec_obj,
                instance_uuids)
原来schedule 就提供了queryclient和reportclient 两个对外的rpc接口,这里的LazyLoader 并没有在SchedulerClient的_init__函数中加载nova.scheduler.client.query.SchedulerQueryClient
和nova.scheduler.client.report.SchedulerReportClient。而是在实际使用的时候才需要,因此才叫LazyLoader
这里以nova.scheduler.client.query.SchedulerQueryClient为例
路径为:E:\nova\nova\scheduler\client\query.py
class SchedulerQueryClient(object):
    """Client class for querying to the scheduler."""

    def __init__(self):
        self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI()

    def select_destinations(self, context, spec_obj, instance_uuids):
        """Returns destinations(s) best suited for this request_spec and
        filter_properties.

        The result should be a list of dicts with 'host', 'nodename' and
        'limits' as keys.
        """
        return self.scheduler_rpcapi.select_destinations(context, spec_obj,
                instance_uuids)
原来最终还是通过scheduler_rpcapi来访问schedule的接口.
可见这里的SchedulerClient真的是一个client


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值