从volume_rpcapi delete_volume开始删除volume
self.volume_rpcapi.delete_volume(context,
volume,
unmanage_only,
cascade)
def delete_volume(self, ctxt, volume, unmanage_only=False, cascade=False):
volume.create_worker()
cctxt = self._get_cctxt(volume.service_topic_queue) 这个cctxt是封闭context的地方,不过个 volume.service_topic_queue从字面上看是topic的名字,
msg_args = {
'volume': volume, 'unmanage_only': unmanage_only,
'cascade': cascade,
}
cctxt.cast(ctxt, 'delete_volume', **msg_args)
volume.service_topic_queue 这里其实我还看了点时间, 从数据库里查找字段,发现根本没有,去objects里的volumes.py里找,也没看到,这就奇怪了,于是多调试了下,并看了下继承,发现原来是在base.py里的ClusteredObject
class ClusteredObject(object):
@property
def service_topic_queue(self):
return self.cluster_name or self.host 原来是host字段
现在终于名字了,这个是取host字段值,名字写的这么高大上,有点名不副实的感觉。
def _get_cctxt(self, host=None, version=None, **kwargs):
if host:
server = utils.extract_host(host)
# TODO(dulek): If we're pinned before 3.6, we should send stuff the
# old way - addressing server=host@backend, topic=cinder-volume.
# Otherwise we're addressing server=host,
# topic=cinder-volume.host@backend. This conditional can go away
# when we stop supporting 3.x.
if self.client.can_send_version('3.6'):
kwargs['topic'] = '%(topic)s.%(host)s' % {'topic': self.TOPIC, #这里到组装topic了,topic=self.TOPIC.host 这个host就是service_topic_queue 取出来的值
'host': server} server = utils.extract_host(server, 'host') kwargs['server'] = server return super(VolumeAPI, self)._get_cctxt(version=version, **kwargs)
分析完毕。