Creating Stack By Heat

作者:Maxwell Li
日期:2016/12/20
未经作者允许,禁止转载本文任何内容。如需转载请留言。


In environments that include the Orchestration service, you can create a stack that launches an instance.

Create a template

The Orchestration service uses templates to describe stacks. To learn about the template language, see the Template Guide in the Heat developer documentation.

Create the admin-template.yml file with the following content.

heat_template_version: 2015-10-15
description: Launch a basic instance with CirrOS image using the
             ``m1.tiny`` flavor, ``heat_key`` key,  and one network.

parameters:
  NetID:
    type: string
    description: Network ID to use for the instance.

resources:
  server:
    type: OS::Nova::Server
    properties:
      image: cirros
      flavor: m1.tiny
      key_name: heat_key
      networks:
      - network: { get_param: NetID }

outputs:
  instance_name:
    description: Name of the instance.
    value: { get_attr: [ server, name ] }
  instance_ip:
    description: IP address of the instance.
    value: { get_attr: [ server, first_address ] }

Preparing to create a stack

1. Source the admin credentials.

$ source /opt/admin-openrc.sh

2. Download the source image.

$ wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img

3. Upload the image to the Image service using the QCOW2 disk format, bare container format, and public visibility so all projects can access it.

$ glance image-create --name "cirros" \
    --file cirros-0.3.4-x86_64-disk.img  \
    --disk-format qcow2 --container-format bare

4. Confirm upload of the image and validate attributes

$ openstack image list
+--------------------------------------+--------+
| ID                                   | Name   |
+--------------------------------------+--------+
| 2b69f73b-000c-493d-bcb9-ab18b32fdc8d | cirros |
+--------------------------------------+--------+

5. Create the different flavors.

$ openstack flavor create --id 0 --vcpus 1 --ram 64 --disk 1 m1.nano
$ openstack flavor create --id 1 --vcpus 1 --ram 512 --disk 1 m1.tiny
$ openstack flavor create --id 2 --vcpus 1 --ram 2048 --disk 20 m1.small
$ openstack flavor create --id 3 --vcpus 2 --ram 4096 --disk 40 m1.medium
$ openstack flavor create --id 4 --vcpus 4 --ram 8192 --disk 80 m1.large
$ openstack flavor create --id 5 --vcpus 8 --ram 16384 --disk 160 m1.xlarge

6. Your cloud will have different flavors and images available for launching instances, you can discover what is available by running.

$ openstack flavor list
+----+-----------+-------+------+-----------+-------+-----------+
| ID | Name      |   RAM | Disk | Ephemeral | VCPUs | Is Public |
+----+-----------+-------+------+-----------+-------+-----------+
| 0  | m1.nano   |    64 |    1 |         0 |     1 | True      |
| 1  | m1.tiny   |   512 |    1 |         0 |     1 | True      |
| 2  | m1.small  |  2048 |   20 |         0 |     1 | True      |
| 3  | m1.medium |  4096 |   40 |         0 |     2 | True      |
| 4  | m1.large  |  8192 |   80 |         0 |     4 | True      |
| 5  | m1.xlarge | 16384 |  160 |         0 |     8 | True      |
+----+-----------+-------+------+-----------+-------+-----------+

7. To allow you to SSH into instances launched by Heat, a keypair will be generated:

$ openstack keypair create heat_key > heat_key.priv
$ chmod 600 heat_key.priv

Create a stack

Create a stack using the admin-template.yml template.

1. Determine available networks.

$ openstack network list
+--------------------------------------+---------+--------------------------------------+
| ID                                   | Name    | Subnets                              |
+--------------------------------------+---------+--------------------------------------+
| 5314b101-d2cd-4082-a798-f70610d43d96 | ext-net | 6b9dc3eb-7989-46b9-aa66-7c28d3bcf606 |
+--------------------------------------+---------+--------------------------------------+

2. Set the NET_ID environment variable to reflect the ID of a network. For example, using the provider network.

$ export NET_ID=$(openstack network list | awk '/ ext-net / { print $2 }')

3. Create a stack of one CirrOS instance on the ext-net network.

