分享

Openstack Cinder中建立volume过程的源码解析(8)

shihailong123 发表于 2014-11-22 13:47:52 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 0 18158
问题导读:
1.VolumeCastTask的源码如何实现?
2.远程调用建立新卷的操作,有哪几个步骤?
3.task类VolumeCastTask具体是如何来实现根据请求信息进行卷的建立的?





在这篇博客中,我将详细的分析task类VolumeCastTask具体是如何来实现根据请求信息进行卷的建立的。
我们来回顾类VolumeCastTask的源码实现:
  1. class VolumeCastTask(base.CinderTask):  
  2.     """
  3.     远程调用实现卷的建立操作;
  4.     """  
  5.   
  6.     def __init__(self, scheduler_rpcapi, volume_rpcapi, db):  
  7.         super(VolumeCastTask, self).__init__(addons=[ACTION])  
  8.         self.volume_rpcapi = volume_rpcapi  
  9.         self.scheduler_rpcapi = scheduler_rpcapi  
  10.         self.db = db  
  11.         self.requires.update(['image_id', 'scheduler_hints', 'snapshot_id',  
  12.                               'source_volid', 'volume_id', 'volume_type',  
  13.                               'volume_properties'])  
  14.   
  15.     def __call__(self, context, **kwargs):  
  16.         """
  17.         远程调用实现卷的建立操作;
  18.         context = <cinder.context.RequestContext object at 0x4337e10>
  19.         kwargs = {'volume_properties': {'status': 'creating',  
  20.                                         'volume_type_id': None,  
  21.                                         'user_id': u'ef073287176048bd861dcd9d9c4d9808',  
  22.                                         'availability_zone': 'nova',  
  23.                                         'reservations': ['4d53f59d-f1ca-4a62-a6ff-7b4609bd6512',  
  24.                                                          '513f29df-26b2-49d3-bd96-951623e4d20f'],  
  25.                                         'volume_admin_metadata': [],  
  26.                                         'attach_status': 'detached',  
  27.                                         'display_description': None,  
  28.                                         'volume_metadata': [],  
  29.                                         'metadata': {},  
  30.                                         'encryption_key_id': None,  
  31.                                         'source_volid': None,  
  32.                                         'snapshot_id': None,  
  33.                                         'display_name': u'shinian01',  
  34.                                         'project_id': u'6c3c74779a614d3b81dd75518824e25c',  
  35.                                         'id': '3e68f81a-3e9e-45f6-8332-55c31a3195dc',  
  36.                                         'size': 1},  
  37.                   'source_volid': None,  
  38.                   'image_id': None,  
  39.                   'snapshot_id': None,  
  40.                   'volume_type': {},  
  41.                   'volume_id': '3e68f81a-3e9e-45f6-8332-55c31a3195dc',  
  42.                   'scheduler_hints': None}
  43.         """  
  44.         scheduler_hints = kwargs.pop('scheduler_hints', None)  
  45.         request_spec = kwargs.copy()  
  46.         filter_properties = {}  
  47.         if scheduler_hints:  
  48.             filter_properties['scheduler_hints'] = scheduler_hints  
  49.         # filter_properties = {}  
  50.         # _cast_create_volume:远程调用建立卷的方法,实现卷的建立操作;  
  51.         self._cast_create_volume(context, request_spec, filter_properties)  
复制代码

