CentOS Stream 9
Sponsored Link

OpenStack Zed : How to use Heat2022/11/11

 
How to use the OpenStack Orchestration Service (Heat).
This example is based on the environment like follows.
------------+-----------------------------+-----------------------------+------------
            |                             |                             |
        eth0|10.0.0.30                eth0|10.0.0.50                eth0|10.0.0.51
+-----------+-----------+     +-----------+-----------+     +-----------+-----------+
|   [ dlp.srv.world ]   |     | [ network.srv.world ] |     |  [ node01.srv.world ] |
|     (Control Node)    |     |     (Network Node)    |     |     (Compute Node)    |
|                       |     |                       |     |                       |
|  MariaDB    RabbitMQ  |     |      Open vSwitch     |     |        Libvirt        |
|  Memcached  Nginx     |     |     Neutron Server    |     |      Nova Compute     |
|  Keystone   httpd     |     |      OVN-Northd       |     |      Open vSwitch     |
|  Glance     Nova API  |     |  Nginx  iSCSI Target  |     |   OVN Metadata Agent  |
|  Cinder API           |     |     Cinder Volume     |     |     OVN-Controller    |
|                       |     |    Heat API/Engine    |     |                       |
+-----------------------+     +-----------------------+     +-----------------------+

[1] Deploy Instances with Heat services and templates.
The example below is on the Control Node.
# install Heat client from Zed, EPEL, CRB

[root@dlp ~(keystone)]#
dnf --enablerepo=centos-openstack-zed,epel,crb -y install python3-heatclient
# create a template for test

[root@dlp ~(keystone)]#
vi sample-stack.yml
heat_template_version: 2021-04-16

description: Heat Sample Template

parameters:
  ImageID:
    type: string
    description: Image used to boot a server
  NetID:
    type: string
    description: Network ID for the server

resources:
  server1:
    type: OS::Nova::Server
    properties:
      name: "Heat_Deployed_Server"
      image: { get_param: ImageID }
      flavor: "m1.small"
      networks:
      - network: { get_param: NetID }

outputs:
  server1_private_ip:
    description: IP address of the server in the private network
    value: { get_attr: [ server1, first_address ] }

[root@dlp ~(keystone)]#
openstack image list

+--------------------------------------+----------------+--------+
| ID                                   | Name           | Status |
+--------------------------------------+----------------+--------+
| 8367cc21-61f4-480b-8d03-90c057c7a7cf | CentOS-Stream9 | active |
+--------------------------------------+----------------+--------+

[root@dlp ~(keystone)]#
openstack network list

+--------------------------------------+---------+--------------------------------------+
| ID                                   | Name    | Subnets                              |
+--------------------------------------+---------+--------------------------------------+
| 004ca400-3d79-4c1b-b8fb-bba1e273000e | public  | 80213093-ac95-469a-b4d9-8c6adc93cfe1 |
| c9c79a1d-136e-4036-8fe0-eaac79f05f5d | private | 85e66c6a-66eb-490f-a4fa-e21f91678c89 |
+--------------------------------------+---------+--------------------------------------+

[root@dlp ~(keystone)]#
Int_Net_ID=$(openstack network list | grep private | awk '{ print $2 }')
# create an instance from the template

[root@dlp ~(keystone)]#
openstack stack create -t sample-stack.yml --parameter "ImageID=CentOS-Stream9;NetID=$Int_Net_ID" Sample-Stack

+---------------------+--------------------------------------+
| Field               | Value                                |
+---------------------+--------------------------------------+
| id                  | 39417140-05b9-47b2-b92d-40876d5a1144 |
| stack_name          | Sample-Stack                         |
| description         | Heat Sample Template                 |
| creation_time       | 2022-11-11T00:29:01Z                 |
| updated_time        | None                                 |
| stack_status        | CREATE_IN_PROGRESS                   |
| stack_status_reason | Stack CREATE started                 |
+---------------------+--------------------------------------+

# turn to [CREATE_COMPLETE] after few minutes later

[root@dlp ~(keystone)]#
openstack stack list

+--------------------------------------+--------------+----------------------------------+-----------------+----------------------+--------------+
| ID                                   | Stack Name   | Project                          | Stack Status    | Creation Time        | Updated Time |
+--------------------------------------+--------------+----------------------------------+-----------------+----------------------+--------------+
| 39417140-05b9-47b2-b92d-40876d5a1144 | Sample-Stack | 939974d6fc8e400eb01f7dd749935ea3 | CREATE_COMPLETE | 2022-11-11T00:29:01Z | None         |
+--------------------------------------+--------------+----------------------------------+-----------------+----------------------+--------------+

