分享

OpenStack Cinder源码分析之二

shihailong123 发表于 2014-11-23 13:47:04 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 1 25398
阅读导读:
1.Cinder中所有调度器类的调度器基类是什么?
2.chance.py有什么作用?
3.filter_scheduler的作用?
4.host_manager的作用?
5.retry_filter调度的作用?



感谢朋友支持本博客,欢迎共同探讨交流,由于能力和时间有限,错误之处在所难免,欢迎指正!

我们继续来整理代码,来看cinder模块中的调度器。
7 scheduler(/cinder/scheduler/)
/cinder/scheduler/driver.py:所有调度器类都应该继承的调度器基类;
  • class Scheduler(object):调度器基类;
  • def get_host_list(self):从HostManager获取主机列表;#注:这个方法目前还没有进行具体应用;
  • def get_service_capabilities(self):从HostManager获取服务的capabilities;#注:这个方法目前还没有进行具体应用;
  • def update_service_capabilities(self, service_name, host, capabilities):更新一个服务节点的capability信息;
  • def hosts_up(self, context, topic):获取所有运行了给定主题的主机列表;
  • def host_passes_filters(self, context, volume_id, host,filter_properties):检测指定的主机是否通过过滤器;
/cinder/scheduler/chance.py:随即选取节点调度器;
  • classChanceScheduler(driver.Scheduler):随即选取节点调度器;随机选取节点调度器的实现;     
  • def _filter_hosts(self, request_spec, hosts, **kwargs):基于request_spec实现对主机列表的过滤;  
  • def _get_weighted_candidates(self, context, topic, request_spec,**kwargs):获取经过request_spec过滤的可用的主机列表;  
  • def _schedule(self, context, topic, request_spec, **kwargs):实现随机选取主机;   
  • def schedule_create_volume(self, context, request_spec,filter_properties):实现随机选取主机;远程调用实现在选取的主机上建立并导出卷;   
  • def host_passes_filters(self, context, host, request_spec,filter_properties):检测指定的host是否通过了过滤器的过滤;
/cinder/scheduler/filter_scheduler.py:FilterScheduler用于建立卷选取目标主机;可以应用这个调度器来指定我们要应用的卷过滤器和称重方法来实现对候选主机的过滤和称重操作;
  • classFilterScheduler(driver.Scheduler):用于对主机进行过滤和称重操作的调度器;     
  • def schedule(self, context, topic, method, *args, **kwargs):对主机进行过滤称重操作,获取最优的主机;  
  • def _get_configuration_options(self):获取配置选项;
  • def populate_filter_properties(self, request_spec, filter_properties):填充过滤器属性信息;
  • def schedule_create_volume(self, context, request_spec, filter_properties):对主机进行过滤和称重操作,获取最优主机,并实现远程调用建立并导出卷;
  • def host_passes_filters(self, context, host, request_spec,filter_properties):检测指定主机是否经过了主机过滤和称重操作,即在经过主机过滤和称重操作所获取的主机列表中查找是否有指定的主机;
  • def _post_select_populate_filter_properties(self, filter_properties,host_state):在最优主机选定之后,添加附加信息到过滤器属性;
  • def _add_retry_host(self, filter_properties, host):增加retry条目属性到卷的后端,当响应请求进行主机列表的重新选取时,这个条目属性将会表示某主机是否已经进行过过滤操作,如果已经进行过过滤操作,则不再进行过滤操作,这也是提高系统效率的一个措施;      
  • def _max_attempts(self):获取调度一个卷重试次数的最大值;     
  • def _log_volume_error(self, volume_id, retry):记录卷操作的错误,以辅助代码开发和调试;   
  • def _populate_retry(self, filter_properties, properties):添加或更新重试次数的属性值到过滤器属性中;   
  • def _get_weighted_candidates(self, context, request_spec,filter_properties=None):返回满足request_spec要求的主机列表,并对主机进行称重操作;  
  • def _schedule(self, context, request_spec, filter_properties=None):对主机进行过滤称重操作,获取最优的主机;
/cinder/scheduler/host_manager.py:管理当前zone的hosts;
  • class HostState(object):更新主机的可变和不可变的信息;      
  • def update_capabilities(self, capabilities=None, service=None):用给定的capabilities和service,更新现有的capabilities和service;      
  • def update_from_volume_capability(self, capability):从volume_node信息capability中获取相关数据信息来更新对应的主机信息;   
  • def consume_from_volume(self, volume):实现从卷的信息更新主机状态;
  • class HostManager(object):主机管理基类;   
  • def _choose_host_filters(self, filter_cls_names):实现检测默认使用的过滤器类是否都可以使用,获取系统默认使用的过滤器类中通过验证的类的列表;  
  • def _choose_host_weighers(self, weight_cls_names):实现检测默认使用的称重类是否都可以使用,获取系统默认使用的称重类中通过验证的类的列表;
  • def get_filtered_hosts(self, hosts, filter_properties,filter_class_names=None):根据所有过滤器对主机进行过滤操作,只返回符合条件的主机列表;
  • def get_weighed_hosts(self, hosts, weight_properties,weigher_class_names=None):对主机进行称重操作,返回排序后的主机列表;
  • def update_service_capabilities(self, service_name, host, capabilities):根据通知更新每个服务的capabilities;
  • def get_all_host_states(self, context):获取所有匹配的主机;