进一步来看方法_cast_create_volume的源码实现:
  1. def _cast_create_volume(self, context, request_spec, filter_properties):  
  2.     """
  3.     远程调用建立卷的方法,实现卷的建立操作;
  4.     request_spec = {'image_id': None,  
  5.                     'volume_type': {},  
  6.                     'volume_id': '3e68f81a-3e9e-45f6-8332-55c31a3195dc',  
  7.                     'snapshot_id': None,  
  8.                     'volume_properties': {'status': 'creating',  
  9.                                           'volume_type_id': None,  
  10.                                           'user_id': u'ef073287176048bd861dcd9d9c4d9808',  
  11.                                           'availability_zone': 'nova',  
  12.                                           'reservations': ['4d53f59d-f1ca-4a62-a6ff-7b4609bd6512',  
  13.                                                            '513f29df-26b2-49d3-bd96-951623e4d20f'],  
  14.                                           'volume_admin_metadata': [],  
  15.                                           'attach_status': 'detached',  
  16.                                           'display_description': None,  
  17.                                           'volume_metadata': [],  
  18.                                           'metadata': {},  
  19.                                           'encryption_key_id': None,  
  20.                                           'source_volid': None,  
  21.                                           'snapshot_id': None,  
  22.                                           'display_name': u'shinian01',  
  23.                                           'project_id': u'6c3c74779a614d3b81dd75518824e25c',  
  24.                                           'id': '3e68f81a-3e9e-45f6-8332-55c31a3195dc',  
  25.                                           'size': 1},  
  26.                      'source_volid': None}
  27.     filter_properties = {}
  28.     """  
  29.     source_volid = request_spec['source_volid']  
  30.     # source_volid = None;  
  31.     volume_id = request_spec['volume_id']  
  32.     # volume_id = 3e68f81a-3e9e-45f6-8332-55c31a3195dc  
  33.     snapshot_id = request_spec['snapshot_id']  
  34.     # snapshot_id = None;  
  35.     image_id = request_spec['image_id']  
  36.     # image_id = None;  
  37.     host = None  
  38.   
  39.     # snapshot_same_host:这个参数定义了是否根据快照在快照所处的主机上建立卷;  
  40.     # 参数的默认值为True;  
  41.     # snapshot_id = None,说明请求中不是要求根据快照来建立卷;  
  42.     if snapshot_id and CONF.snapshot_same_host:              
  43.         # 根据snapshot_id获取指定卷的快照;  
  44.         snapshot_ref = self.db.snapshot_get(context, snapshot_id)  
  45.         # 根据snapshot_ref['volume_id']获取volume;  
  46.         source_volume_ref = self.db.volume_get(context, snapshot_ref['volume_id'])  
  47.         # 根据卷的属性获取它所在的主机信息;  
  48.         host = source_volume_ref['host']  
  49.          
  50.     # source_volid = None,说明请求中不是要求根据现有的指定的卷来建立卷;  
  51.     elif source_volid:  
  52.         # 根据source_volid获取volume;  
  53.         source_volume_ref = self.db.volume_get(context, source_volid)  
  54.         # 根据卷的属性获取它所在的主机信息;  
  55.         host = source_volume_ref['host']  
  56.   
  57.     # 如果没有获取到主机信息,说明没有确定建立卷的目标主机,需要通过调度器择优获取目标主机,并实现远程调用方法create_volume,来进行建立卷的操作;         
  58.     if not host:  
  59.         # create_volume:远程调用实现卷的建立操作;  
  60.         # self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI();  
  61.         self.scheduler_rpcapi.create_volume(  
  62.             context,  
  63.             CONF.volume_topic,  
  64.             volume_id,  
  65.             snapshot_id=snapshot_id,  
  66.             image_id=image_id,  
  67.             request_spec=request_spec,  
  68.             filter_properties=filter_properties)  
  69.       
  70.     # 如果获取到主机的信息,则直接通过volume_rpcapi实现远程调用方法create_volume,来进行卷的建立操作。  
  71.     else:  
  72.         now = timeutils.utcnow()  
  73.         values = {'host': host, 'scheduled_at': now}  
  74.         # 在卷上设置给定的属性,并进行更新;  
  75.         volume_ref = self.db.volume_update(context, volume_id, values)  
  76.         # 远程调用实现建立并导出卷;  
  77.         # self.volume_rpcapi = volume_rpcapi.VolumeAPI();  
  78.         self.volume_rpcapi.create_volume(  
  79.             context,  
  80.             volume_ref,  
  81.             volume_ref['host'],  
  82.             request_spec,  
  83.             filter_properties,  
  84.             allow_reschedule=False,  
  85.             snapshot_id=snapshot_id,  
  86.             image_id=image_id,  
  87.             source_volid=source_volid)
复制代码



