• openstack nova 深入


    一、概述:

      由nova --debug list查看到:

    #nova --debug list
    DEBUG (session:195) REQ: curl -g -i -X GET http://192.168.39.172:5000/v2.0 -H "Accept: application/json" -H "User-Agent: python-keystoneclient"
    INFO (connectionpool:203) Starting new HTTP connection (1): 192.168.39.172
    DEBUG (connectionpool:383) "GET /v2.0 HTTP/1.1" 200 340
    DEBUG (session:224) RESP: [200] content-length: 340 vary: X-Auth-Token connection: keep-alive date: Tue, 06 Jun 2017 08:18:26 GMT content-type: application/json x-openstack-request-id: req-7a31faa4-497d-46e2-a137-51255744bd01 
    RESP BODY: {"version": {"status": "stable", "updated": "2014-04-17T00:00:00Z", "media-types": [{"base": "application/json", "type": "application/vnd.openstack.identity-v2.0+json"}], "id": "v2.0", "links": [{"href": "http://192.168.39.172:5000/v2.0/", "rel": "self"}, {"href": "http://docs.openstack.org/", "type": "text/html", "rel": "describedby"}]}}
    
    DEBUG (v2:76) Making authentication request to http://192.168.39.172:5000/v2.0/tokens
    DEBUG (connectionpool:383) "POST /v2.0/tokens HTTP/1.1" 200 3327
    DEBUG (session:195) REQ: curl -g -i -X GET http://192.168.39.172:8774/v2/b8a56795b6d749cd8434f841868ee6a4/servers/detail -H "User-Agent: python-novaclient" -H "Accept: application/json" -H "X-Auth-Token: {SHA1}eaa78ad5bbad815caccc425100e97714d032eb71"
    INFO (connectionpool:203) Starting new HTTP connection (1): 192.168.39.172
    DEBUG (connectionpool:383) "GET /v2/b8a56795b6d749cd8434f841868ee6a4/servers/detail HTTP/1.1" 200 4848
    DEBUG (session:224) RESP: [200] date: Tue, 06 Jun 2017 08:18:26 GMT connection: keep-alive content-type: application/json content-length: 4848 x-compute-request-id: req-0452bc14-9ae0-46ad-b857-4102a0a23d72 
    RESP BODY: {"servers": [{"status": "ACTIVE", "updated": "2017-06-05T03:31:36Z", "hostId": "4c820983066e6ff21f0753adca9b55e75797235c0fb8fa1141efab4d", "OS-EXT-SRV-ATTR:host": "TS-M2-Cloud173", "addresses": {"NW": [{"OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:d5:ed:11", "version": 4, "addr": "192.168.0.189", "OS-EXT-IPS:type": "fixed"}]}, "links": [{"href": "http://192.168.39.172:8774/v2/b8a56795b6d749cd8434f841868ee6a4/servers/2e3dd89c-ad59-4499-a3ff-6444ca74f7c3", "rel": "self"}, {"href": "http://192.168.39.172:8774/b8a56795b6d749cd8434f841868ee6a4/servers/2e3dd89c-ad59-4499-a3ff-6444ca74f7c3", "rel": "bookmark"}], "key_name": null, "image": "", "OS-EXT-STS:task_state": null, "OS-EXT-STS:vm_state": "active", "OS-EXT-SRV-ATTR:instance_name": "instance-000000d1", "OS-SRV-USG:launched_at": "2017-05-25T07:12:27.000000", "OS-EXT-SRV-ATTR:hypervisor_hostname": "TS-M2-Cloud173", "flavor": {"id": "c0540dff-eadd-44b2-a6d4-a4f74409b9c4", "links": [{"href": "http://192.168.39.172:8774/b8a56795b6d749cd8434f841868ee6a4/flavors/c0540dff-eadd-44b2-a6d4-a4f74409b9c4", "rel": "bookmark"}]}, "id": "2e3dd89c-ad59-4499-a3ff-6444ca74f7c3", "security_groups": [{"name": "default"}], "OS-SRV-USG:terminated_at": null, "OS-EXT-AZ:availability_zone": "ACTIVE", "user_id": "c2102ee1835440e39eea98cf264f118e", "name": "New", "created": "2017-05-25T07:11:56Z", "tenant_id": "b8a56795b6d749cd8434f841868ee6a4", "OS-DCF:diskConfig": "AUTO", "os-extended-volumes:volumes_attached": [{"id": "a79fe8d0-efe9-47be-a54e-033a1ad08f71"}], "accessIPv4": "", "accessIPv6": "", "progress": 0, "OS-EXT-STS:power_state": 1, "config_drive": "", "metadata": {}}, {"status": "ACTIVE", "updated": "2017-05-25T07:12:57Z", "hostId": "fbd0e31d7dd6d0f516942bc9b19f6a1733e0108121008d884e44d5b9", "OS-EXT-SRV-ATTR:host": "TS-M2-Cloud177", "addresses": {"NW": [{"OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:12:a4:f0", "version": 4, "addr": "192.168.0.188", "OS-EXT-IPS:type": "fixed"}]}, "links": [{"href": "http://192.168.39.172:8774/v2/b8a56795b6d749cd8434f841868ee6a4/servers/8e61920f-150a-43e9-addd-85e3108ea771", "rel": "self"}, {"href": "http://192.168.39.172:8774/b8a56795b6d749cd8434f841868ee6a4/servers/8e61920f-150a-43e9-addd-85e3108ea771", "rel": "bookmark"}], "key_name": null, "image": "", "OS-EXT-STS:task_state": null, "OS-EXT-STS:vm_state": "active", "OS-EXT-SRV-ATTR:instance_name": "instance-000000d0", "OS-SRV-USG:launched_at": "2017-05-25T07:12:56.000000", "OS-EXT-SRV-ATTR:hypervisor_hostname": "TS-M2-Cloud177", "flavor": {"id": "c0540dff-eadd-44b2-a6d4-a4f74409b9c4", "links": [{"href": "http://192.168.39.172:8774/b8a56795b6d749cd8434f841868ee6a4/flavors/c0540dff-eadd-44b2-a6d4-a4f74409b9c4", "rel": "bookmark"}]}, "id": "8e61920f-150a-43e9-addd-85e3108ea771", "security_groups": [{"name": "default"}], "OS-SRV-USG:terminated_at": null, "OS-EXT-AZ:availability_zone": "ACTIVE", "user_id": "c2102ee1835440e39eea98cf264f118e", "name": "test-1", "created": "2017-05-25T07:11:55Z", "tenant_id": "b8a56795b6d749cd8434f841868ee6a4", "OS-DCF:diskConfig": "AUTO", "os-extended-volumes:volumes_attached": [{"id": "dfc6abad-49bd-40a9-a7a5-4c868eb9e211"}], "accessIPv4": "", "accessIPv6": "", "progress": 0, "OS-EXT-STS:power_state": 1, "config_drive": "", "metadata": {}}, {"status": "ACTIVE", "updated": "2017-05-19T03:35:37Z", "hostId": "fbd0e31d7dd6d0f516942bc9b19f6a1733e0108121008d884e44d5b9", "OS-EXT-SRV-ATTR:host": "TS-M2-Cloud177", "addresses": {"Office": [{"OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:82:15:4e", "version": 4, "addr": "192.168.39.68", "OS-EXT-IPS:type": "fixed"}]}, "links": [{"href": "http://192.168.39.172:8774/v2/b8a56795b6d749cd8434f841868ee6a4/servers/34f0b3a5-4142-4276-b27d-bac7c64f9f90", "rel": "self"}, {"href": "http://192.168.39.172:8774/b8a56795b6d749cd8434f841868ee6a4/servers/34f0b3a5-4142-4276-b27d-bac7c64f9f90", "rel": "bookmark"}], "key_name": null, "image": "", "OS-EXT-STS:task_state": null, "OS-EXT-STS:vm_state": "active", "OS-EXT-SRV-ATTR:instance_name": "instance-000000c8", "OS-SRV-USG:launched_at": "2017-05-19T03:35:37.000000", "OS-EXT-SRV-ATTR:hypervisor_hostname": "TS-M2-Cloud177", "flavor": {"id": "665a38e6-6f80-4dc2-ad97-89ca335358e6", "links": [{"href": "http://192.168.39.172:8774/b8a56795b6d749cd8434f841868ee6a4/flavors/665a38e6-6f80-4dc2-ad97-89ca335358e6", "rel": "bookmark"}]}, "id": "34f0b3a5-4142-4276-b27d-bac7c64f9f90", "security_groups": [{"name": "default"}], "OS-SRV-USG:terminated_at": null, "OS-EXT-AZ:availability_zone": "ACTIVE", "user_id": "c2102ee1835440e39eea98cf264f118e", "name": "test01", "created": "2017-05-19T03:35:24Z", "tenant_id": "b8a56795b6d749cd8434f841868ee6a4", "OS-DCF:diskConfig": "AUTO", "os-extended-volumes:volumes_attached": [{"id": "48e6d225-c43e-41a3-8890-8a3d40b4a38e"}], "accessIPv4": "", "accessIPv6": "", "progress": 0, "OS-EXT-STS:power_state": 1, "config_drive": "", "metadata": {}}]}
    
    +--------------------------------------+------------------+--------+------------+-------------+----------------------+
    | ID                                   | Name             | Status | Task State | Power State | Networks             |
    +--------------------------------------+------------------+--------+------------+-------------+----------------------+
    | 2e3dd89c-ad59-4499-a3ff-6444ca74f7c3 | New              | ACTIVE | -          | Running     | NW=192.168.0.189     |
    | 34f0b3a5-4142-4276-b27d-bac7c64f9f90 | test01           | ACTIVE | -          | Running     | Office=192.168.39.68 |
    | 8e61920f-150a-43e9-addd-85e3108ea771 | test-1           | ACTIVE | -          | Running     | NW=192.168.0.188     |
    +--------------------------------------+------------------+--------+------------+-------------+----------------------+

      由第二个请求可知,获取请求结果实质是通过二个请求即可(ps:第一个请求为token)

    curl -g -i -X GET http://192.168.39.172:8774/v2/b8a56795b6d749cd8434f841868ee6a4/servers/detail -H "User-Agent: python-novaclient" -H "Accept: application/json" -H "X-Auth-Token: 28db6fe8c2ac45db850b96189c939629" 
    HTTP/1.1 200 OK
    Content-Type: application/json
    Content-Length: 4848
    X-Compute-Request-Id: req-cff95650-9cf8-442f-8a2c-fdc90c21443b
    Date: Tue, 06 Jun 2017 08:21:06 GMT
    
    {"servers": [{"status": "ACTIVE", "updated": "2017-06-05T03:31:36Z", "hostId": "4c820983066e6ff21f0753adca9b55e75797235c0fb8fa1141efab4d", "OS-EXT-SRV-ATTR:host": "TS-M2-Cloud173", "addresses": {"NW": [{"OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:d5:ed:11", "version": 4, "addr": "192.168.0.189", "OS-EXT-IPS:type": "fixed"}]}, "links": [{"href": "http://192.168.39.172:8774/v2/b8a56795b6d749cd8434f841868ee6a4/servers/2e3dd89c-ad59-4499-a3ff-6444ca74f7c3", "rel": "self"}, {"href": "http://192.168.39.172:8774/b8a56795b6d749cd8434f841868ee6a4/servers/2e3dd89c-ad59-4499-a3ff-6444ca74f7c3", "rel": "bookmark"}], "key_name": null, "image": "", "OS-EXT-STS:task_state": null, "OS-EXT-STS:vm_state": "active", "OS-EXT-SRV-ATTR:instance_name": "instance-000000d1", "OS-SRV-USG:launched_at": "2017-05-25T07:12:27.000000", "OS-EXT-SRV-ATTR:hypervisor_hostname": "TS-M2-Cloud173", "flavor": {"id": "c0540dff-eadd-44b2-a6d4-a4f74409b9c4", "links": [{"href": "http://192.168.39.172:8774/b8a56795b6d749cd8434f841868ee6a4/flavors/c0540dff-eadd-44b2-a6d4-a4f74409b9c4", "rel": "bookmark"}]}, "id": "2e3dd89c-ad59-4499-a3ff-6444ca74f7c3", "security_groups": [{"name": "default"}], "OS-SRV-USG:terminated_at": null, "OS-EXT-AZ:availability_zone": "ACTIVE", "user_id": "c2102ee1835440e39eea98cf264f118e", "name": "New", "created": "2017-05-25T07:11:56Z", "tenant_id": "b8a56795b6d749cd8434f841868ee6a4", "OS-DCF:diskConfig": "AUTO", "os-extended-volumes:volumes_attached": [{"id": "a79fe8d0-efe9-47be-a54e-033a1ad08f71"}], "accessIPv4": "", "accessIPv6": "", "progress": 0, "OS-EXT-STS:power_state": 1, "config_drive": "", "metadata": {}}, {"status": "ACTIVE", "updated": "2017-05-25T07:12:57Z", "hostId": "fbd0e31d7dd6d0f516942bc9b19f6a1733e0108121008d884e44d5b9", "OS-EXT-SRV-ATTR:host": "TS-M2-Cloud177", "addresses": {"NW": [{"OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:12:a4:f0", "version": 4, "addr": "192.168.0.188", "OS-EXT-IPS:type": "fixed"}]}, "links": [{"href": "http://192.168.39.172:8774/v2/b8a56795b6d749cd8434f841868ee6a4/servers/8e61920f-150a-43e9-addd-85e3108ea771", "rel": "self"}, {"href": "http://192.168.39.172:8774/b8a56795b6d749cd8434f841868ee6a4/servers/8e61920f-150a-43e9-addd-85e3108ea771", "rel": "bookmark"}], "key_name": null, "image": "", "OS-EXT-STS:task_state": null, "OS-EXT-STS:vm_state": "active", "OS-EXT-SRV-ATTR:instance_name": "instance-000000d0", "OS-SRV-USG:launched_at": "2017-05-25T07:12:56.000000", "OS-EXT-SRV-ATTR:hypervisor_hostname": "TS-M2-Cloud177", "flavor": {"id": "c0540dff-eadd-44b2-a6d4-a4f74409b9c4", "links": [{"href": "http://192.168.39.172:8774/b8a56795b6d749cd8434f841868ee6a4/flavors/c0540dff-eadd-44b2-a6d4-a4f74409b9c4", "rel": "bookmark"}]}, "id": "8e61920f-150a-43e9-addd-85e3108ea771", "security_groups": [{"name": "default"}], "OS-SRV-USG:terminated_at": null, "OS-EXT-AZ:availability_zone": "ACTIVE", "user_id": "c2102ee1835440e39eea98cf264f118e", "name": "test-1", "created": "2017-05-25T07:11:55Z", "tenant_id": "b8a56795b6d749cd8434f841868ee6a4", "OS-DCF:diskConfig": "AUTO", "os-extended-volumes:volumes_attached": [{"id": "dfc6abad-49bd-40a9-a7a5-4c868eb9e211"}], "accessIPv4": "", "accessIPv6": "", "progress": 0, "OS-EXT-STS:power_state": 1, "config_drive": "", "metadata": {}}, {"status": "ACTIVE", "updated": "2017-05-19T03:35:37Z", "hostId": "fbd0e31d7dd6d0f516942bc9b19f6a1733e0108121008d884e44d5b9", "OS-EXT-SRV-ATTR:host": "TS-M2-Cloud177", "addresses": {"Office": [{"OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:82:15:4e", "version": 4, "addr": "192.168.39.68", "OS-EXT-IPS:type": "fixed"}]}, "links": [{"href": "http://192.168.39.172:8774/v2/b8a56795b6d749cd8434f841868ee6a4/servers/34f0b3a5-4142-4276-b27d-bac7c64f9f90", "rel": "self"}, {"href": "http://192.168.39.172:8774/b8a56795b6d749cd8434f841868ee6a4/servers/34f0b3a5-4142-4276-b27d-bac7c64f9f90", "rel": "bookmark"}], "key_name": null, "image": "", "OS-EXT-STS:task_state": null, "OS-EXT-STS:vm_state": "active", "OS-EXT-SRV-ATTR:instance_name": "instance-000000c8", "OS-SRV-USG:launched_at": "2017-05-19T03:35:37.000000", "OS-EXT-SRV-ATTR:hypervisor_hostname": "TS-M2-Cloud177", "flavor": {"id": "665a38e6-6f80-4dc2-ad97-89ca335358e6", "links": [{"href": "http://192.168.39.172:8774/b8a56795b6d749cd8434f841868ee6a4/flavors/665a38e6-6f80-4dc2-ad97-89ca335358e6", "rel": "bookmark"}]}, "id": "34f0b3a5-4142-4276-b27d-bac7c64f9f90", "security_groups": [{"name": "default"}], "OS-SRV-USG:terminated_at": null, "OS-EXT-AZ:availability_zone": "ACTIVE", "user_id": "c2102ee1835440e39eea98cf264f118e", "name": "chengpeng_test01", "created": "2017-05-19T03:35:24Z", "tenant_id": "b8a56795b6d749cd8434f841868ee6a4", "OS-DCF:diskConfig": "AUTO", "os-extended-volumes:volumes_attached": [{"id": "48e6d225-c43e-41a3-8890-8a3d40b4a38e"}], "accessIPv4": "", "accessIPv6": "", "progress": 0, "OS-EXT-STS:power_state": 1, "config_drive": "", "metadata": {}}]}

      分析该url:http://192.168.39.172:8774/v2/b8a56795b6d749cd8434f841868ee6a4/servers/detail; 如何转换为底层请求具体的方法呢?

      1、nova-api来接收请求;其底层配置配置为/etc/nova/api-paste.ini 

      2、可知app_factory路径为:nova/api/openstack/compute包中,查看其__init__.py文件:

      由此路由函数即可进行转换;

  • 相关阅读:
    矩阵的阶
    python中'0b111'中的b 是什么意思
    Python字节码介绍
    多版本python共存,安装三方库到指定python版本
    关于python 中的__future__模块
    解决Python模块报错:ModuleNotFoundError: No module name 'StringIO'
    python常用魔法函数
    MySQL binlog
    MySQL start and stop
    Mysql 源码安装
  • 原文地址:https://www.cnblogs.com/chris-cp/p/6952262.html
Copyright © 2020-2023  润新知