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
compute和schedule通过scheduler_client进行rpc通讯
最新推荐文章于 2021-03-17 18:14:24 发布