这个方法主要实现了根据具体情况通过远程调用建立新卷的操作。在这个方法中,大致可以分为四个步骤:
1.从输入参数request_spec中获取相应的数据信息,主要用于鉴别采用何种建立卷的方法;
2.判断是否根据现有快照在快照所在的主机上进行新卷的建立,根据判断结果从具体的参数中获取建立新卷的目标主机;
3.如果没有获取到主机信息,说明没有确定建立卷的目标主机,需要通过调度器择优获取目标主机,并实现远程调用方法create_volume,来进行建立卷的操作;
4.如果获取到主机的信息,则直接通过volume_rpcapi实现远程调用方法create_volume,来进行卷的建立操作。
我们先来看上述第3步骤的具体实现过程,在这里我们知道self.scheduler_rpcapi = scheduler_rpcapi.SchedulerAPI(),所以这里调用的建立卷的方法为/cinder/scheduler/rpcapi.py----class SchedulerAPI----def create_volume,我们来看方法的源码实现:
  1. def create_volume(self, ctxt, topic, volume_id, snapshot_id=None,  
  2.                   image_id=None, request_spec=None,  
  3.                   filter_properties=None):  
  4.     """
  5.     远程调用实现建立卷的主机选择,以及卷的建立操作;
  6.     """  
  7.     request_spec_p = jsonutils.to_primitive(request_spec)  
  8.     return self.cast(ctxt, self.make_msg(  
  9.         'create_volume',  
  10.         topic=topic,  
  11.         volume_id=volume_id,  
  12.         snapshot_id=snapshot_id,  
  13.         image_id=image_id,  
  14.         request_spec=request_spec_p,  
  15.         filter_properties=filter_properties),  
  16.         version='1.2')  
复制代码



我们可以看到,这个方法中通过广播的方式,发送请求远程调用建立卷的方法create_volume,这里具体执行的方法是/cinder/scheduler/manager.py----class SchedulerManager----def create_volume,我们来看方法的源码实现:
  1. def create_volume(self, context, topic, volume_id, snapshot_id=None,  
  2.                   image_id=None, request_spec=None,  
  3.                   filter_properties=None):  
  4.     """
  5.     volume_rpcapi.create_volume是调用manager.py中的create_volume方法,   
  6.     该方法先从数据库中取出volume的信息,然后调用volume_utils.notify_about_volume_usage方法(是不是通知RabbitMQ?)。
  7.     然后继续从volume信息中取vol_name,vol_size,
  8.     并且如果入参中有snapshot_id,说明从快照创建卷,则从DB中取该snapshot的信息,
  9.     如果入参中有source_volID,说明是从已有卷创建卷,则从DB中取该源卷信息,
  10.     如果入参中有image_id,说明是从镜像创建卷,则从glance中获取镜像服务器信息,镜像ID,镜像位置,镜像的metadata.
  11.     然后调用该类的私有方法_create_volume,该方法首先判断如果snapshot_ref,imag_id,srcvol_ref都是空,
  12.     则说明是创建一个空卷,就调用driver.create_volume去创卷,
  13.     如果有snapshot_ref参数,则调用driver.create_volume_from_snapshot方法去创卷,
  14.     如果请求中有源卷的参数,则调用driver.create_cloned_volume去创卷(实际上就是克隆一个卷)。
  15.     如果请求中有镜像参数,则调用driver.clone_image方法去创卷,
  16.     如果clone_image失败,则调用普通创卷方法先创建个空卷,
  17.     然后将卷状态置为downloading,
  18.     然后调用_copy_image_to_volume方法把镜像内容拷贝入卷中。
  19.     """  
  20.   
  21.     # 构建并返回用于通过远程调度建立卷的flow;  
  22.     flow = create_volume.get_scheduler_flow(db, self.driver,  
  23.                                             request_spec,  
  24.                                             filter_properties,  
  25.                                             volume_id, snapshot_id,  
  26.                                             image_id)  
  27.     assert flow, _('Schedule volume flow not retrieved')  
  28.   
  29.     flow.run(context)  
  30.     if flow.state != states.SUCCESS:  
  31.         LOG.warn(_("Failed to successfully complete"  
  32.                    " schedule volume using flow: %s"), flow)  
复制代码


