执行openstack flavor list后,通过在/nova/api/openstack/compute/flavors.py中FlavorsController类detail()方法添加断点,具体如下:
def detail(self, req): """Return all flavors in detail.""" import pydevd pydevd.settrace(‘localhost‘, port=12345, stdoutToServer=True, stderrToServer=True) limited_flavors = self._get_flavors(req) #调用方法从数据库里获取到flavors req.cache_db_flavors(limited_flavors) #。。。 return self._view_builder.detail(req, limited_flavors) #_view_builder是一个class ViewBuilder(common.ViewBuilder)对象,在views/flavors.py文件中
可以获取到,nova是如何查询到flavors并返回给client。
首先,我们查看req请求包含的内容:
GET /compute/v2.1/flavors/detail HTTP/1.1 Accept: application/json Accept-Encoding: gzip, deflate Connection: keep-alive Content-Length: 0 Host: 192.168.72.192 User-Agent: python-novaclient X-Auth-Token: gAAAAABacqw9UtQcB8_Mwcjp72aGSy0amSoOX7rj0TO1m1wehcY9Oz3Rcppc4i1iv59J49NGk3Mms-t9BuV0MmOEaQQFXbcr2ImnY6ATDbctEn8Ve13rbv1yUaIgqTKdK5X0oLMzyaWcs5ORqAj0eAB0McQOlvVa5MZvuFxbm8k3uPHKEmW71Ac X-Domain-Id: None X-Domain-Name: None X-Identity-Status: Confirmed X-Is-Admin-Project: True X-Project-Domain-Id: default X-Project-Domain-Name: Default X-Project-Id: 220a18a8c961468f93f1d5b81de9774f X-Project-Name: demo X-Role: Member,anotherrole X-Roles: Member,anotherrole X-Service-Catalog: [{"endpoints": [{"region": "RegionOne", "publicURL": "http://192.168.72.192/compute/v2/220a18a8c961468f93f1d5b81de9774f"}], "type": "compute_legacy", "name": "nova_legacy"}, {"endpoints": [{"region": "RegionOne", "publicURL": "http://192.168.72.192:9696/"}], "type": "network", "name": "neutron"}, {"endpoints": [{"adminURL": "http://192.168.72.192/identity", "region": "RegionOne", "publicURL": "http://192.168.72.192/identity"}], "type": "identity", "name": "keystone"}, {"endpoints": [{"region": "RegionOne", "publicURL": "http://192.168.72.192/volume/v1/220a18a8c961468f93f1d5b81de9774f"}], "type": "volume", "name": "cinder"}, {"endpoints": [{"region": "RegionOne", "publicURL": "http://192.168.72.192/placement"}], "type": "placement", "name": "placement"}, {"endpoints": [{"region": "RegionOne", "publicURL": "http://192.168.72.192/volume/v3/220a18a8c961468f93f1d5b81de9774f"}], "type": "volumev3", "name": "cinderv3"}, {"endpoints": [{"region": "RegionOne", "publicURL": "http://192.168.72.192/compute/v2.1"}], "type": "compute", "name": "nova"}, {"endpoints": [{"region": "RegionOne", "publicURL": "http://192.168.72.192/volume/v2/220a18a8c961468f93f1d5b81de9774f"}], "type": "volumev2", "name": "cinderv2"}, {"endpoints": [{"region": "RegionOne", "publicURL": "http://192.168.72.192/image"}], "type": "image", "name": "glance"}] X-Tenant: demo X-Tenant-Id: 220a18a8c961468f93f1d5b81de9774f X-Tenant-Name: demo X-User: demo X-User-Domain-Id: default X-User-Domain-Name: Default X-User-Id: 159ceecc04924edd95f698e28772929b X-User-Name: demo
使用了GET方法,具体的url=/compute/v2.1/flavors/detail,X-Auth-Token应该是keystone给的token认证。X-***给出的是一些工程、租户、用户等相关的信息。然后,使用limited_flavors=self._get_flavors(req)获取到flavors的信息,return self._view_builder.detail(req, limited_flavors)对返回的flavor信息做了进一步处理,满足返回请求的需要。
本文的分析没有关注wsgi框架中如何载入app,以及如何建立RESTFUL框架的问题,而是直接从请求APP入口去分析openstack组件将如何去响应各种请求。
关于不同请求是如何与相应app对应,在后续介绍。