Ubuntu 20.04
Sponsored Link

OpenStack Yoga : How to use Heat2022/04/06

 
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
+-----------+-----------+   +-----------+-----------+   +-----------+-----------+
|    [ Control Node ]   |   |    [ Storage Node ]   |   |    [ Compute Node ]   |
|                       |   |                       |   |                       |
|  MariaDB    RabbitMQ  |   |      Open vSwitch     |   |        Libvirt        |
|  Memcached  httpd     |   |     Neutron Server    |   |     Nova Compute      |
|  Keystone   Glance    |   |       OVN-Northd      |   |      Open vSwitch     |
|  Nova API             |   |     Cinder Volume     |   |   OVN Metadata Agent  |
|  Cinder API           |   |     iSCSI Target      |   |     OVN-Controller    |
|                       |   |    Heat API/Engine    |   |                       |
+-----------------------+   +-----------------------+   +-----------------------+

[1] Deploy Instances with Heat services and templates. The example below is on the Controle Node.
root@dlp ~(keystone)#
apt -y install python3-heatclient
# create a template for tests

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 |
+--------------------------------------+------------+--------+
| 53f6415a-1f98-485f-be0b-3f80edf523df | Ubuntu2004 | active |
+--------------------------------------+------------+--------+

root@dlp ~(keystone)#
openstack network list

+--------------------------------------+---------+--------------------------------------+
| ID                                   | Name    | Subnets                              |
+--------------------------------------+---------+--------------------------------------+
| 669dbb8b-17b9-4b1c-ba1a-34b24f1afaf1 | public  | ca423ec5-7604-403f-92ca-14f81ee603cd |
| 8cba72d5-e8c6-4003-9f68-5bb79c89ecc9 | private | e8c96f5c-0035-4966-a263-a84c54085d1e |
+--------------------------------------+---------+--------------------------------------+

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=Ubuntu2004;NetID=$Int_Net_ID" Sample-Stack

+---------------------+--------------------------------------+
| Field               | Value                                |
+---------------------+--------------------------------------+
| id                  | 918e8f04-f7e7-416a-b9ee-b174c998c63b |
| stack_name          | Sample-Stack                         |
| description         | Heat Sample Template                 |
| creation_time       | 2022-04-06T06:56:04Z                 |
| updated_time        | None                                 |
| stack_status        | CREATE_IN_PROGRESS                   |
| stack_status_reason | Stack CREATE started                 |
+---------------------+--------------------------------------+

# turn to [CREATE_COMPLETE] after few minutes later like follows

root@dlp ~(keystone)#
openstack stack list

+--------------------------------------+--------------+----------------------------------+-----------------+----------------------+--------------+
| ID                                   | Stack Name   | Project                          | Stack Status    | Creation Time        | Updated Time |
+--------------------------------------+--------------+----------------------------------+-----------------+----------------------+--------------+
| 918e8f04-f7e7-416a-b9ee-b174c998c63b | Sample-Stack | ddb7c08ba73a48eea040270d13a7b0cf | CREATE_COMPLETE | 2022-04-06T06:56:04Z | None         |
+--------------------------------------+--------------+----------------------------------+-----------------+----------------------+--------------+

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

root@dlp ~(keystone)#
openstack server list

+--------------------------------------+----------------------+--------+-------------------------+------------+----------+
| ID                                   | Name                 | Status | Networks                | Image      | Flavor   |
+--------------------------------------+----------------------+--------+-------------------------+------------+----------+
| e86641a5-912f-4bc8-a352-a3372ccfcd50 | Heat_Deployed_Server | ACTIVE | private=192.168.100.164 | Ubuntu2004 | m1.small |
+--------------------------------------+----------------------+--------+-------------------------+------------+----------+

# delete the instance

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

root@dlp ~(keystone)#
openstack stack 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 common users, it needs to change some settings.
root@dlp ~(keystone)#
openstack role list

+----------------------------------+------------------+
| ID                               | Name             |
+----------------------------------+------------------+
| 18131267bfb04d78a58221442aecc388 | heat_stack_owner |
| 2d9d1a4b052d402795c8bf5f9f83a1b7 | heat_stack_user  |
| 3eca53d4474f4d81bf2c85c8ea238f7c | reader           |
| 7eea1df857244828afbf10ac46356b23 | CloudUser        |
| dbd8fff588c74deaa4e2192ba1d92933 | member           |
| f125eaa73aed4ea2ba2b7cba02acd42c | admin            |
+----------------------------------+------------------+

root@dlp ~(keystone)#
openstack project list

+----------------------------------+-----------+
| ID                               | Name      |
+----------------------------------+-----------+
| c043fb355eff47e69642adfcd7a55620 | service   |
| d3434f55aa5541cfab5f13916da0697d | hiroshima |
| ddb7c08ba73a48eea040270d13a7b0cf | admin     |
+----------------------------------+-----------+

root@dlp ~(keystone)#
openstack user list

+----------------------------------+-------------------+
| ID                               | Name              |
+----------------------------------+-------------------+
| a8f07b80a7b34425a7778dee92319ef1 | admin             |
| 924b949b9fcd440abc7def686443cc21 | glance            |
| bcb1420b3c5145289f7f99e55a477705 | nova              |
| 2de5e07505a548829776022cd469ff64 | placement         |
| 5cd4b73f2cd74402b56be5c672dcfaa7 | neutron           |
| 95f196a1851c4b93b016871f7d5ded82 | serverworld       |
| 0bad5b870b814ba69014ae8c6a4f7ec2 | cinder            |
| 4922ef9d42f44be097324b38c6454ab8 | heat              |
| 99e220e856b94f29bae9c1f1e7b60ae7 | 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
# on the Node Neutron Server is running, change settings

root@dlp ~(keystone)#
vi /etc/neutron/policy.json
# create new
# overwrite some settings

{
  "create_port:fixed_ips:subnet_id": "",
  "create_port:allowed_address_pairs": "",
  "create_port:allowed_address_pairs:ip_address": "",
}

root@dlp ~(keystone)#
systemctl restart neutron-server

# that's OK, common users can create stacks

ubuntu@dlp ~(keystone)$
openstack stack list

+--------------------------------------+--------------+-----------------+----------------------+--------------+
| ID                                   | Stack Name   | Stack Status    | Creation Time        | Updated Time |
+--------------------------------------+--------------+-----------------+----------------------+--------------+
| 357508bd-2b99-4055-8545-8a66b0ceba1f | Sample-Stack | CREATE_COMPLETE | 2022-04-06T07:03:59Z | None         |
+--------------------------------------+--------------+-----------------+----------------------+--------------+

ubuntu@dlp ~(keystone)$
openstack server list

+--------------------------------------+----------------------+---------+------------------------------------+------------+----------+
| ID                                   | Name                 | Status  | Networks                           | Image      | Flavor   |
+--------------------------------------+----------------------+---------+------------------------------------+------------+----------+
| 4342a3bf-c1ca-482c-9a92-74af7c142c8a | Heat_Deployed_Server | ACTIVE  | private=192.168.100.37             | Ubuntu2004 | m1.small |
| 7ea894ee-3a91-4541-96ba-717ff45917c5 | Ubuntu-2004          | SHUTOFF | private=10.0.0.230, 192.168.100.12 | Ubuntu2004 | m1.small |
+--------------------------------------+----------------------+---------+------------------------------------+------------+----------+
Matched Content