我们这里可以看到,这里再一次应用taskflow模式来实现通过调度器选取目标主机并实现建立卷的操作,taskflow模式的具体应用方法在前面的博客中我们已经进行过详细的解析,这里不再赘述,这里我们只是简单的看看源码实现:
  1. def get_scheduler_flow(db, driver, request_spec=None, filter_properties=None,  
  2.                        volume_id=None, snapshot_id=None, image_id=None):  
  3.   
  4.     """
  5.     Constructs and returns the scheduler entrypoint flow.
  6.     构建并返回用于通过远程调度建立卷的flow;
  7.     flow将会做以下的事情:
  8.     1. 为相关的task注入keys和values;
  9.     2. 实现了从输入的参数中提取调度器的规范信息的操作;
  10.     3. 对于出错的task进行处理,发送错误通知,记录错误信息等;
  11.     4. 远程调用实现在主机上建立卷;
  12.     """  
  13.   
  14.     # flow_name:volume_create_scheduler;  
  15.     flow_name = ACTION.replace(":", "_") + "_scheduler"  
  16.     # 获取类Flow的实例化对象;  
  17.     scheduler_flow = linear_flow.Flow(flow_name)  
  18.   
  19.     # This injects the initial starting flow values into the workflow so that  
  20.     # the dependency order of the tasks provides/requires can be correctly  
  21.     # determined.  
  22.     # 添加一个给定的task到flow;  
  23.     # 这个类实现了注入字典信息到flow中;  
  24.     scheduler_flow.add(base.InjectTask({  
  25.         'request_spec': request_spec,  
  26.         'filter_properties': filter_properties,  
  27.         'volume_id': volume_id,  
  28.         'snapshot_id': snapshot_id,  
  29.         'image_id': image_id,  
  30.     }, addons=[ACTION]))  
  31.   
  32.     # This will extract and clean the spec from the starting values.  
  33.     # 添加一个给定的task到flow;  
  34.     # ExtractSchedulerSpecTask:实现了从输入的参数中提取调度器的规范信息的操作;  
  35.     scheduler_flow.add(ExtractSchedulerSpecTask(db))  
  36.   
  37.     # The decorator application here ensures that the method gets the right  
  38.     # requires attributes automatically by examining the underlying functions  
  39.     # arguments.  
  40.     @decorators.task  
  41.     def schedule_create_volume(context, request_spec, filter_properties):  
  42.         """
  43.         实现通过合适的调度器算法选择建立卷的主机,并实现卷的建立;
  44.         """  
  45.   
  46.         def _log_failure(cause):  
  47.             """
  48.             记录错误信息;
  49.             """  
  50.             LOG.error(_("Failed to schedule_create_volume: %(cause)s") %  
  51.                       {'cause': cause})  
  52.   
  53.         def _notify_failure(cause):  
  54.             """
  55.             When scheduling fails send out a event that it failed.
  56.             当调度出现错误时,则发送一个标志为错误的事件通知;
  57.             """  
  58.             topic = "scheduler.create_volume"  
  59.             payload = {  
  60.                 'request_spec': request_spec,  
  61.                 'volume_properties': request_spec.get('volume_properties', {}),  
  62.                 'volume_id': volume_id,  
  63.                 'state': 'error',  
  64.                 'method': 'create_volume',  
  65.                 'reason': cause,  
  66.             }  
  67.             try:  
  68.                 publisher_id = notifier.publisher_id("scheduler")  
  69.                 notifier.notify(context, publisher_id, topic, notifier.ERROR,  
  70.                                 payload)  
  71.             except exception.CinderException:  
  72.                 LOG.exception(_("Failed notifying on %(topic)s "  
  73.                                 "payload %(payload)s") % {'topic': topic,  
  74.                                                           'payload': payload})  
  75.   
  76.         try:  
  77.             # 目前cinder中提供了三种调度器方法实现建立卷的主机的选择,并实现卷的建立;  
  78.             driver.schedule_create_volume(context, request_spec, filter_properties)  
  79.         except exception.NoValidHost as e:  
  80.             # Not host found happened, notify on the scheduler queue and log  
  81.             # that this happened and set the volume to errored out and  
  82.             # *do not* reraise the error (since whats the point).  
  83.             # 当调度出现错误时,则发送一个标志为错误的事件通知;  
  84.             _notify_failure(e)  
  85.             # 记录错误信息;  
  86.             _log_failure(e)  
  87.             _error_out_volume(context, db, volume_id, reason=e)  
  88.         except Exception as e:  
  89.             # Some other error happened, notify on the scheduler queue and log  
  90.             # that this happened and set the volume to errored out and  
  91.             # *do* reraise the error.  
  92.             with excutils.save_and_reraise_exception():  
  93.                 _notify_failure(e)  
  94.                 _log_failure(e)  
  95.                 _error_out_volume(context, db, volume_id, reason=e)  
  96.   
  97.     # 添加一个给定的task到flow;  
  98.     # schedule_create_volume:<span style="font-family:KaiTi_GB2312;">通过调度器获取目标主机并实现远程调用建立新卷的操作</span>;  
  99.     scheduler_flow.add(schedule_create_volume)  
  100.   
  101.     # 获取flow的调试信息;  
  102.     return flow_utils.attach_debug_listeners(scheduler_flow)
