[openstack] 建立現有的 instance 為 image
一班而言使用即時存檔或名”快照” (snapshots) 就可以達到下次起另外一個雲實例或名”實體” (instance) 的功能,但是礙於我自己龜毛,想要一個 image 直接可以啟動,所以寫這篇文章記錄。
用 server list 指令查看想要做 image 的主機狀態
$ openstack server list
如果還在開機狀態請關機,可以用 server stop 關機
$ openstack server stop latte
關機好之後,就可以建立該主機 latte 的 image
$ openstack server image create --name latte_s1 latte

在 openstack 網頁上面看到 latte_s1 的型態是 Snapshot,這樣其實已經可以啟用另外一個實體,但是我不想因為這是用快照。下列指令可以列出目前的快照:
$ openstack volume snapshot list

然後按照上面的快照ID建立一個雲硬碟(volume)
$ openstack volume create --snapshot 0ee45900-f3e6-4fc5-9e44-76dd6f4414c0 --size 80 latte_s1_v1
用 volume list 看看剛剛建立的結果
$ openstack volume list

再把剛剛建立的 volume 建立成 image
$ openstack image create --volume f4b6e194-77bd-492b-825c-bf18e09c9a7b latte_i1
這要等待一段時間,因為他是按照該主機的 volume 大小去建立

然後用 image list 找出剛剛建立的 80GB RAW image
$ openstack image list

把 latte_i1 下載為 latte_i1.raw,這也需要等待一段時間
$ openstack image save --file latte_i1.raw 1af2092c-ccd6-4e79-84e9-2566b737c556
用 qemu-img 工具轉換 raw 為 qcow2, 請耐心等待
$ qemu-img convert -f raw -O qcow2 latte_i1.raw latte_v2.qcow2
轉好 qcow2 image 上傳到 openstack 上
$ openstack image create --container-format bare --disk-format qcow2 --file latte_v2.qcow2 latte_v2

確認沒問題後,把剛剛產生出來的 latte_i1, latte_s1 刪除,一樣用 image list 找出那兩個 images 然後用 image delete 刪除。
$ openstack image list

$ openstack image delete 1af2092c-ccd6-4e79-84e9-2566b737c556
$ openstack image delete aa4a2f55-87c1-4a4a-8c56-8537193b4335
然後也找出快照把它刪除。
$ openstack volume snapshot list

$ openstack volume snapshot delete 0ee45900-f3e6-4fc5-9e44-76dd6f4414c0
最後把剛剛建立的 volume 把它刪除
$ openstack volume list

$ openstack volume delete f4b6e194-77bd-492b-825c-bf18e09c9a7b