1. 前言swift
在openstack中,glance負責p_w_picpath,即鏡像相關的服務,鏡像是一個已經打包好的文件,內置有操做系統和預先部署好的軟件。基於p_w_picpath建立虛擬機,在openstack中是以backing file的形式建立的,即新建的虛擬機和鏡像文件之間創建一個鏈接,相關的內容,後續以博客的形式呈現。本文以最簡單的鏡像上傳爲例,演示在openstack中製做完鏡像以後,如何上傳到openstack雲環境中。centos
2. 經過glance操做api
獲取鏡像,查看鏡像信息app
[root@controller upload]# qemu-img info CentOS-7-x86_64-GenericCloud.qcow2c p_w_picpath: CentOS-7-x86_64-GenericCloud.qcow2c file format: qcow2 #格式爲qcow2 virtual size: 8.0G (8589934592 bytes) #空間大小 disk size: 410M cluster_size: 65536
2. 經過glance命令上傳至openstackide
[root@controller upload]# glance p_w_picpath-create --name centos-7 --disk-format qcow2 --container-format bare --min-disk 0 --min-ram 512 --is-public True --is-protected True --human-readable --progress --file CentOS-7-x86_64-GenericCloud.qcow2c [=================> ] 59% +------------------+--------------------------------------+ | Property | Value | +------------------+--------------------------------------+ | checksum | 8e27a90b433e7c1a4db3fe8b8af6d1ad | | container_format | bare | | created_at | 2016-01-21T01:58:13 | | deleted | False | | deleted_at | None | | disk_format | qcow2 | | id | 4cccb602-0222-4c47-857a-5079ec571976 | | is_public | True | | min_disk | 0 | | min_ram | 512 | | name | centos-7 | | owner | 842ab3268a2c47e6a4b0d8774de805ae | | protected | True | | size | 409.2MB | | status | active | | updated_at | 2016-01-21T01:58:21 | | virtual_size | None | +------------------+--------------------------------------+
3. 查看glance鏡像列表ui
[root@controller upload]# glance p_w_picpath-list +--------------------------------------+---------------+-------------+------------------+-------------+--------+ | ID | Name | Disk Format | Container Format | Size | Status | +--------------------------------------+---------------+-------------+------------------+-------------+--------+ | 6637990f-bcff-4ea7-a978-d3edeeb636d7 | centos-5.9-kg | qcow2 | bare | 2187460608 | active | | 4cccb602-0222-4c47-857a-5079ec571976 | centos-7 | qcow2 | bare | 429056512 | active | #上傳成功 | b6c049c5-c4af-4f50-bba5-38b6850d7f41 | centos-7.0 | raw | bare | 10737418240 | active | | 73379d54-10f8-42b9-94d3-16ca6640c4b0 | cfme | qcow2 | bare | 2052325376 | active | | 37aaedc7-6fe6-4fc8-b110-408d166b8e51 | cirrors | qcow2 | bare | 13200896 | active | | ff0f7d03-a553-4357-a819-c74e913d649f | win2k8 | qcow2 | bare | 3391881216 | active | +--------------------------------------+---------------+-------------+------------------+-------------+--------+
4. 查看p_w_picpath的詳細信息this
[root@controller upload]# glance p_w_picpath-show 4cccb602-0222-4c47-857a-5079ec571976 +------------------+--------------------------------------+ | Property | Value | +------------------+--------------------------------------+ | checksum | 8e27a90b433e7c1a4db3fe8b8af6d1ad | | container_format | bare | container個數 | created_at | 2016-01-21T01:58:13 | | deleted | False | | disk_format | qcow2 | 磁盤格式 | id | 4cccb602-0222-4c47-857a-5079ec571976 | | is_public | True | 是否共有 | min_disk | 0 | 磁盤最小大小 | min_ram | 512 | 內存最小大小 | name | centos-7 | 名字 | owner | 842ab3268a2c47e6a4b0d8774de805ae | | protected | True | 是否保護 | size | 429056512 | 鏡像大小 | status | active | | updated_at | 2016-01-21T01:58:21 | +------------------+--------------------------------------+
5. p_w_picpath的更新url
[root@controller upload]# glance p_w_picpath-update --is-protected False 4cccb602-0222-4c47-857a-5079ec571976 +------------------+--------------------------------------+ | Property | Value | +------------------+--------------------------------------+ | checksum | 8e27a90b433e7c1a4db3fe8b8af6d1ad | | container_format | bare | | created_at | 2016-01-21T01:58:13 | | deleted | False | | deleted_at | None | | disk_format | qcow2 | | id | 4cccb602-0222-4c47-857a-5079ec571976 | | is_public | True | | min_disk | 0 | | min_ram | 512 | | name | centos-7 | | owner | 842ab3268a2c47e6a4b0d8774de805ae | | protected | False | #設置不保護,有保護不能夠刪除 | size | 429056512 | | status | active | | updated_at | 2016-01-21T02:02:20 | | virtual_size | None | +------------------+--------------------------------------+
6. p_w_picpath的刪除操作系統
[root@controller upload]# glance p_w_picpath-delete 4cccb602-0222-4c47-857a-5079ec571976
3. 經過nova操做3d
除了經過glance操做openstack的p_w_picpath服務以外,還能夠經過nova命令操做,主要基於兩方面的考慮:1. 最初glance集成在nova的代碼中,到了E版才脫離出來,成爲一個單獨的項目,2. nova建立虛擬機的時候,須要經過API的方式調用glance,以獲取instance的鏡像,從而實現instance的建立。因此,也能夠經過nova的方式操做glance,實際上都是調用glance的底層實現鏡像的相關操做。與glance不一樣的是,nova提供了對鏡像的快照功能。
查看p_w_picpath
[root@controller upload]# nova p_w_picpath-list +--------------------------------------+---------------+--------+--------+ | ID | Name | Status | Server | +--------------------------------------+---------------+--------+--------+ | 6637990f-bcff-4ea7-a978-d3edeeb636d7 | centos-5.9-kg | ACTIVE | | | b6c049c5-c4af-4f50-bba5-38b6850d7f41 | centos-7.0 | ACTIVE | | | 73379d54-10f8-42b9-94d3-16ca6640c4b0 | cfme | ACTIVE | | | 37aaedc7-6fe6-4fc8-b110-408d166b8e51 | cirrors | ACTIVE | | | ff0f7d03-a553-4357-a819-c74e913d649f | win2k8 | ACTIVE | | +--------------------------------------+---------------+--------+--------+
2. 將instance轉換爲快照
root@controller upload]# nova p_w_picpath-create --show --poll c3e573aa-ea68-42fc-97be-609cf0907298 nova_p_w_picpath_test_by_happy Server snapshotting... 100% complete Finished +-------------------------------------+--------------------------------------+ | Property | Value | +-------------------------------------+--------------------------------------+ | OS-EXT-IMG-SIZE:size | 965541888 | #快照記錄元數據metadata的信息 | created | 2016-01-21T02:11:38Z | | id | 81c20616-fabd-419e-a286-37fd9b8cdb76 | | metadata base_p_w_picpath_ref | 5ce414b0-660a-46e1-ad0a-b842b2afc0b7 | | metadata p_w_picpath_location | snapshot | | metadata p_w_picpath_state | available | | metadata p_w_picpath_type | snapshot | | metadata instance_type_ephemeral_gb | 10 | | metadata instance_type_flavorid | 63a239ff-d557-4882-a9e4-1ebe24d98f3c | | metadata instance_type_id | 15 | | metadata instance_type_memory_mb | 2048 | | metadata instance_type_name | vmDev.F1 | | metadata instance_type_root_gb | 10 | | metadata instance_type_rxtx_factor | 1.0 | | metadata instance_type_swap | 0 | | metadata instance_type_vcpus | 1 | | metadata instance_uuid | c3e573aa-ea68-42fc-97be-609cf0907298 | | metadata network_allocated | True | | metadata owner_id | 842ab3268a2c47e6a4b0d8774de805ae | | metadata user_id | bc5e46fc4204497185ae3ca6f8b7affb | | minDisk | 10 | | minRam | 0 | | name | nova_p_w_picpath_test_by_happy | | progress | 100 | | server | c3e573aa-ea68-42fc-97be-609cf0907298 | | status | ACTIVE | | updated | 2016-01-21T02:14:20Z | +-------------------------------------+--------------------------------------+
3. 查看鏡像快照的詳細信息
[root@controller upload]# nova p_w_picpath-show 81c20616-fabd-419e-a286-37fd9b8cdb76 +-------------------------------------+--------------------------------------+ | Property | Value | +-------------------------------------+--------------------------------------+ | OS-EXT-IMG-SIZE:size | 965541888 | | created | 2016-01-21T02:11:38Z | | id | 81c20616-fabd-419e-a286-37fd9b8cdb76 | | metadata base_p_w_picpath_ref | 5ce414b0-660a-46e1-ad0a-b842b2afc0b7 | | metadata p_w_picpath_location | snapshot | | metadata p_w_picpath_state | available | | metadata p_w_picpath_type | snapshot | | metadata instance_type_ephemeral_gb | 10 | | metadata instance_type_flavorid | 63a239ff-d557-4882-a9e4-1ebe24d98f3c | | metadata instance_type_id | 15 | | metadata instance_type_memory_mb | 2048 | | metadata instance_type_name | vmDev.F1 | | metadata instance_type_root_gb | 10 | | metadata instance_type_rxtx_factor | 1.0 | | metadata instance_type_swap | 0 | | metadata instance_type_vcpus | 1 | | metadata instance_uuid | c3e573aa-ea68-42fc-97be-609cf0907298 | | metadata network_allocated | True | | metadata owner_id | 842ab3268a2c47e6a4b0d8774de805ae | | metadata user_id | bc5e46fc4204497185ae3ca6f8b7affb | | minDisk | 10 | | minRam | 0 | | name | nova_p_w_picpath_test_by_happy | | progress | 100 | | server | c3e573aa-ea68-42fc-97be-609cf0907298 | | status | ACTIVE | | updated | 2016-01-21T02:14:20Z | +-------------------------------------+--------------------------------------+
4. 刪除p_w_picpath
[root@controller upload]# nova p_w_picpath-delete 81c20616-fabd-419e-a286-37fd9b8cdb76
4. 總結
glance負責openstack中p_w_picpath的服務,p_w_picpath的製做能夠經過兩種方式:1. 新制做鏡像,2. 從現有的instance作snapshot,前者的功能由glance實現,後者的功能由nova實現。製做完鏡像以後,便可從鏡像中啓動虛擬機實例了。
5. 附錄
glance p_w_picpath-create的命令幫助信息
[root@controller upload]# glance help p_w_picpath-create usage: glance p_w_picpath-create [--id <IMAGE_ID>] [--name <NAME>] [--store <STORE>] [--disk-format <DISK_FORMAT>] [--container-format <CONTAINER_FORMAT>] [--owner <TENANT_ID>] [--size <SIZE>] [--min-disk <DISK_GB>] [--min-ram <DISK_RAM>] [--location <IMAGE_URL>] [--file <FILE>] [--checksum <CHECKSUM>] [--copy-from <IMAGE_URL>] [--is-public {True,False}] [--is-protected {True,False}] [--property <key=value>] [--human-readable] [--progress] Create a new p_w_picpath. Optional arguments: --id <IMAGE_ID> ID of p_w_picpath to reserve. --name <NAME> Name of p_w_picpath. #名字 --store <STORE> Store to upload p_w_picpath to. --disk-format <DISK_FORMAT> Disk format of p_w_picpath. Acceptable formats: ami, ari, #磁盤格式,支持aki, vhd, vmdk, raw, qcow2, vdi, and iso格式 aki, vhd, vmdk, raw, qcow2, vdi, and iso --container-format <CONTAINER_FORMAT> #容器格式,支持ami,ari, aki, bare, and ovf格式 Container format of p_w_picpath. Acceptable formats: ami, ari, aki, bare, and ovf. --owner <TENANT_ID> Tenant who should own p_w_picpath. --size <SIZE> Size of p_w_picpath data (in bytes). Only used with '-- location' and '--copy_from'. --min-disk <DISK_GB> Minimum size of disk needed to boot p_w_picpath (in #最小的磁盤,表示鏡像最小須要的磁盤空間,和flavor有關,若是過小,則建立vm失敗 gigabytes). --min-ram <DISK_RAM> Minimum amount of ram needed to boot p_w_picpath (in megabytes). --location <IMAGE_URL> URL where the data for this p_w_picpath already resides. For #位置,支持三種location,file和copy-from,location是一個url路徑 example, if the p_w_picpath data is stored in swift, you could specify 'swift://account:key@example.com/container/obj'. #本地文件 --file <FILE> Local file that contains disk p_w_picpath to be uploaded during creation. Alternatively, p_w_picpaths can be passed to the client via stdin. --checksum <CHECKSUM> Hash of p_w_picpath data used Glance can use for verification. Provide a md5 checksum here. --copy-from <IMAGE_URL> #遠程拷貝,相比於location,copy-from會直接拷貝,而location則指定定義url路徑 Similar to '--location' in usage, but this indicates that the Glance server should immediately copy the data and store it in its configured p_w_picpath store. --is-public {True,False} #設置是否共有 Make p_w_picpath accessible to the public. --is-protected {True,False} #是否保護標誌位,房子誤刪除 Prevent p_w_picpath from being deleted. --property <key=value> Arbitrary property to associate with p_w_picpath. May be used multiple times. --human-readable Print p_w_picpath size in a human-friendly format. #鏡像大小可讀,即MB,GB格式顯示 --progress Show upload progress bar. #顯示上傳的進度條
2. glance相關命令
[root@controller upload]# glance help usage: glance [--version] [-d] [-v] [--get-schema] [-k] [--cert-file CERT_FILE] [--key-file KEY_FILE] [--os-cacert <ca-certificate-file>] [--ca-file OS_CACERT] [--timeout TIMEOUT] [--no-ssl-compression] [-f] [--dry-run] [--ssl] [-H ADDRESS] [-p PORT] [--os-username OS_USERNAME] [-I OS_USERNAME] [--os-password OS_PASSWORD] [-K OS_PASSWORD] [--os-tenant-id OS_TENANT_ID] [--os-tenant-name OS_TENANT_NAME] [-T OS_TENANT_NAME] [--os-auth-url OS_AUTH_URL] [-N OS_AUTH_URL] [--os-region-name OS_REGION_NAME] [-R OS_REGION_NAME] [--os-auth-token OS_AUTH_TOKEN] [-A OS_AUTH_TOKEN] [--os-p_w_picpath-url OS_IMAGE_URL] [-U OS_IMAGE_URL] [--os-p_w_picpath-api-version OS_IMAGE_API_VERSION] [--os-service-type OS_SERVICE_TYPE] [--os-endpoint-type OS_ENDPOINT_TYPE] [-S OS_AUTH_STRATEGY] <subcommand> ... Command-line interface to the OpenStack Images API. Positional arguments: <subcommand> add DEPRECATED! Use p_w_picpath-create instead. #舊版的增刪改查,即add,delete,update,list,show,details clear DEPRECATED! delete DEPRECATED! Use p_w_picpath-delete instead. details DEPRECATED! Use p_w_picpath-list instead. p_w_picpath-create Create a new p_w_picpath. #新版的增刪改查,即p_w_picpath-create,p_w_picpath-delete,p_w_picpath-update,p_w_picpath-list,p_w_picpath-show p_w_picpath-delete Delete specified p_w_picpath(s). p_w_picpath-download Download a specific p_w_picpath. p_w_picpath-list List p_w_picpaths you can access. p_w_picpath-members DEPRECATED! Use member-list instead. p_w_picpath-show Describe a specific p_w_picpath. p_w_picpath-update Update a specific p_w_picpath. index DEPRECATED! Use p_w_picpath-list instead. member-add DEPRECATED! Use member-create instead. #若是p_w_picpath設置爲private,則能夠經過member的形式共享給其餘的tenant使用 member-create Share a specific p_w_picpath with a tenant. #包含member共享的相關操做,即member-create新建共享,member-delete刪除共享,member-list查看共享 member-delete Remove a shared p_w_picpath from a tenant. member-p_w_picpaths DEPRECATED! Use member-list instead. member-list Describe sharing permissions by p_w_picpath or tenant. members-replace DEPRECATED! show DEPRECATED! Use p_w_picpath-show instead. update DEPRECATED! Use p_w_picpath-update instead. help Display help about this program or one of its subcommands.