复制代码



在这个方法中,构建了flow任务流对象,并注入了三个task任务对象,其中前两个任务主要是完成若干信息数据的注入和获取,其中最重要的任务就是第三个任务,即通过调度器获取目标主机并实现远程调用建立新卷的操作。我们来看其具体实现方法的源码:
  1. @decorators.task  
  2. def schedule_create_volume(context, request_spec, filter_properties):  
  3.     """
  4.     实现通过合适的调度器算法选择建立卷的主机,并实现卷的建立;
  5.     """  
  6.   
  7.     def _log_failure(cause):  
  8.         """
  9.         记录错误信息;
  10.         """  
  11.         LOG.error(_("Failed to schedule_create_volume: %(cause)s") %  
  12.                   {'cause': cause})  
  13.   
  14.     def _notify_failure(cause):  
  15.         """
  16.         When scheduling fails send out a event that it failed.
  17.         当调度出现错误时,则发送一个标志为错误的事件通知;
  18.         """  
  19.         topic = "scheduler.create_volume"  
  20.         payload = {  
  21.             'request_spec': request_spec,  
  22.             'volume_properties': request_spec.get('volume_properties', {}),  
  23.             'volume_id': volume_id,  
  24.             'state': 'error',  
  25.             'method': 'create_volume',  
  26.             'reason': cause,  
  27.         }  
  28.         try:  
  29.             publisher_id = notifier.publisher_id("scheduler")  
  30.             notifier.notify(context, publisher_id, topic, notifier.ERROR,  
  31.                             payload)  
  32.         except exception.CinderException:  
  33.             LOG.exception(_("Failed notifying on %(topic)s "  
  34.                             "payload %(payload)s") % {'topic': topic,  
  35.                                                       'payload': payload})  
  36.   
  37.     try:  
  38.         # 目前cinder中提供了三种调度器方法实现建立卷的主机的选择,并实现卷的建立;  
  39.         driver.schedule_create_volume(context, request_spec, filter_properties)  
  40.     except exception.NoValidHost as e:  
  41.         # Not host found happened, notify on the scheduler queue and log  
  42.         # that this happened and set the volume to errored out and  
  43.         # *do not* reraise the error (since whats the point).  
  44.         # 当调度出现错误时,则发送一个标志为错误的事件通知;  
  45.         _notify_failure(e)  
  46.         # 记录错误信息;  
  47.         _log_failure(e)  
  48.         _error_out_volume(context, db, volume_id, reason=e)  
  49.     except Exception as e:  
  50.         # Some other error happened, notify on the scheduler queue and log  
  51.         # that this happened and set the volume to errored out and  
  52.         # *do* reraise the error.  
  53.         with excutils.save_and_reraise_exception():  
  54.             _notify_failure(e)  
  55.             _log_failure(e)  
  56.             _error_out_volume(context, db, volume_id, reason=e)  
复制代码

   
这个方法中最重要的语句就是:
driver.schedule_create_volume(context, request_spec, filter_properties)
这条语句所实现的作用就是调用指定的调度器算法实现目标主机的确定,并实现新卷的建立的操作。在H版的cinder模块中,暂时实现了三个调度器算法,即过滤-承重算法、随机获取主机算法和选取建立卷数量最少作为目标主机的算法。这里所调用的方法是由driver所确定的;
我们在类SchedulerManager的初始化方法中可以看到:
if not scheduler_driver:
    scheduler_driver = CONF.scheduler_driver
self.driver = importutils.import_object(scheduler_driver)
所以具体调度器算法的确定就是由变量scheduler_driver所确定的,我们又可以看到:
scheduler_driver_opt = cfg.StrOpt('scheduler_driver',
                                  default='cinder.scheduler.filter_scheduler.'
                                          'FilterScheduler',
                                  help='Default scheduler driver to use')
