[Open Stack] Install Image Service (glance) - OpenStack Installation Guide For Ubuntu 12.04 (LTS) Havana [3]

3. Cấu hình Image Service (glance)
Glance được sử dụng để quản lý virtual disk images, người dùng có thể thêm các images của hệ điều hành hoặc khởi chạy hệ điều hành mới từ snapshoot.
B1. Cài đặt glance
apt-get install glance

B2. Tạo database để lưu trữ thông tin của Image Service
mysql -u root -p
CREATE DATABASE glance;
GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' \
IDENTIFIED BY 'glance123';
GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' \
IDENTIFIED BY 'glance123';
GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'controller' \
IDENTIFIED BY 'glance123';
B3. Chúng ta khai báo database mySQL trong cả 2 file /etc/glance/glance-api.conf và  /etc/glance/glance-registry.conf 
# SQLAlchemy connection string for the reference implementation
# registry server. Any valid SQLAlchemy connection string is fine.
sql_connection = mysql://glance:glance123@controller/glance
Mặc định keystone sử dụng sqlite, xóa database này vì không dùng tới:
rm -rf /var/lib/glance/glance.sqlite
Tạo database và khởi động lại glance:
glance-manage db_sync
service glance-registry restart
service glance-api restart

B4. Khởi tạo 1 glance user để Image Service có thể xác thực với Identity Service.
keystone user-create --name=glance --pass=glance123 \
   --email=glance@controller.com
keystone user-role-add --user=glance --tenant=service --role=admin
B5. Chỉnh sửa 2 file /etc/glance/glance-api.conf và  /etc/glance/glance-registry.conf 
[keystone_authtoken]
auth_host = controller
auth_port = 35357
auth_protocol = http
admin_tenant_name = service
admin_user = glance
admin_password = glance123

[filter:authtoken]
paste.filter_factory=keystoneclient.middleware.auth_token:filter_factory
auth_host=controller
admin_user=glance
admin_tenant_name=service
admin_password=glance123
B6. Đăng ký Image Service với Identity Service
keystone service-create --name=glance --type=image \
  --description="Glance Image Service"
Hiển thị:
+-------------+----------------------------------+
|   Property  |              Value               |
+-------------+----------------------------------+
| description |       Glance Image Service       |
|      id     | e1a60af3811a4201851da3bfd88448dd |
|     name    |              glance              |
|     type    |              image               |
+-------------+----------------------------------+
B7. Sử dụng ID ở trên để tạo endpoint
keystone endpoint-create \
  --service-id=e1a60af3811a4201851da3bfd88448dd \
  --publicurl=http://controller:9292 \
  --internalurl=http://controller:9292 \
  --adminurl=http://controller:9292
B8. Khởi động lại service glance
service glance-registry restart
service glance-api restart
B9. Import image của 1 hệ điều hành vào OpenStack (lưu ý rằng các image này phải hỗ trợ OpenStack), ở đây tôi sử dụng CirrOS - là một image được tinh giản cho mục đích test.
- Download image:
mkdir /etc/glance/images/
wget http://cdn.download.cirros-cloud.net/0.3.1/cirros-0.3.1-x86_64-disk.img
- Upload image vừa down vào Image Service:
glance image-create --name="CirrOS" --disk-format=qcow2 \
  --container-format=bare --is-public=true < cirros-0.3.1-x86_64-disk.img
Các thông số như disk-format, container-format các bạn tham khảo tại link [3]
- Kiểm tra image đã upload thành công vào Image Service chưa:
glance image-list
Hiển thị:

+--------------------------------------+--------------+-------------+------------------+----------+--------+
| ID                                   | Name         | Disk Format | Container Format | Size     | Status |
+--------------------------------------+--------------+-------------+------------------+----------+--------+
| 27e53b72-d6d7-4006-81ea-7cc0ef188fc5 | CirrOS 0.3.1 | qcow2       | bare             | 13147648 | active |
+--------------------------------------+--------------+-------------+------------------+----------+--------+