Auto-scaling in OpenStack (2)

在上一篇文章中 (這裡),
我們跟隨官網上的範例, 寫了一個簡單的template,
然而, 我們回顧一下在nova上開啟虛擬機的程序,
包括: 指定虛擬機映象檔, 選擇虛擬機樣板 (flavor), 選擇登入金鑰 (key),
同時, 還要選擇虛擬機網路與防火牆規則,

在上一篇template中, 並不包括網路與防火牆部分,
因此, 若是直接採用上一篇的template, 會得到以下的結果:

| stack_status         | CREATE_FAILED                                                    |
| stack_status_reason  | Resource CREATE failed: BadRequest: Multiple possible            |
|                      | networks found, use a Network ID to be more specific.            |
|                      | (HTTP 400) (Request-ID: req-                                     |
|                      | 545827a4-ada9-4873-8337-d7b0f4627d59)                            |


錯誤訊息是指有多於一個以上的網路選擇,
所以heat不知道要在哪一個網路下開啟虛擬機.
因此, 我們找了一下其他資源, 並實作一個可行的template,

以下是所參考的template:

heat_template_version: 2013-05-23

description: Simple template to deploy a single compute instance

parameters:
  image:
    type: string
    label: Image name or ID
    description: Image to be used for compute instance
    default: cirros
  flavor:
    type: string
    label: Flavor
    description: Type of instance (flavor) to be used
    default: m1.small
  key:
    type: string
    label: Key name
    description: Name of key-pair to be used for compute instance
    default: my_key
  private_network:
    type: string
    label: Private network name or ID
    description: Network to attach instance to.
    default: ****-4b6e-81cd-d5c1c537e498

resources:
  my_instance:
    type: OS::Nova::Server
    properties:
      image: { get_param: image }
      flavor: { get_param: flavor }
      key_name: { get_param: key }
      networks:
        - network: { get_param: private_network }

outputs:
  instance_ip:
    description: IP address of the instance
    value: { get_attr: [my_instance, first_address] }

在這一份template中, 唯一的差別就是private_network這一段,
這裡我們填入了網路 (private network) 的識別號 (ID),
也就是 ****-4b6e-81cd-d5c1c537e498,
此號碼可以從網頁中, 網路詳細資訊看到,

=============================================
我嘗試填入名稱, 但是卻失敗...
error message: Resource CREATE failed: NoUniqueMatch:
(debug: 2016/7/17)
這是因為有舊的網路沒有清除乾淨...
# neutron net-list
+-----------------------------+---------+-------------------------------------------------+
| id                          | name    | subnets                                         |
+-----------------------------+---------+-------------------------------------------------+
| ****-46f4-83ab-52f69b0b37a8 | ext-net | ****-af57-3b779db91fd7 192.168.0.0/24           |
| ****-4b6e-81cd-d5c1c537e498 | net     | ****-4862-99e9-ceff2dbdd524 192.168.2.0/24      |
| ****-490a-b91e-8b22a0f80c05 | net     | ****-4ce7-9105-e6dcd310fb69 192.168.10.0/24     |
| ****-4fdc-9d82-2b407608f2f3 | net     | ****-4275-81bf-6ec1028cede2 192.168.1.0/24      |
+--------------------------------------+---------+----------------------------------------+
把多餘的net刪除後, 就可以直接用net名稱開啟stack.
=============================================

在source 登入身分後,
可以用heat comment開啟stack, 並查詢stack的狀態,
指令如下:

(cr) # heat stack-create first_stack -f first.yaml

+-----------------------------+-------------+--------------------+----------------------+
| id                          | stack_name  | stack_status       | creation_time        |
+-----------------------------+-------------+--------------------+----------------------+
| ****-41ab-ab6e-add9d3876dc8 | first_stack | CREATE_IN_PROGRESS | **************       |
+-----------------------------+-------------+--------------------+----------------------+

heat stack-show first_stack

| capabilities                | []
| creation_time               | ****
| description                 | Simple template to deploy a single compute instance
| disable_rollback            | True
| id                          | ****-41ab-ab6e-add9d3876dc8
| links                       | http://192.168.0.30:8004/v1/****
| notification_topics         | []
| outputs                     | [
|                             |   {
|                             |     "output_value": "192.168.2.103",
|                             |     "description": "IP address of the instance",
|                             |     "output_key": "instance_ip"
|                             |   }
|                             | ]
| parameters                  | {
|                             |   "OS::stack_id": "****-41ab-ab6e-add9d3876dc8
|                             |   "OS::stack_name": "first_stack",
|                             |   "image": "cirros",
|                             |   "key": "my_key",
|                             |   "private_network": "net",
|                             |   "flavor": "m1.small"
|                             | }
| stack_name                  | first_stack
| stack_status                | CREATE_COMPLETE
| stack_status_reason         | Stack CREATE completed successfully
| template_description        | Simple template to deploy a single compute instance
| timeout_mins                | None
| updated_time                | None


我們可以看到,
這份文件包含所使用的parameter和所定義輸出的output,
此外, 如果要變更template中使用的input參數,
不需要直接更改template, 可以用指令方式輸入,
例如:

heat stack-create second_stack -f first.yaml -P "key=my_key2;image=ubuntu"


這樣就修改了template中所使用的image,
以及登入所需要的金鑰.
需要注意的是, 這裡的名稱都必須要預先在openstack中創建, 並對應,
否則會出現無法對應, 導致stack無法開啟

參考資料:
https://developer.rackspace.com/blog/openstack-orchestration-in-depth-part-1-introduction-to-heat/

留言

熱門文章

LTE筆記: RSRP, RSSI and RSRQ

[WiFi] WiFi 網路的識別: BSS, ESS, SSID, ESSID, BSSID

LTE筆記: 波束成型 (beamforming) 和天線陣列