所以系统默认的调度器算法为:
cinder.scheduler.filter_scheduler.FilterScheduler.schedule_create_volume,所以我们先来看这个方法的源码实现:
  1. def schedule_create_volume(self, context, request_spec, filter_properties):  
  2.     """
  3.     对主机进行过滤和称重操作,获取最优主机,并实现远程调用建立并导出卷;
  4.     """  
  5.     # 对主机进行过滤称重操作,获取最优的主机;  
  6.     weighed_host = self._schedule(context, request_spec, filter_properties)  
  7.   
  8.     if not weighed_host:  
  9.         raise exception.NoValidHost(reason="")  
  10.   
  11.     host = weighed_host.obj.host  
  12.     volume_id = request_spec['volume_id']  
  13.     snapshot_id = request_spec['snapshot_id']  
  14.     image_id = request_spec['image_id']  
  15.   
  16.     # @@@@在卷上设置给定的属性,并进行更新;  
  17.     updated_volume = driver.volume_update_db(context, volume_id, host)  
  18.     # @@@@在最优主机选定之后,添加附加信息到过滤器属性;  
  19.     self._post_select_populate_filter_properties(filter_properties,  
  20.                                                  weighed_host.obj)  
  21.   
  22.     # context is not serializable  
  23.     filter_properties.pop('context', None)  
  24.   
  25.     # create_volume:远程调用实现建立并导出卷;  
  26.     self.volume_rpcapi.create_volume(context, updated_volume, host,  
  27.                                      request_spec, filter_properties,  
  28.                                      allow_reschedule=True,  
  29.                                      snapshot_id=snapshot_id,  
  30.                                      image_id=image_id)  
复制代码

   
这里采用了对所有可用主机进行过滤和称重操作来实现确定目标主机,并调用create_volume方法实现远程调用在目标主机上建立新卷的操作。具体方法实现比较简单,脉络比较清晰,所以这里不进行详细的解析。
我们再来看随机选取目标主机的调度器算法的源码实现:
  1. def schedule_create_volume(self, context, request_spec, filter_properties):  
  2.     """
  3.     Picks a host that is up at random.
  4.     实现随机选取主机;
  5.     远程调用实现在选取的主机上建立并导出卷;
  6.     """  
  7.     topic = CONF.volume_topic  
  8.     # _schedule:实现随机选取主机;  
  9.     host = self._schedule(context, topic, request_spec,  
  10.                           filter_properties=filter_properties)  
  11.     volume_id = request_spec['volume_id']  
  12.     snapshot_id = request_spec['snapshot_id']  
  13.     image_id = request_spec['image_id']  
  14.   
  15.     # volume_update_db:在给定的卷的数据库中设置属性信息并进行更新;  
  16.     updated_volume = driver.volume_update_db(context, volume_id, host)  
  17.     # create_volume:远程调用实现建立并导出卷;  
  18.     self.volume_rpcapi.create_volume(context, updated_volume, host,  
  19.                                      request_spec, filter_properties,  
  20.                                      snapshot_id=snapshot_id,  
  21.                                      image_id=image_id)  
复制代码

   
我们也可以看到在这个方法中,也调用create_volume方法实现远程调用在目标主机上建立新卷的操作;
我们再来看选取最少卷作为目标主机的调度器算法的源码实现:
  1. def schedule_create_volume(self, context, request_spec, filter_properties):  
  2.     """
  3.     Picks a host that is up and has the fewest volumes.
  4.     选取拥有最少卷的主机作为目标主机;
  5.     """  
  6.     elevated = context.elevated()  
  7.   
  8.     volume_id = request_spec.get('volume_id')  
  9.     snapshot_id = request_spec.get('snapshot_id')  
  10.     image_id = request_spec.get('image_id')  
  11.     volume_properties = request_spec.get('volume_properties')  
  12.     volume_size = volume_properties.get('size')  
  13.     availability_zone = volume_properties.get('availability_zone')  
  14.   
  15.     zone, host = None, None  
  16.     if availability_zone:  
  17.         zone, _x, host = availability_zone.partition(':')  
  18.     if host and context.is_admin:  
  19.         topic = CONF.volume_topic  
  20.         service = db.service_get_by_args(elevated, host, topic)  
  21.         if not utils.service_is_up(service):  
  22.             raise exception.WillNotSchedule(host=host)  
  23.         updated_volume = driver.volume_update_db(context, volume_id, host)  
  24.         self.volume_rpcapi.create_volume(context, updated_volume, host,  
  25.                                          request_spec, filter_properties,  
  26.                                          snapshot_id=snapshot_id,  
  27.                                          image_id=image_id)  
  28.         return None  
  29.   
  30.     results = db.service_get_all_volume_sorted(elevated)  
  31.     if zone:  
  32.         results = [(s, gigs) for (s, gigs) in results  
  33.                    if s['availability_zone'] == zone]  
  34.     for result in results:  
  35.         (service, volume_gigabytes) = result  
  36.         if volume_gigabytes + volume_size > CONF.max_gigabytes:  
  37.             msg = _("Not enough allocatable volume gigabytes remaining")  
  38.             raise exception.NoValidHost(reason=msg)  
  39.         if utils.service_is_up(service) and not service['disabled']:  
  40.             updated_volume = driver.volume_update_db(context, volume_id,  
  41.                                                      service['host'])  
  42.             self.volume_rpcapi.create_volume(context, updated_volume,  
  43.                                              service['host'], request_spec,  
  44.                                              filter_properties,  
  45.                                              snapshot_id=snapshot_id,  
  46.                                              image_id=image_id)  
  47.             return None  
  48.     msg = _("Is the appropriate service running?")  
  49.     raise exception.NoValidHost(reason=msg)
