您好,登錄后才能下訂單哦!
這篇文章給大家介紹nova創(chuàng)建虛擬機(jī)的過程是怎樣的,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。
1. 初衷
時(shí)常被問及“nova創(chuàng)建虛擬機(jī)的過程”,雖然大致是知道里面的過程的,但在某些場(chǎng)合之下,說“大致”知道往往決定了一場(chǎng)對(duì)話的無疾而終。要把這詳細(xì)的內(nèi)容給完整地說出來,有邏輯地說出來,還是需要細(xì)細(xì)斟酌一番的,那種“大致”的說辭就顯得蒼白了。畢竟作為從業(yè)者,詳細(xì)地,深入地了解內(nèi)部的整個(gè)過程應(yīng)該是必須的基本功,這算是初衷吧。
2. 由一條命令引起的風(fēng)波
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)建虛擬機(jī)(實(shí)例)的命令,在命令中指定了新實(shí)例的名稱:ubuntu_test,云主機(jī)類型:2,鏡像:cde1d850-65bb-48f6-8ee9-b990c7ccf158,數(shù)量:1臺(tái),指定網(wǎng)絡(luò):cfa25cef-96c3-46f1-8522-d9518eb5a451。
這里要說明一下鏡像和網(wǎng)絡(luò):
命令中的鏡像網(wǎng)絡(luò)通過這兩個(gè)命令查詢而來。
正如所看到的,命令中加了--debug參數(shù),這可以讓我們清楚看到在執(zhí)行這個(gè)命令的過程中做了哪些具體操作。
下圖就是我們執(zhí)行創(chuàng)建實(shí)例后的過程
這里信息有點(diǎn)多啊,因此只好截了部分的圖。詳細(xì)信息整理后放在下面。并逐一分析。
3. debug輸出的主要的請(qǐng)求
這里主要說明下面最重要的四條
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驗(yàn)證鏡像
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驗(yàn)證云主機(jī)類型
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)建實(shí)例
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ā)送請(qǐng)求的時(shí)候,組織了這樣的一個(gè)數(shù)據(jù)
{ "auth": { "tenantName": "admin", "passwordCredentials": { "username": "admin", "password": "{SHA1}5705cc2e5fda0ab7529d5093c5e389fffe45d615" } } }
把這個(gè)數(shù)據(jù)發(fā)給keystone,目的是為了獲取一個(gè)token,就是一個(gè)鑰匙,有了它,我們后面的操作就可以憑借這個(gè)鑰匙暢通無阻了。那keystone是怎么處理的呢。
找到keystone的源碼
看到token了吧,嗯嗯,就在那里面
nano token/controllers.py
找到Auth類的authenticate方法
是不是跟上面給keystone的參數(shù)類似。這個(gè)方法一切順利的話,在最后它會(huì)返回一個(gè)token(鑰匙)。
keystone回復(fù)的是什么呢。
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"]}}}
太亂了,整理一下,把回復(fù)的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. 驗(yàn)證鏡像和云主機(jī)類型
在第3節(jié)中可以看到這兩條驗(yàn)證的請(qǐng)求,分別是驗(yàn)證鏡像和云主機(jī)類型
3.2. 通過nova-api驗(yàn)證鏡像
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驗(yàn)證云主機(jī)類型
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"
這兩條請(qǐng)求,是類似的,它們的代碼位于nova.api.openstack.compute中的images.py和flavors.py中的Controller。
關(guān)于nova創(chuàng)建虛擬機(jī)的過程是怎樣的就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。