/cinder/scheduler/manager.py:调度器管理服务;
  • classSchedulerManager(manager.Manager):选取一个host来建立volumes;   
  • def get_host_list(self, context):从HostManager获取主机列表;#注:这个方法目前还没有进行具体应用;   
  • def get_service_capabilities(self, context):从HostManager获取服务的capabilities;#注:这个方法目前还没有进行具体应用;
  • def update_service_capabilities(self, context, service_name=None,host=None, capabilities=None, **kwargs):更新一个服务节点的capability信息;
  • def create_volume(self, context, topic, volume_id, snapshot_id=None,image_id=None, request_spec=None,filter_properties=None):volume_rpcapi.create_volume是调用manager.py中的create_volume方法,该方法先从数据库中取出volume的信息,然后调用volume_utils.notify_about_volume_usage方法(是不是通知RabbitMQ?)。然后继续从volume信息中取vol_name,vol_size,并且如果入参中有snapshot_id,说明从快照创建卷,则从DB中取该snapshot的信息,如果入参中有source_volID,说明是从已有卷创建卷,则从DB中取该源卷信息,如果入参中有image_id,说明是从镜像创建卷,则从glance中获取镜像服务器信息,镜像ID,镜像位置,镜像的metadata.然后调用该类的私有方法_create_volume,该方法首先判断如果snapshot_ref,imag_id,srcvol_ref都是空,则说明是创建一个空卷,就调用driver.create_volume去创卷,如果有snapshot_ref参数,则调用driver.create_volume_from_snapshot方法去创卷,如果请求中有源卷的参数,则调用driver.create_cloned_volume去创卷(实际上就是克隆一个卷)。如果请求中有镜像参数,则调用driver.clone_image方法去创卷,如果clone_image失败,则调用普通创卷方法先创建个空卷,然后将卷状态置为downloading,然后调用_copy_image_to_volume方法把镜像内容拷贝入卷中。
  • def request_service_capabilities(self, context):远程调用实现收集驱动的状态和capabilities信息,并进行信息的发布;   
  • def migrate_volume_to_host(self, context, topic, volume_id, host,force_host_copy, request_spec, filter_properties=None):确认host的存在性并接收指定的卷;即先确定指定的主机是否经过了过滤操作,如果经过了过滤操作,将其作为目标主机,将指定的卷迁移到目标主机上;
  • def _set_volume_state_and_notify(self, method, updates, context, ex,request_spec):设置卷的状态信息,并进行通知操作;
/cinder/scheduler/rpcapi.py:scheduler管理RPC API的客户端;
  • classSchedulerAPI(cinder.openstack.common.rpc.proxy.RpcProxy):scheduler管理RPC API的客户端;      
  • def create_volume(self, ctxt, topic, volume_id, snapshot_id=None,image_id=None, request_spec=None, filter_properties=None):远程调用实现卷的建立操作;   
  • def migrate_volume_to_host(self, ctxt, topic, volume_id, host,force_host_copy=False, request_spec=None, filter_properties=None):远程调用实现确认host的存在性并接收指定的卷;  
  • def update_service_capabilities(self, ctxt, service_name, host,capabilities):远程调用实现获取capabilities信息;
/cinder/scheduler/scheduler_options.py:检测json文件的变化,如果需要要进行文件的加载;
  • class SchedulerOptions(object):检测json文件的变化,如果需要要进行文件的加载;
/cinder/scheduler/simple.py:简单调度器;选取拥有最少卷的主机作为目标主机;
  • classSimpleScheduler(chance.ChanceScheduler):简单的主机调度器类;
  • def schedule_create_volume(self, context, request_spec,filter_properties):选取拥有最少卷的主机作为目标主机;
/cinder/scheduler/filters/capacity_filter.py:基于卷主机capacity使用率的CapacityFilter过滤器;
  • classCapacityFilter(filters.BaseHostFilter):基于卷主机capacity使用率的CapacityFilter过滤器;      
  • def host_passes(self, host_state, filter_properties):如果主机有足够的capacity,返回True;根据过滤器参数filter_properties.get('size')对主机进行过滤;
/cinder/scheduler/filters/retry_filter.py:过滤掉那些已经尝试过的节点;
  • classRetryFilter(filters.BaseHostFilter):过滤掉那些已经尝试过的节点;
  • def host_passes(self, host_state, filter_properties):跳过那些已经尝试过的节点;
/cinder/scheduler/weights/capacity.py:Capacity称重;根据主机可用的available来进行称重主机的操作;
  • classCapacityWeigher(weights.BaseHostWeigher):Capacity称重;根据主机可用的available来进行称重主机的操作;


相关文章



OpenStack Cinder源码分析之一
http://www.aboutyun.com/thread-10236-1-1.html



OpenStack Cinder源码分析之三
http://www.aboutyun.com/thread-10243-1-1.html


OpenStack Cinder源码分析之四
http://www.aboutyun.com/thread-10244-1-1.html

OpenStack Cinder源码分析之五
http://www.aboutyun.com/thread-10245-1-1.html

OpenStack Cinder源码分析之六
http://www.aboutyun.com/thread-10246-1-1.html


OpenStack Cinder源码分析之七
http://www.aboutyun.com/thread-10247-1-1.html


OpenStack Cinder源码分析之八
http://www.aboutyun.com/thread-10248-1-1.html


如果转载,请保留作者信息。
博客地址:http://blog.csdn.net/gaoxingnengjisuan
邮箱地址:dong.liu@siat.ac.cn


已有(1)人评论

跳转到指定楼层
hahaxixi 发表于 2014-11-24 09:56:06
先收藏者,感谢分享~~~~~
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条