复制代码

   
我们也可以看到在这个方法中,也调用了create_volume方法实现远程调用在目标主机上建立新卷的操作;
我们可以看到,在这三个调度器算法中,最后都调用了方法create_volume实现远程调用在目标主机上建立新卷的操作。我们再回到方法_cast_create_volume中,可以看到也是调用了create_volume方法实现远程调用在目标主机上建立新卷的目标。
对于方法create_volume的实现过程,我将会在下一篇博客中进行详细解析。


相关文章:
Openstack Cinder中建立volume过程的源码解析(1)
http://www.aboutyun.com/thread-10217-1-1.html
1.cinder中卷的建立的过程中,客户端传递过来的request的执行过程是怎样的?
2.__call__方法都通过什么方法封装?
3.如何调用指定中间件的__call__方法?


Openstack Cinder中建立volume过程的源码解析(2)
http://www.aboutyun.com/thread-10216-1-1.html
1.如何获取要执行的action方法及其相关的扩展方法?
2.Resource类中的__call__(self,request)方法如何实现?
3.meth的作用?
4.如何从request.environ中获取要执行的action方法?
5.如何对body进行反序列化操作?


Openstack Cinder中建立volume过程的源码解析(3)
http://www.aboutyun.com/thread-10215-1-1.html
1.get_serializer的作用?
2.isgeneratorfunction是用来做什么的?
3.什么是特殊的generator方法?
4.进行响应信息的序列化操作的步骤?
5.简述在cinder模块中实现客户端发送过来的请求信息操作的主要的步骤?

Openstack Cinder中建立volume过程的源码解析(4)----以及taskflow相关解析
http://www.aboutyun.com/thread-10214-1-1.html
1.简述cinder是如何实现卷的建立的?
2.简述taskflow库来实现卷的简历过程?
3.如何根据给定id来检索获取单个的卷的类型?
4.如何构建并返回用于建立卷的flow?
5.如何声明flow是否是真的?
6.简述建立卷的flow的步骤?


Openstack Cinder中建立volume过程的源码解析(5)----以及taskflow相关解析
http://www.aboutyun.com/thread-10213-1-1.html
1.如何实现Flow类的初始化的?
2.用于卷的建立的flow中都添加了哪些task?
3.ExtractVolumeRequestTask类的作用是什么?
4.如何完全或部分的重置flow的内部的状态?
5.如何从给定的卷中提取卷的id信息?
6.OnFailureChangeStatusTask类的作用?

Openstack Cinder中建立volume过程的源码解析(6)----以及taskflow相关解析
http://www.aboutyun.com/thread-10212-1-1.html
1.如何来运行已经构建好的flow?
2.run的源码如何实现及实现过程是什么?
3.resume_it的实现过程是什么?
4.类Runner的初始化方法是什么?
5.run_it的源码如何实现?

Openstack Cinder中建立volume过程的源码解析(7)----以及taskflow相关解析
http://www.aboutyun.com/thread-10211-1-1.html
1.关于flow中task执行的重要语句的实现基本解析完成,如何实现?
2.如果卷的建立出现异常,则如何执行相关的逆转回滚操作?




Openstack Cinder中建立volume过程的源码解析(9)
http://www.aboutyun.com/thread-10210-1-1.html
1.如何实现create_volume的源码?
2.Cast如何实现远程调create_volume?
3.如何实现调用方法self.volume_rpcapi.create_volume来实现在目标主机上新卷的建立?




转自:http://blog.csdn.net/gaoxingnengjisuan/article/details/23789533






没找到任何评论,期待你打破沉寂

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

本版积分规则

关闭

推荐上一条 /2 下一条