美文网首页
Nova list 背后做了什么?

Nova list 背后做了什么?

作者: louyang | 来源:发表于2019-02-12 15:34 被阅读6次
    1 查看当前运行的虚拟机

    在OpenStack上,我们通常用nova list命令来查看所有当前租户的虚拟机。例如:

    +--------------------------------------+---------------+--------+------------+-------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | ID                                   | Name          | Status | Task State | Power State | Networks                                                                                                                                                                                                                                                    |
    +--------------------------------------+---------------+--------+------------+-------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | 46909036-6701-4dbf-af9d-b5fc188f8b30 | RCP-1234-cp-0 | ACTIVE | -          | Running     | RCP-1234-internal-net=192.168.1.7; RCP-1234-intmsg0-net=169.254.0.9                                                                                                                                                                                         |
    | 32fd180d-0e7f-43b4-80a9-f911e9802201 | RCP-1234-ei-0 | ACTIVE | -          | Running     | extnet-vlan-2=2a00:8a00:8000:5002:0:17:0:224, 10.107.115.144; extnet-vlan-0=2a00:8a00:8000:5002:0:17:0:a, 10.107.115.49; extnet-vlan-1=10.107.115.86, 2a00:8a00:8000:5002:0:17:0:123; RCP-1234-internal-net=192.168.1.10; RCP-1234-intmsg0-net=169.254.0.14 |
    | 60a5e01b-5f1b-4a86-b959-920c97f1e86c | RCP-1234-ei-1 | ACTIVE | -          | Running     | extnet-vlan-2=2a00:8a00:8000:5002:0:17:0:229, 10.107.115.146; extnet-vlan-0=2a00:8a00:8000:5002:0:17:0:14, 10.107.115.27; extnet-vlan-1=10.107.115.79, 2a00:8a00:8000:5002:0:17:0:107; RCP-1234-internal-net=192.168.1.15; RCP-1234-intmsg0-net=169.254.0.5 |
    | 74a8678d-0e41-45c9-839a-81d47c13bf22 | RCP-1234-mn-0 | ACTIVE | -          | Running     | RCP-1234-internal-net=192.168.1.13; extnet-vlan-4=2a00:8a00:8000:5002:0:17:0:404, 10.107.116.9; RCP-1234-intmsg0-net=169.254.0.11                                                                                                                           |
    | b7e4cb84-738d-4046-b86c-466fd69cee54 | RCP-1234-up-0 | ACTIVE | -          | Running     | extnet-vlan-0=2a00:8a00:8000:5002:0:17:0:4, 10.107.115.9; RCP-1234-internal-net=192.168.1.12; RCP-1234-intmsg0-net=169.254.0.12                                                                                                                             |
    +--------------------------------------+---------------+--------+------------+-------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    

    类似的命令还有:openstack server list

    +--------------------------------------+---------------+--------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------+---------------+
    | ID                                   | Name          | Status | Networks                                                                                                                                                                                                                                                    | Image                     | Flavor        |
    +--------------------------------------+---------------+--------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------+---------------+
    | 60a5e01b-5f1b-4a86-b959-920c97f1e86c | RCP-1234-ei-1 | ACTIVE | extnet-vlan-2=2a00:8a00:8000:5002:0:17:0:229, 10.107.115.146; extnet-vlan-0=2a00:8a00:8000:5002:0:17:0:14, 10.107.115.27; extnet-vlan-1=10.107.115.79, 2a00:8a00:8000:5002:0:17:0:107; RCP-1234-internal-net=192.168.1.15; RCP-1234-intmsg0-net=169.254.0.5 | rcp2.0-ci2019-03-01-10-47 | rcp_xlarge_v4 |
    | 32fd180d-0e7f-43b4-80a9-f911e9802201 | RCP-1234-ei-0 | ACTIVE | extnet-vlan-2=2a00:8a00:8000:5002:0:17:0:224, 10.107.115.144; extnet-vlan-0=2a00:8a00:8000:5002:0:17:0:a, 10.107.115.49; extnet-vlan-1=10.107.115.86, 2a00:8a00:8000:5002:0:17:0:123; RCP-1234-internal-net=192.168.1.10; RCP-1234-intmsg0-net=169.254.0.14 | rcp2.0-ci2019-03-01-10-47 | rcp_xlarge_v4 |
    | b7e4cb84-738d-4046-b86c-466fd69cee54 | RCP-1234-up-0 | ACTIVE | extnet-vlan-0=2a00:8a00:8000:5002:0:17:0:4, 10.107.115.9; RCP-1234-internal-net=192.168.1.12; RCP-1234-intmsg0-net=169.254.0.12                                                                                                                             | rcp2.0-ci2019-03-01-10-47 | rcp_large_v4  |
    | 46909036-6701-4dbf-af9d-b5fc188f8b30 | RCP-1234-cp-0 | ACTIVE | RCP-1234-internal-net=192.168.1.7; RCP-1234-intmsg0-net=169.254.0.9                                                                                                                                                                                         | rcp2.0-ci2019-03-01-10-47 | rcp_medium_v4 |
    | 74a8678d-0e41-45c9-839a-81d47c13bf22 | RCP-1234-mn-0 | ACTIVE | RCP-1234-internal-net=192.168.1.13; extnet-vlan-4=2a00:8a00:8000:5002:0:17:0:404, 10.107.116.9; RCP-1234-intmsg0-net=169.254.0.11                                                                                                                           | rcp2.0-ci2019-03-01-10-47 | rcp_large_v4  |
    +--------------------------------------+---------------+--------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------+---------------+
    

    或者,使用Openstack的dashboard:


    image.png

    实际上,不管是命令行,还是Web UI,都使用了OpenStack的RESTful API来得到虚拟机的信息。下面我们来推导这个过程。

    2 “--debug”帮我们看到更多信息

    通过nova --debug list拿到运行时的log:

    [cranuser3@controller-1 ~(keystone_cranuser3)]$ nova --debug list
    DEBUG (extension:189) found extension EntryPoint.parse('aodh-noauth = aodhclient.noauth:AodhNoAuthLoader')
    ...
    
    3 从”--debug”中梳理出Restful API

    我们知道,Restful API就是每个资源都有独立的URL,并且通过HTTP协议来操作的API。在“--debug”中,有下面这些HTTP消息:

    curl -g -i -X GET http://192.168.54.5:5000/v3
    http://192.168.54.5:5000 "POST /v3/auth/tokens HTTP/1.1
    curl -g -i -X GET http://192.168.54.5:8774/v2.1
    curl -g -i -X GET http://192.168.54.5:8774/v2.1/servers/detail 
    

    可以看到这里使用了5000和8774端口,通过endpoint命令,

    [cranuser2@controller-1 ~(keystone_cranuser2)]$ openstack endpoint list | grep 5000
    | eff831537fd4497794a0cbbb0449854c | RegionOne | keystone     | identity       | True    | public    | https://10.107.184.20:5000                  |
    | f1deba856a6f4b4fb7cc800956eccf39 | RegionOne | keystone     | identity       | True    | internal  | http://192.168.54.5:5000                    |
    [cranuser2@controller-1 ~(keystone_cranuser2)]$ openstack endpoint list | grep 8774
    | 0b554bbb3a3043dd9cc6482e0a3526c2 | RegionOne | nova         | compute        | True    | admin     | http://192.168.54.5:8774/v2.1               |
    | 35c3df0004cb40d1a0512f4f04083b9d | RegionOne | nova         | compute        | True    | internal  | http://192.168.54.5:8774/v2.1               |
    | 35f6aff1cc444321b2318141472dbc27 | RegionOne | nova         | compute        | True    | public    | https://10.107.184.20:8774/v2.1             |
    

    可以看到5000是keystone, 8774是nova的服务端口。

    4 得到keystone 版本3的状态
    $ curl http://192.168.54.5:5000/v3
    {"version": {"status": "stable", "updated": "2018-02-28T00:00:00Z", "media-types": [{"base": "application/json", "type": "application/vnd.openstack.identity-v3+json"}], "id": "v3.10", "links": [{"href": "http://192.168.54.5:5000/v3/", "rel": "self"}]}}
    

    我认为这一步是可做可不做的。

    5 拿token
    $ curl -i -d '
        {
            "auth": {
                "identity": {
                    "methods": ["password"],
                    "password": {
                        "user": {
                            "domain": {"name": "Default"},
                            "name": "cranuser3",
                            "password": "systeM!23"
                        }
                    }
                }
            }
        }' -H "Content-type: application/json" "http://192.168.54.5:5000/v3/auth/tokens?nocatalog"
    
    HTTP/1.1 201 Created
    Server: nginx
    Date: Mon, 04 Mar 2019 07:52:41 GMT
    Content-Type: application/json
    Content-Length: 660
    X-Subject-Token: gAAAAABcfNlJ4TofivayZJDwWOdE2R0aM9DRQ4mdfdKft7LSHNGzx_e9cKODjYbDMJDaxkwh8K7Alg9xFgUQ2oyGKuMnrRvizxpNHEZWyrNryGPdFXoLTuU66RId1Ll9Oc9o-d6exlWuC6TWwJka9SftxWgDnrvk4EP8XAOtiisCATmfkwuijek
    Vary: X-Auth-Token
    x-openstack-request-id: req-12271058-fe16-4dd8-a7ea-445e1a4a4cfb
    X-Content-Type-Options: nosniff
    X-XSS-Protection: 1; mode=block
    Content-Security-Policy: default-src 'self' https: wss:;
    X-Frame-Options: DENY
    X-Frame-Options: SAMEORIGIN
    Strict-Transport-Security: max-age=15768000
    
    {"token": {"is_domain": false, "methods": ["password"], "roles": [{"id": "9fe2ff9ee4384b1894a90878d3e92bab", "name": "_member_"}, {"id": "6e5cf37d5deb494eba30a74391113d03", "name": "admin"}, {"id": "c7f537ec56a74d1da2fffac2b22bc68b", "name": "network_user"}], "expires_at": "2019-03-04T19:52:41.000000Z", "project": {"domain": {"id": "default", "name": "Default"}, "id": "cf0ee152f3ef4136a2811af804d4cf19", "name": "cran3"}, "user": {"password_expires_at": null, "domain": {"id": "default", "name": "Default"}, "id": "0404c966a1a94f90922c803ebb4308bf", "name": "cranuser3"}, "audit_ids": ["kQIfNlgtSQO1N0uvhevl0g"], "issued_at": "2019-03-04T07:52:41.000000Z"}}
    

    注意X-Subject-Token

    6 拿虚拟机列表
    $ curl -X GET http://192.168.54.5:8774/v2.1/servers -H "Accept: application/json" -H "X-Auth-Token: gAAAAABcfNlJ4TofivayZJDwWOdE2R0aM9DRQ4mdfdKft7LSHNGzx_e9cKODjYbDMJDaxkwh8K7Alg9xFgUQ2oyGKuMnrRvizxpNHEZWyrNryGPdFXoLTuU66RId1Ll9Oc9o-d6exlWuC6TWwJka9SftxWgDnrvk4EP8XAOtiisCATmfkwuijek"
    
    {"servers": [{"id": "60a5e01b-5f1b-4a86-b959-920c97f1e86c", "links": [{"href": "http://192.168.54.5:8774/v2.1/servers/60a5e01b-5f1b-4a86-b959-920c97f1e86c", "rel": "self"}, {"href": "http://192.168.54.5:8774/servers/60a5e01b-5f1b-4a86-b959-920c97f1e86c", "rel": "bookmark"}], "name": "RCP-1234-ei-1"}, {"id": "32fd180d-0e7f-43b4-80a9-f911e9802201", "links": [{"href": "http://192.168.54.5:8774/v2.1/servers/32fd180d-0e7f-43b4-80a9-f911e9802201", "rel": "self"}, {"href": "http://192.168.54.5:8774/servers/32fd180d-0e7f-43b4-80a9-f911e9802201", "rel": "bookmark"}], "name": "RCP-1234-ei-0"}, {"id": "b7e4cb84-738d-4046-b86c-466fd69cee54", "links": [{"href": "http://192.168.54.5:8774/v2.1/servers/b7e4cb84-738d-4046-b86c-466fd69cee54", "rel": "self"}, {"href": "http://192.168.54.5:8774/servers/b7e4cb84-738d-4046-b86c-466fd69cee54", "rel": "bookmark"}], "name": "RCP-1234-up-0"}, {"id": "46909036-6701-4dbf-af9d-b5fc188f8b30", "links": [{"href": "http://192.168.54.5:8774/v2.1/servers/46909036-6701-4dbf-af9d-b5fc188f8b30", "rel": "self"}, {"href": "http://192.168.54.5:8774/servers/46909036-6701-4dbf-af9d-b5fc188f8b30", "rel": "bookmark"}], "name": "RCP-1234-cp-0"}, {"id": "74a8678d-0e41-45c9-839a-81d47c13bf22", "links": [{"href": "http://192.168.54.5:8774/v2.1/servers/74a8678d-0e41-45c9-839a-81d47c13bf22", "rel": "self"}, {"href": "http://192.168.54.5:8774/servers/74a8678d-0e41-45c9-839a-81d47c13bf22", "rel": "bookmark"}], "name": "RCP-1234-mn-0"}]}
    
    image.png

    相关文章

      网友评论

          本文标题:Nova list 背后做了什么?

          本文链接:https://www.haomeiwen.com/subject/mnkigxtx.html