# the instance is running which is created from the Heat template

[root@dlp ~(keystone)]#
openstack server list

+--------------------------------------+----------------------+--------+-------------------------+----------------+----------+
| ID                                   | Name                 | Status | Networks                | Image          | Flavor   |
+--------------------------------------+----------------------+--------+-------------------------+----------------+----------+
| 55681685-50f6-4252-a587-dee173e91129 | Heat_Deployed_Server | ACTIVE | private=192.168.100.243 | CentOS-Stream9 | m1.small |
+--------------------------------------+----------------------+--------+-------------------------+----------------+----------+

# delete the instance

[root@dlp ~(keystone)]#
openstack stack delete --yes Sample-Stack

[root@dlp ~(keystone)]#
openstack stack list
[root@dlp ~(keystone)]#
openstack server list


[2]
The guide for writing templates are opened on the official site below.
⇒ https://docs.openstack.org/heat/latest/template_guide/index.html
[3] If you'd like to use Heat with a common user, it needs to add the user in Heat role.
[root@dlp ~(keystone)]#
openstack role list

+----------------------------------+------------------+
| ID                               | Name             |
+----------------------------------+------------------+
| 16412daf1fb0451bbc38119fbe7fdd5e | heat_stack_owner |
| 2ed73129635949579e071bd01563ba4f | admin            |
| 8c46c138d04543a19500eb30170adc5a | reader           |
| ad273121353f477db37e30d683deb0d4 | CloudUser        |
| b5fd8fd9ddf94d19911472d768ef9f2c | heat_stack_user  |
| e5a78e58eab343b5ad161b837cb04677 | member           |
+----------------------------------+------------------+

[root@dlp ~(keystone)]#
openstack project list

+----------------------------------+-----------+
| ID                               | Name      |
+----------------------------------+-----------+
| 28b6e37c787240e4a975d3614821cc71 | hiroshima |
| 62f531f4d2934e75b8d7f11cd7d53be3 | service   |
| 939974d6fc8e400eb01f7dd749935ea3 | admin     |
+----------------------------------+-----------+

[root@dlp ~(keystone)]#
openstack user list

+----------------------------------+-------------------+
| ID                               | Name              |
+----------------------------------+-------------------+
| f00e5072d7d6488f935ea680256af89c | admin             |
| 78009f5643d240da9996dff0aee5cc37 | glance            |
| 7ed52b257a47436389a60aef689d20f0 | nova              |
| 2080b84b7e304486b33365a447963bc1 | placement         |
| 6f4af63a84f944f3a7a0c018ef64a4a1 | neutron           |
| 9e8824a151c949ad9105535ead452501 | serverworld       |
| 42de8b3de0c74f3e9f1622c89fc1a178 | cinder            |
| 03b59cb43c8547d4bf0a055dd9edd7a8 | heat              |
| e8c47aafd9324805b90b52f963dc6cad | heat_domain_admin |
+----------------------------------+-------------------+

# for example, add [serverworld] user in [hiroshima] project to [heat_stack_owner] role

[root@dlp ~(keystone)]#
openstack role add --project hiroshima --user serverworld heat_stack_owner
# that's OK, allowed common users can create stacks

[cent@dlp ~(keystone)]$
openstack stack list

+--------------------------------------+--------------+-----------------+----------------------+--------------+
| ID                                   | Stack Name   | Stack Status    | Creation Time        | Updated Time |
+--------------------------------------+--------------+-----------------+----------------------+--------------+
| bdd82a73-c300-4e92-b6dc-4a33bcadd0ad | Sample-Stack | CREATE_COMPLETE | 2022-11-11T00:33:47Z | None         |
+--------------------------------------+--------------+-----------------+----------------------+--------------+

[cent@dlp ~(keystone)]$
openstack server list

+--------------------------------------+----------------------+---------+------------------------------------+----------------+----------+
| ID                                   | Name                 | Status  | Networks                           | Image          | Flavor   |
+--------------------------------------+----------------------+---------+------------------------------------+----------------+----------+
| 9198ab3c-be9d-4a67-8818-9ceb111ffa41 | Heat_Deployed_Server | ACTIVE  | private=192.168.100.176            | CentOS-Stream9 | m1.small |
| 158685ed-8159-4aad-a294-3227b427f7e1 | CentOS-St9           | SHUTOFF | private=10.0.0.218, 192.168.100.75 | CentOS-Stream9 | m1.small |
+--------------------------------------+----------------------+---------+------------------------------------+----------------+----------+
Matched Content