這篇文章給大家介紹nova創(chuàng)建虛擬機的過程是怎樣的,內(nèi)容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
成都創(chuàng)新互聯(lián)公司是一家專業(yè)提供元江縣企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計、H5技術(shù)、小程序制作等業(yè)務。10年已為元江縣眾多企業(yè)、政府機構(gòu)等服務。創(chuàng)新互聯(lián)專業(yè)網(wǎng)絡公司優(yōu)惠進行中。
1. 初衷
時常被問及“nova創(chuàng)建虛擬機的過程”,雖然大致是知道里面的過程的,但在某些場合之下,說“大致”知道往往決定了一場對話的無疾而終。要把這詳細的內(nèi)容給完整地說出來,有邏輯地說出來,還是需要細細斟酌一番的,那種“大致”的說辭就顯得蒼白了。畢竟作為從業(yè)者,詳細地,深入地了解內(nèi)部的整個過程應該是必須的基本功,這算是初衷吧。
2. 由一條命令引起的風波
nova --debug boot ubuntu_test --flavor 2 \ --image cde1d850-65bb-48f6-8ee9-b990c7ccf158 \ --num-instance 1 \ --nic net-id=cfa25cef-96c3-46f1-8522-d9518eb5a451
這是一條創(chuàng)建虛擬機(實例)的命令,在命令中指定了新實例的名稱:ubuntu_test,云主機類型:2,鏡像:cde1d850-65bb-48f6-8ee9-b990c7ccf158,數(shù)量:1臺,指定網(wǎng)絡:cfa25cef-96c3-46f1-8522-d9518eb5a451。
這里要說明一下鏡像和網(wǎng)絡:
命令中的鏡像網(wǎng)絡通過這兩個命令查詢而來。
正如所看到的,命令中加了--debug參數(shù),這可以讓我們清楚看到在執(zhí)行這個命令的過程中做了哪些具體操作。
下圖就是我們執(zhí)行創(chuàng)建實例后的過程
這里信息有點多啊,因此只好截了部分的圖。詳細信息整理后放在下面。并逐一分析。
3. debug輸出的主要的請求
這里主要說明下面最重要的四條
3.1. 向keystone取得token
REQ: curl \ -i 'http://ubuntu80:35357/v2.0/tokens' -X POST -H "Accept: application/json" \ -H "Content-Type: application/json" -H "User-Agent: python-novaclient" \ -d '{"auth": {"tenantName": "admin", "passwordCredentials": {"username": "admin", "password": "{SHA1}5705cc2e5fda0ab7529d5093c5e389fffe45d615"}}}'
3.2. 通過nova-api驗證鏡像
REQ: curl -i 'http://ubuntu80:8774/v2/0e962df9db3f4469b3d9bfbc5ffdaf7e/images/cde1d850-65bb-48f6-8ee9-b990c7ccf158' \ -X GET \ -H "Accept: application/json" \ -H "User-Agent: python-novaclient" \ -H "X-Auth-Project-Id: admin" \ -H "X-Auth-Token: {SHA1}e87219521f61238b143fbb323b962930380ce022"
3.3. 通過nova-api驗證云主機類型
REQ: curl -i 'http://ubuntu80:8774/v2/0e962df9db3f4469b3d9bfbc5ffdaf7e/flavors/2' \ -X GET -H "Accept: application/json" -H "User-Agent: python-novaclient" \ -H "X-Auth-Project-Id: admin" \ -H "X-Auth-Token: {SHA1}e87219521f61238b143fbb323b962930380ce022"
3.4. 創(chuàng)建實例
REQ: curl -i 'http://ubuntu80:8774/v2/0e962df9db3f4469b3d9bfbc5ffdaf7e/servers' \ -X POST -H "Accept: application/json" \ -H "Content-Type: application/json" \ -H "User-Agent: python-novaclient" \ -H "X-Auth-Project-Id: admin" \ -H "X-Auth-Token: {SHA1}e87219521f61238b143fbb323b962930380ce022" \ -d '{"server": {"name": "ubuntu_test", "imageRef": "cde1d850-65bb-48f6-8ee9-b990c7ccf158", "flavorRef": "2", "max_count": 1, "min_count": 1, "networks": [{"uuid": "cfa25cef-96c3-46f1-8522-d9518eb5a451"}]}}'
4. 從如何取得token說起
我們都知道35357是keystone的端口,問我為啥知道是keystone,好吧,我是通過端口查到的。
恩,是的,就是keystone,我們回到我們的主題,這里向keystone發(fā)送請求的時候,組織了這樣的一個數(shù)據(jù)
{ "auth": { "tenantName": "admin", "passwordCredentials": { "username": "admin", "password": "{SHA1}5705cc2e5fda0ab7529d5093c5e389fffe45d615" } } }
把這個數(shù)據(jù)發(fā)給keystone,目的是為了獲取一個token,就是一個鑰匙,有了它,我們后面的操作就可以憑借這個鑰匙暢通無阻了。那keystone是怎么處理的呢。
找到keystone的源碼
看到token了吧,嗯嗯,就在那里面
nano token/controllers.py
找到Auth類的authenticate方法
是不是跟上面給keystone的參數(shù)類似。這個方法一切順利的話,在最后它會返回一個token(鑰匙)。
keystone回復的是什么呢。
REQ: curl \ -i 'http://ubuntu80:35357/v2.0/tokens' \ -X POST -H "Accept: application/json" \ -H "Content-Type: application/json" \ -H "User-Agent: python-novaclient" \ -d '{"auth": {"tenantName": "admin", "passwordCredentials": {"username": "admin", "password": "{SHA1}5705cc2e5fda0ab7529d5093c5e389fffe45d615"}}}' INFO (connectionpool:259) Starting new HTTP connection (1): ubuntu80 DEBUG (connectionpool:390) Setting read timeout to 600.0 DEBUG (connectionpool:430) "POST /v2.0/tokens HTTP/1.1" 200 1744 RESP: [200] {'date': 'Mon, 18 Jan 2016 01:58:37 GMT', 'vary': 'X-Auth-Token', 'content-length': '1744', 'content-type': 'application/json', 'x-distribution': 'Ubuntu'} RESP BODY: {"access": {"token": {"issued_at": "2016-01-18T01:58:37.093849", "expires": "2016-01-18T02:58:37Z", "id": "{SHA1}e87219521f61238b143fbb323b962930380ce022", "tenant": {"enabled": true, "description": "Admin Tenant", "name": "admin", "id": "0e962df9db3f4469b3d9bfbc5ffdaf7e"}, "audit_ids": ["RugmwI0_R3ysmpJ3zF8k4Q"]}, "serviceCatalog": [{"endpoints_links": [], "endpoints": [{"adminURL": "http://ubuntu80:9292", "region": "regionOne", "publicURL": "http://ubuntu80:9292", "internalURL": "http://ubuntu80:9292", "id": "4794a2d722ab4f6bbda00d779c1410d1"}], "type": "image", "name": "glance"}, {"endpoints_links": [], "endpoints": [{"adminURL": "http://ubuntu80:8774/v2/0e962df9db3f4469b3d9bfbc5ffdaf7e", "region": "regionOne", "publicURL": "http://ubuntu80:8774/v2/0e962df9db3f4469b3d9bfbc5ffdaf7e", "internalURL": "http://ubuntu80:8774/v2/0e962df9db3f4469b3d9bfbc5ffdaf7e", "id": "a8ccc19100934fc1ae7c899dc5e17bdd"}], "type": "compute", "name": "nova"}, {"endpoints_links": [], "endpoints": [{"adminURL": "http://ubuntu80:9696", "region": "regionOne", "publicURL": "http://ubuntu80:9696", "internalURL": "http://ubuntu80:9696", "id": "656371fd3163415c95ff2fc0facbe5e1"}], "type": "network", "name": "neutron"}, {"endpoints_links": [], "endpoints": [{"adminURL": "http://ubuntu80:35357/v2.0", "region": "regionOne", "publicURL": "http://ubuntu80:5000/v2.0", "internalURL": "http://ubuntu80:5000/v2.0", "id": "4f1d53f12dc6485cb5816c83f68b7053"}], "type": "identity", "name": "keystone"}], "user": {"username": "admin", "roles_links": [], "id": "96a7c834b3f8485c87d79df7b6480c92", "roles": [{"name": "_member_"}, {"name": "admin"}], "name": "admin"}, "metadata": {"is_admin": 0, "roles": ["9fe2ff9ee4384b1894a90878d3e92bab", "fc2574382dd74936b1bc85cc2110c3c2"]}}}
太亂了,整理一下,把回復的json抽出來
{ "access": { "token": { "issued_at": "2016-01-18T01:58:37.093849", "expires": "2016-01-18T02:58:37Z", "id": "{SHA1}e87219521f61238b143fbb323b962930380ce022", "tenant": { "enabled": true, "description": "Admin Tenant", "name": "admin", "id": "0e962df9db3f4469b3d9bfbc5ffdaf7e" }, "audit_ids": [ "RugmwI0_R3ysmpJ3zF8k4Q" ] }, "serviceCatalog": [ { "endpoints_links": [ ], "endpoints": [ { "adminURL": "http://ubuntu80:9292", "region": "regionOne", "publicURL": "http://ubuntu80:9292", "internalURL": "http://ubuntu80:9292", "id": "4794a2d722ab4f6bbda00d779c1410d1" } ], "type": "image", "name": "glance" }, { "endpoints_links": [ ], "endpoints": [ { "adminURL": "http://ubuntu80:8774/v2/0e962df9db3f4469b3d9bfbc5ffdaf7e", "region": "regionOne", "publicURL": "http://ubuntu80:8774/v2/0e962df9db3f4469b3d9bfbc5ffdaf7e", "internalURL": "http://ubuntu80:8774/v2/0e962df9db3f4469b3d9bfbc5ffdaf7e", "id": "a8ccc19100934fc1ae7c899dc5e17bdd" } ], "type": "compute", "name": "nova" }, { "endpoints_links": [ ], "endpoints": [ { "adminURL": "http://ubuntu80:9696", "region": "regionOne", "publicURL": "http://ubuntu80:9696", "internalURL": "http://ubuntu80:9696", "id": "656371fd3163415c95ff2fc0facbe5e1" } ], "type": "network", "name": "neutron" }, { "endpoints_links": [ ], "endpoints": [ { "adminURL": "http://ubuntu80:35357/v2.0", "region": "regionOne", "publicURL": "http://ubuntu80:5000/v2.0", "internalURL": "http://ubuntu80:5000/v2.0", "id": "4f1d53f12dc6485cb5816c83f68b7053" } ], "type": "identity", "name": "keystone" } ], "user": { "username": "admin", "roles_links": [ ], "id": "96a7c834b3f8485c87d79df7b6480c92", "roles": [ { "name": "_member_" }, { "name": "admin" } ], "name": "admin" }, "metadata": { "is_admin": 0, "roles": [ "9fe2ff9ee4384b1894a90878d3e92bab", "fc2574382dd74936b1bc85cc2110c3c2" ] } } }
看到了token中的id({SHA1}e87219521f61238b143fbb323b962930380ce022)。后面的操作都是要帶上它。
5. 驗證鏡像和云主機類型
在第3節(jié)中可以看到這兩條驗證的請求,分別是驗證鏡像和云主機類型
3.2. 通過nova-api驗證鏡像
REQ: curl \ -i 'http://ubuntu80:8774/v2/0e962df9db3f4469b3d9bfbc5ffdaf7e/images/cde1d850-65bb-48f6-8ee9-b990c7ccf158' \ -X GET -H "Accept: application/json" \ -H "User-Agent: python-novaclient" \ -H "X-Auth-Project-Id: admin" \ -H "X-Auth-Token: {SHA1}e87219521f61238b143fbb323b962930380ce022"
3.3. 通過nova-api驗證云主機類型
REQ: curl \ -i 'http://ubuntu80:8774/v2/0e962df9db3f4469b3d9bfbc5ffdaf7e/flavors/2' \ -X GET \ -H "Accept: application/json" \ -H "User-Agent: python-novaclient" \ -H "X-Auth-Project-Id: admin" \ -H "X-Auth-Token: {SHA1}e87219521f61238b143fbb323b962930380ce022"
這兩條請求,是類似的,它們的代碼位于nova.api.openstack.compute中的images.py和flavors.py中的Controller。
關(guān)于nova創(chuàng)建虛擬機的過程是怎樣的就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
標題名稱:nova創(chuàng)建虛擬機的過程是怎樣的
網(wǎng)頁地址:http://aaarwkj.com/article36/pccesg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、網(wǎng)站收錄、域名注冊、響應式網(wǎng)站、用戶體驗、靜態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)