$ openstack stack create -t admin-template.yml --parameter "NetID=$NET_ID" stack
+---------------------+----------------------------------------------------------------------------+
| Field               | Value                                                                      |
+---------------------+----------------------------------------------------------------------------+
| id                  | d19fe979-675b-4197-83f5-e24919e7f011                                       |
| stack_name          | stack                                                                      |
| description         | Launch a basic instance with CirrOS image using the ``m1.tiny`` flavor,    |
|                     | ``heat_key`` key,  and one network.                                        |
| creation_time       | 2016-11-17T07:39:52Z                                                       |
| updated_time        | None                                                                       |
| stack_status        | CREATE_IN_PROGRESS                                                         |
| stack_status_reason | Stack CREATE started                                                       |
+---------------------+----------------------------------------------------------------------------+

Note: After a few seconds, the stack_status should change from IN_PROGRESS to CREATE_COMPLETE.

4. After a short time, verify successful creation of the stack.

$ openstack stack list
+-------------------------+------------+-----------------+----------------------+--------------+
| ID                      | Stack Name | Stack Status    | Creation Time        | Updated Time |
+-------------------------+------------+-----------------+----------------------+--------------+
| d19fe979-675b-4197-83f5 | stack      | CREATE_COMPLETE | 2016-11-17T07:39:52Z | None         |
| -e24919e7f011           |            |                 |                      |              |
+-------------------------+------------+-----------------+----------------------+--------------+

5. Show the name and IP address of the instance and compare with the output of the OpenStack client:

$ openstack stack output show --all stack
+---------------+-------------------------------------------------+
| Field         | Value                                           |
+---------------+-------------------------------------------------+
| instance_name | {                                               |
|               |   "output_value": "stack-server-oqjxndmd5dk3",  |
|               |   "output_key": "instance_name",                |
|               |   "description": "Name of the instance."        |
|               | }                                               |
| instance_ip   | {                                               |
|               |   "output_value": "192.168.116.233",            |
|               |   "output_key": "instance_ip",                  |
|               |   "description": "IP address of the instance."  |
|               | }                                               |
+---------------+-------------------------------------------------+

$ openstack server list
+------------------------+------------------------+--------+-------------------------+------------+
| ID                     | Name                   | Status | Networks                | Image Name |
+------------------------+------------------------+--------+-------------------------+------------+
| 144c9222-dd87-4ca0     | stack-server-          | ACTIVE | ext-net=192.168.116.233 | cirros     |
| -899a-051c7fff79eb     | oqjxndmd5dk3           |        |                         |            |
+------------------------+------------------------+--------+-------------------------+------------+

Delete the stack.

$ openstack stack delete --yes stack

Note: The list operation will show no running stack.:

You can explore other heat commands by referring to theHeat chapter of the OpenStack Command-Line Interface Reference then read the Template Guide and start authoring your own templates.

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 215,634评论 6 497
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,951评论 3 391
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 161,427评论 0 351
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,770评论 1 290
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,835评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,799评论 1 294
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,768评论 3 416
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,544评论 0 271
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,979评论 1 308
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,271评论 2 331
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,427评论 1 345
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,121评论 5 340
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,756评论 3 324
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,375评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,579评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,410评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,315评论 2 352

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,322评论 0 10
  • 旧日旧事,常忆常新。那些过去的旧光阴,就像一匹剪不断的旧丝绸,结实而有弹性,老绿却有光泽。旧日由旧事串成,...
    冰夫阅读 159评论 0 0
  • 前一阵子抱着试一试的态度,参加了心理学知识与技能系统的授课导师梁船长的实用心理学训练营,头几天自我感觉很好,在认识...
    魏云阅读 1,895评论 0 1
  • 在openSUSE软件中心找到了 https://software.opensuse.org/package/ch...
    KINGZ1993阅读 978评论 0 0
  • 子曰:“射不主皮,为力不同科,古之道也。” 子贡欲去告朔饩羊。子曰:“赐也!尔爱其羊,我爱其礼。” 子曰:“事君尽...
    苏苏落叶阅读 188评论 0 0