您好,登錄后才能下訂單哦!
如何進行nova.api.openstack.APIRouterV21模塊的解析,針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
nova.api.openstack.APIRouterV21模塊的解析:
from nova import wsgi as base_wsgi class APIRouterV21(base_wsgi.Router):""" 將OpenStack v2.1 API上的請求路由到適當的控制器和方法。 """ @classmethod def factory(cls, global_config, **local_config):"""paste factory 方法, 在/etc/nova/api-paste.ini里的[app:osapi_compute_app_v21]調用""" return cls()@staticmethod def api_extension_namespace(): """定義插件命名空間 """ return 'nova.api.v21.extensions' def __init__(self):def _check_load_extension(ext):return self._register_extension(ext) #通過stevedore 動態加載插件self.api_extension_manager = stevedore.enabled.EnabledExtensionManager(namespace=self.api_extension_namespace(),check_func=_check_load_extension,invoke_on_load=True,invoke_kwds={"extension_info": self.loaded_extension_info}) mapper = ProjectMapper()#Routes映射器,此類是nova對routes.Mapper的繼承重載self.resources = {}# 核心API支持被重寫為擴展, 但在概念上仍然具有核心性 if list(self.api_extension_manager):# 如果沒有檢測到插件,Stevedore將引發異常。 self._register_resources_check_inherits(mapper)self.api_extension_manager.map(self._register_controllers) LOG.info(_LI("Loaded extensions: %s"), sorted(self.loaded_extension_info.get_extensions().keys()))super(APIRouterV21, self).__init__(mapper)def _register_resources_list(self, ext_list, mapper):for ext in ext_list:self._register_resources(ext, mapper)def _register_resources_check_inherits(self, mapper): ext_has_inherits = [] ext_no_inherits = []for ext in self.api_extension_manager:for resource in ext.obj.get_resources():if resource.inherits: ext_has_inherits.append(ext)break else: ext_no_inherits.append(ext)self._register_resources_list(ext_no_inherits, mapper)self._register_resources_list(ext_has_inherits, mapper)@property def loaded_extension_info(self):raise NotImplementedError()def _register_extension(self, ext):raise NotImplementedError()def _register_resources(self, ext, mapper):""" 注冊由extensions定義的資源 Extensions通過get_resources函數定義要添加的資源 """ handler = ext.obj LOG.debug("Running _register_resources on %s", ext.obj)for resource in handler.get_resources(): LOG.debug('Extended resource: %s', resource.collection) inherits = None if resource.inherits: inherits = self.resources.get(resource.inherits)if not resource.controller: resource.controller = inherits.controller wsgi_resource = wsgi.ResourceV21(resource.controller, inherits=inherits)self.resources[resource.collection] = wsgi_resource kargs = dict(controller=wsgi_resource,collection=resource.collection_actions,member=resource.member_actions)if resource.parent: kargs['parent_resource'] = resource.parent# 非核心api插件使用collection名稱作為member名稱, # 但是core-API插件對member/collection名稱使用單復數約定 if resource.member_name: member_name = resource.member_nameelse: member_name = resource.collection mapper.resource(member_name, resource.collection, **kargs)if resource.custom_routes_fn: resource.custom_routes_fn(mapper, wsgi_resource)def _register_controllers(self, ext):""" 注冊由extensions定義的控制器 通過get_controller_extensions函數Extensions定義要添加的資源""" handler = ext.obj LOG.debug("Running _register_controllers on %s", ext.obj)for extension in handler.get_controller_extensions(): ext_name = extension.extension.name collection = extension.collection controller = extension.controllerif collection not in self.resources: LOG.warning(_LW('Extension %(ext_name)s: Cannot extend ' 'resource %(collection)s: No such resource'), {'ext_name': ext_name, 'collection': collection})continue LOG.debug('Extension %(ext_name)s extending resource: ' '%(collection)s', {'ext_name': ext_name, 'collection': collection}) resource = self.resources[collection] resource.register_actions(controller) resource.register_extensions(controller)
關于如何進行nova.api.openstack.APIRouterV21模塊的解析問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注億速云行業資訊頻道了解更多相關知識。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。