文章目录
  1. 1. 启动
    1. 1.0.1. to be continued

从openstack的nova开始先介绍,在openstack的组件中,基本每个组件都会有一个API服务,对于Nova来说API服务主要的作用就是接收由用户通过Client或者一些其他REST请求工具(比如curl、postman)发送的请求。一般来说会包含一些虚拟机创建的参数,比如虚拟机的规格、可用域之类的信息。

启动

我们在启动nova-api会使用service openstack-nova-api start命令,查看该服务启动的是/usr/bin/nova-api

  1. nova/cmd/api.py def main(): #启动进程

    功能:载入配置文件、启动进程数(默认cpu核数)、根据配置文件中的enabled_apis启动不同WSGIService

    nova.conf

    enabled_apis=ec2,osapi_compute,metadata

    ec2 亚马逊云主机

    osapi_compute openstack云主机

    metadata 元数据

    我们主要看osapi_compute

  2. nova/service.py class WSGIService(service.Service):

    功能加载/etc/nova/api-paste.ini(这里用到了deploy模块解释:https://www.cnblogs.com/Security-Darren/p/4087587.html

  3. etc/nova/api-paste.ini

    [composite:osapi_compute]

    use = call:nova.api.openstack.urlmap:urlmap_factory

    解析url调用 urlmap_factory

  4. nova/api/openstack/urlmap.py

    def urlmap_factory(loader, global_conf, **local_conf):

    #loader是上面加在的app的loader,这里是osapi_compute

    #global_conf = {‘file‘: ‘/etc/nova/api-paste.ini’, ‘here’: ‘/etc/nova’}

    #local_conf = {‘/v2’: ‘openstack_compute_api_v21_legacy_v2_compatible’, ‘/‘: ‘oscomputeversions’, ‘/v2.1’: ‘openstack_compute_api_v21’}

    该方法将osapi_compute 转换为 openstack_compute_api_v21_legacy_v2_compatible

    [composite:openstack_compute_api_v21_legacy_v2_compatible]

    use = call:nova.api.auth:pipeline_factory_v21

    noauth2 = cors http_proxy_to_wsgi compute_req_id faultwrap request_log sizelimit osprofiler noauth2 legacy_v2_compatible osapi_compute_app_v21

    keystone = cors http_proxy_to_wsgi compute_req_id faultwrap request_log sizelimit osprofiler authtoken keystonecontext legacy_v2_compatible osapi_compute_app_v21

  5. nova/api/auth.py

    def pipeline_factory_v21(loader, global_conf, **local_conf):

    #使用keystone验证 类似Django midware看keystone最后一项osapi_compute_app_v21

  6. [app:osapi_compute_app_v21]

    paste.app_factory = nova.api.openstack.compute:APIRouterV21.factory

    Nova/api/openstack/compute/routes.py

    class APIRouterV21(base_wsgi.Router): #最终url解析(flavor、show…)

    贴一个调用流程图,新版加入了nova-cell这里是个简易版

    先介绍这里,剩下就是nova-conductor、nova-scheduler、nova-coumpute的rpc调用

to be continued
文章目录
  1. 1. 启动
    1. 1.0.1. to be continued