1 准备工作
找到一个安装了 OpenStack 的环境。
$ openstack --version
openstack 3.14.2
从这里下载cirros image。下载好后,执行下面命令:
$ glance image-create --name cirros --file ./cirros-0.4.0-x86_64-disk.img --container-format bare --disk-format qcow2
2 清理环境
$ openstack project list --user
得到project-id,如果系统中有残留的stack,可以通过下面命令删除:
$ openstack stack list --property tenant=
$ openstack stack delete
3 世界上最简单的 Heat Orchestration Template (HOT)
HEAT是OpenStack中的编排器,编写HOT模板类似于对HEAT编排器编程。
在编写之前,先了解一下当前系统中支持的HOT版本:
$ openstack orchestration template version list
+--------------------------------------+------+------------------------------+
| Version | Type | Aliases |
+--------------------------------------+------+------------------------------+
| AWSTemplateFormatVersion.2010-09-09 | cfn | |
| HeatTemplateFormatVersion.2012-12-12 | cfn | |
| heat_template_version.2013-05-23 | hot | |
| heat_template_version.2014-10-16 | hot | |
| heat_template_version.2015-04-30 | hot | |
| heat_template_version.2015-10-15 | hot | |
| heat_template_version.2016-04-08 | hot | |
| heat_template_version.2016-10-14 | hot | heat_template_version.newton |
| heat_template_version.2017-02-24 | hot | heat_template_version.ocata |
| heat_template_version.2017-09-01 | hot | heat_template_version.pike |
| heat_template_version.2018-03-02 | hot | heat_template_version.queens |
+--------------------------------------+------+------------------------------+
再了解一下当前系统中支持的flavor,接下来会用到:
$ openstack flavor list
+--------------------------------------+------------------------+-------+------+-----------+-------+-----------+
| ID | Name | RAM | Disk | Ephemeral | VCPUs | Is Public |
+--------------------------------------+------------------------+-------+------+-----------+-------+-----------+
| 29a0a5de-ed3a-4962-a7cd-757a389d8108 | rcp_large_isolated_v6 | 10240 | 10 | 0 | 4 | True |
| 29b169d4-a2ef-4d40-b34b-c4afc58dc5a5 | rcp_xlarge_v5 | 10240 | 10 | 0 | 8 | True |
| 3982daf3-f4c0-4dd9-8add-6543c491893d | rcp_xlarge_isolated_v5 | 10240 | 10 | 0 | 8 | True |
| 3a1a2ba4-7053-4d2f-9d1e-ac8cfb739b68 | rcp_tiny_isolated_v6 | 2048 | 10 | 0 | 2 | True |
| 3dce9e32-1518-4aca-9ffa-89e4a6a83d74 | rcp_small_v5 | 2048 | 10 | 0 | 4 | True |
| 4d5d3808-f9bf-4570-baa2-542a9cd7fb54 | rcp_medium_v5 | 4096 | 10 | 0 | 4 | True |
| 5b62c87f-d6d6-45bd-b406-60bf2cb79e33 | rcp_tiny_v6 | 2048 | 10 | 0 | 2 | True |
| 6a6858fc-4014-4571-a4cd-1d94dc1613aa | rcp_small_isolated_v6 | 2048 | 10 | 0 | 4 | True |
| a0637be2-f669-4387-9414-e5d814a98f58 | rcp_tiny_v5 | 2048 | 10 | 0 | 2 | True |
| abd811ab-bfe7-4063-ad46-b009fbc44abc | rcp_small_v6 | 2048 | 10 | 0 | 4 | True |
| bdb84ef5-8cbb-49e9-94b2-8df90b01c1f7 | rcp_medium_isolated_v6 | 4096 | 10 | 0 | 4 | True |
| bdf81eaa-815e-4a6f-8f46-671aee5bb148 | rcp_large_v6 | 10240 | 10 | 0 | 4 | True |
| c51c9537-076b-44cf-ae23-9bad4e45c253 | rcp_xlarge_v6 | 10240 | 10 | 0 | 8 | True |
| d2d7fc87-a65a-416f-8414-662ee3691cc3 | rcp_medium_v6 | 4096 | 10 | 0 | 4 | True |
| e57fbb28-1247-43ea-a673-02cd12ec0801 | rcp_xlarge_isolated_v6 | 10240 | 10 | 0 | 8 | True |
| f26559e0-02e6-474b-a5aa-98901b86ecd6 | rcp_large_v5 | 10240 | 10 | 0 | 4 | True |
+--------------------------------------+------------------------+-------+------+-----------+-------+-----------+
最后,选择一个network:
$ openstack network list | grep vlan-4
| b5eb741e-36c0-4799-82bf-76046971a0fd | extnet-vlan-4 | b32b6ea7-95d3-456d-ba5d-b83571a1f7b1, b952e880-f53d-4a00-90a3-f938ac74d91b |
现在可以开始编写HOT模板了。
创建一个文本文件,名字为 hello.yaml。其内容为:
heat_template_version: 2018-03-02
description: Simple template to deploy a virtual machine.
resources:
my_hello_vm:
type: OS::Nova::Server
properties:
image: cirros
flavor: rcp_tiny_v5
networks:
- network: extnet-vlan-4
4 创建 stack
$ openstack stack create -t hello.yaml xxx
+---------------------+----------------------------------------------+
| Field | Value |
+---------------------+----------------------------------------------+
| id | 2afee774-8e2d-42a5-89e4-fc72f86c91cc |
| stack_name | xxx |
| description | Simple template to deploy a virtual machine. |
| creation_time | 2019-02-21T06:43:54Z |
| updated_time | None |
| stack_status | CREATE_IN_PROGRESS |
| stack_status_reason | Stack CREATE started |
+---------------------+----------------------------------------------+
$ openstack project list --user cranuser8
+----------------------------------+-------+
| ID | Name |
+----------------------------------+-------+
| 6bcb7e7677a5449196fd56565f68fc7f | cran8 |
+----------------------------------+-------+
$ openstack stack list --property tenant=6bcb7e7677a5449196fd56565f68fc7f --short
+--------------------------------------+------------+----------------------------------+-----------------+
| ID | Stack Name | Project | Stack Status |
+--------------------------------------+------------+----------------------------------+-----------------+
| 2afee774-8e2d-42a5-89e4-fc72f86c91cc | xxx | 6bcb7e7677a5449196fd56565f68fc7f | CREATE_COMPLETE |
+--------------------------------------+------------+----------------------------------+-----------------+
$ nova list
+--------------------------------------+------------------------------+--------+------------+-------------+-------------------------------------------------------------+
| ID | Name | Status | Task State | Power State | Networks |
+--------------------------------------+------------------------------+--------+------------+-------------+-------------------------------------------------------------+
| 621d717d-66c5-43b0-9b49-7f0dcfd26f79 | xxx-my_hello_vm-avmsaydhfhp5 | ACTIVE | - | Running | extnet-vlan-4=2a00:8a00:8000:5002:0:17:0:405, 10.107.116.36 |
+--------------------------------------+------------------------------+--------+------------+-------------+-------------------------------------------------------------+
5 删除 stack
$ openstack stack delete xxx
参考文献
https://github.com/rackerlabs/heat-tutorial/tree/master/101.Hello-Compute
Heat Orchestration Template (HOT) Guide