Ubuntu 20.04
Sponsored Link

OpenStack Xena : How to use Heat2021/10/08

 
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 |
+--------------------------------------+------------+--------+
| ba8781c7-85ef-4872-957e-2c27b55275b2 | Ubuntu2004 | active |
+--------------------------------------+------------+--------+

root@dlp ~(keystone)#
openstack network list

+--------------------------------------+---------+--------------------------------------+
| ID                                   | Name    | Subnets                              |
+--------------------------------------+---------+--------------------------------------+
| 35816d4c-fa30-4901-8aa5-3749970fa706 | public  | 694a93ec-762f-4c2e-b8f3-4f5aa72b631e |
| a5d44a8a-4980-4c19-a53a-26af6aabd732 | private | 77ab8a8b-9cca-4f4a-90c6-a61f8a58f08d |
+--------------------------------------+---------+--------------------------------------+

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                  | 1a4e6d2c-8238-452d-9d8d-2ae8ed15e075 |
| stack_name          | Sample-Stack                         |
| description         | Heat Sample Template                 |
| creation_time       | 2021-10-08T00:03:01Z                 |
| 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 |
+--------------------------------------+--------------+----------------------------------+-----------------+----------------------+--------------+
| 1a4e6d2c-8238-452d-9d8d-2ae8ed15e075 | Sample-Stack | f4431102f2d9415590e3ac11c616858a | CREATE_COMPLETE | 2021-10-08T00:03: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   |
+--------------------------------------+----------------------+--------+-------------------------+------------+----------+
| bbebb224-925b-4f43-a318-1322cf6cd3c7 | Heat_Deployed_Server | ACTIVE | private=192.168.100.106 | 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             |
+----------------------------------+------------------+
| 2d9c6c4a1fbe4fd6aecbbc1aa6f939e8 | member           |
| 4ea4942f45f4490bb2885cc5a28526bf | heat_stack_user  |
| 633cd44ec02246dfb51b402274a7ae25 | heat_stack_owner |
| 95387bd895fc4e57b9f68cafe1e8376a | admin            |
| c06a64c6001e42df8f03b157d1b1fe1a | reader           |
| d09ce5f970e447cbb88558c4a91b0cef | CloudUser        |
+----------------------------------+------------------+

root@dlp ~(keystone)#
openstack project list

+----------------------------------+-----------+
| ID                               | Name      |
+----------------------------------+-----------+
| 611e3ba8938b475fb9dd8124603f18d3 | service   |
| f4431102f2d9415590e3ac11c616858a | admin     |
| facc545a7f9e4218884c40169158a2dc | hiroshima |
+----------------------------------+-----------+

root@dlp ~(keystone)#
openstack user list

+----------------------------------+-------------------+
| ID                               | Name              |
+----------------------------------+-------------------+
| cf04da25a4b04d5983a1bfaeaa5830f7 | admin             |
| 67b144163ad54b4fb3bad7c731fe0330 | glance            |
| 77db0f264e8647808f3823c2f20d5801 | nova              |
| 73565cb500354a309fa8174450ead2cd | placement         |
| 944be1c8d2cc49458dc29875c17ad7fc | neutron           |
| f5a7ffdd6e54434badbd75ba0e6d6ac2 | serverworld       |
| 8ea432b3a36a4fc9a90d96ad6c524413 | cinder            |
| 5589e11f41304de4abecf9ec264b12f2 | heat              |
| cbb9e7b95a47486fa3129e5fae4d531b | 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@network:~#
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@network:~#
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 |
+--------------------------------------+--------------+-----------------+----------------------+--------------+
| 95529dee-21aa-46b2-bd72-57c3dbebc7e6 | Sample-Stack | CREATE_COMPLETE | 2021-10-08T00:07:03Z | None         |
+--------------------------------------+--------------+-----------------+----------------------+--------------+

ubuntu@dlp ~(keystone)$
openstack server list

+--------------------------------------+----------------------+---------+-------------------------------------+------------+----------+
| ID                                   | Name                 | Status  | Networks                            | Image      | Flavor   |
+--------------------------------------+----------------------+---------+-------------------------------------+------------+----------+
| a399eba9-aca1-4f0f-855b-abfe3eded2bb | Heat_Deployed_Server | ACTIVE  | private=192.168.100.31              | Ubuntu2004 | m1.small |
| 4699d575-1d94-4024-8323-9dfa3599c8d2 | Ubuntu-2004          | SHUTOFF | private=10.0.0.249, 192.168.100.237 | Ubuntu2004 | m1.small |
+--------------------------------------+----------------------+---------+-------------------------------------+------------+----------+
Matched Content