1 准备工作
找到一个安装了 OpenStack 的环境。
$ openstack --version
openstack 3.14.2
从这里下载cirros image。下载好后,执行下面命令:
$ glance image-create --name cirros --file ./cirros-0.3.5-x86_64-disk.img --container-format bare --disk-format qcow2
2 清理环境
$ openstack project list --user <user-name>
得到project-id,如果系统中有残留的stack,可以通过下面命令删除:
$ openstack stack list --property tenant=<project-id>
$ openstack stack delete <stack-name or stack-id>
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 |
+--------------------------------------+------------------------+-------+------+-----------+-------+-----------+
| 08c87409-5f58-4a7a-8435-fbef92641381 | rcp_xlarge_v5 | 10240 | 10 | 0 | 8 | True |
| 0d205991-d9ea-4518-adfa-c17fe76e3b32 | rcp_medium_v4 | 4096 | 10 | 0 | 4 | True |
| 1558b453-957b-431e-b327-3bb0072ae872 | rcp_small_v5 | 2048 | 10 | 0 | 4 | True |
| 16bdc05a-92f0-42ce-a1ba-2f087ae162c3 | rcp_medium_v5 | 4096 | 10 | 0 | 4 | True |
| 1f08f259-da59-4581-85c0-99dc225ee6ff | rcp_tiny_v5 | 2048 | 10 | 0 | 2 | True |
| 49a1f8c9-6a53-4698-9aa6-6b13da0c6f6c | rcp_tiny_v4 | 2048 | 10 | 0 | 2 | True |
| 5d1ed462-10e2-4abb-b42f-9d1ecca6cffa | rcp_large_v5 | 10240 | 10 | 0 | 4 | True |
| 772ba087-1348-475e-a272-2184b5fd5631 | rcp_xlarge_isolated_v5 | 10240 | 10 | 0 | 8 | True |
| 98daafed-9d23-4d58-a889-3da01cc4e40d | rcp_large_v4 | 10240 | 10 | 0 | 4 | True |
| bb2fc265-1675-407d-a049-e29821f1b174 | rcp_small_v4 | 2048 | 10 | 0 | 4 | True |
| e27f034e-f0a2-456c-bb7f-82f632063aaa | rcp_xlarge_v4 | 10240 | 10 | 0 | 8 | 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_v4
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
网友评论