Creating Stack By Heat

版权声明:未经作者允许,禁止转载本文任何内容。如需转载请留言。 https://blog.csdn.net/liyuenan93/article/details/82117614

作者:Maxwell Li
日期:2016/12/20
未经作者允许,禁止转载本文任何内容。如需转载请留言。


In environments that include the Orchestration service, you can create a stack that launches an instance.

Create a template

The Orchestration service uses templates to describe stacks. To learn about the template language, see the Template Guide in the Heat developer documentation.

Create the admin-template.yml file with the following content.

heat_template_version: 2015-10-15
description: Launch a basic instance with CirrOS image using the
             ``m1.tiny`` flavor, ``heat_key`` key,  and one network.

parameters:
  NetID:
    type: string
    description: Network ID to use for the instance.

resources:
  server:
    type: OS::Nova::Server
    properties:
      image: cirros
      flavor: m1.tiny
      key_name: heat_key
      networks:
      - network: { get_param: NetID }

outputs:
  instance_name:
    description: Name of the instance.
    value: { get_attr: [ server, name ] }
  instance_ip:
    description: IP address of the instance.
    value: { get_attr: [ server, first_address ] }

Preparing to create a stack

1. Source the admin credentials.

$ source /opt/admin-openrc.sh

2. Download the source image.

$ wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img

3. Upload the image to the Image service using the QCOW2 disk format, bare container format, and public visibility so all projects can access it.

$ glance image-create --name "cirros" \
    --file cirros-0.3.4-x86_64-disk.img  \
    --disk-format qcow2 --container-format bare

4. Confirm upload of the image and validate attributes

$ openstack image list
+--------------------------------------+--------+
| ID                                   | Name   |
+--------------------------------------+--------+
| 2b69f73b-000c-493d-bcb9-ab18b32fdc8d | cirros |
+--------------------------------------+--------+

5. Create the different flavors.

$ openstack flavor create --id 0 --vcpus 1 --ram 64 --disk 1 m1.nano
$ openstack flavor create --id 1 --vcpus 1 --ram 512 --disk 1 m1.tiny
$ openstack flavor create --id 2 --vcpus 1 --ram 2048 --disk 20 m1.small
$ openstack flavor create --id 3 --vcpus 2 --ram 4096 --disk 40 m1.medium
$ openstack flavor create --id 4 --vcpus 4 --ram 8192 --disk 80 m1.large
$ openstack flavor create --id 5 --vcpus 8 --ram 16384 --disk 160 m1.xlarge

6. Your cloud will have different flavors and images available for launching instances, you can discover what is available by running.

$ openstack flavor list
+----+-----------+-------+------+-----------+-------+-----------+
| ID | Name      |   RAM | Disk | Ephemeral | VCPUs | Is Public |
+----+-----------+-------+------+-----------+-------+-----------+
| 0  | m1.nano   |    64 |    1 |         0 |     1 | True      |
| 1  | m1.tiny   |   512 |    1 |         0 |     1 | True      |
| 2  | m1.small  |  2048 |   20 |         0 |     1 | True      |
| 3  | m1.medium |  4096 |   40 |         0 |     2 | True      |
| 4  | m1.large  |  8192 |   80 |         0 |     4 | True      |
| 5  | m1.xlarge | 16384 |  160 |         0 |     8 | True      |
+----+-----------+-------+------+-----------+-------+-----------+

7. To allow you to SSH into instances launched by Heat, a keypair will be generated:

$ openstack keypair create heat_key > heat_key.priv
$ chmod 600 heat_key.priv

Create a stack

Create a stack using the admin-template.yml template.

1. Determine available networks.

$ openstack network list
+--------------------------------------+---------+--------------------------------------+
| ID                                   | Name    | Subnets                              |
+--------------------------------------+---------+--------------------------------------+
| 5314b101-d2cd-4082-a798-f70610d43d96 | ext-net | 6b9dc3eb-7989-46b9-aa66-7c28d3bcf606 |
+--------------------------------------+---------+--------------------------------------+

2. Set the NET_ID environment variable to reflect the ID of a network. For example, using the provider network.

$ export NET_ID=$(openstack network list | awk '/ ext-net / { print $2 }')

3. Create a stack of one CirrOS instance on the ext-net network.

$ openstack stack create -t admin-template.yml --parameter "NetID=$NET_ID" stack
+---------------------+----------------------------------------------------------------------------+
| Field               | Value                                                                      |
+---------------------+----------------------------------------------------------------------------+
| id                  | d19fe979-675b-4197-83f5-e24919e7f011                                       |
| stack_name          | stack                                                                      |
| description         | Launch a basic instance with CirrOS image using the ``m1.tiny`` flavor,    |
|                     | ``heat_key`` key,  and one network.                                        |
| creation_time       | 2016-11-17T07:39:52Z                                                       |
| updated_time        | None                                                                       |
| stack_status        | CREATE_IN_PROGRESS                                                         |
| stack_status_reason | Stack CREATE started                                                       |
+---------------------+----------------------------------------------------------------------------+

Note: After a few seconds, the stack_status should change from IN_PROGRESS to CREATE_COMPLETE.

4. After a short time, verify successful creation of the stack.

$ openstack stack list
+-------------------------+------------+-----------------+----------------------+--------------+
| ID                      | Stack Name | Stack Status    | Creation Time        | Updated Time |
+-------------------------+------------+-----------------+----------------------+--------------+
| d19fe979-675b-4197-83f5 | stack      | CREATE_COMPLETE | 2016-11-17T07:39:52Z | None         |
| -e24919e7f011           |            |                 |                      |              |
+-------------------------+------------+-----------------+----------------------+--------------+

5. Show the name and IP address of the instance and compare with the output of the OpenStack client:

$ openstack stack output show --all stack
+---------------+-------------------------------------------------+
| Field         | Value                                           |
+---------------+-------------------------------------------------+
| instance_name | {                                               |
|               |   "output_value": "stack-server-oqjxndmd5dk3",  |
|               |   "output_key": "instance_name",                |
|               |   "description": "Name of the instance."        |
|               | }                                               |
| instance_ip   | {                                               |
|               |   "output_value": "192.168.116.233",            |
|               |   "output_key": "instance_ip",                  |
|               |   "description": "IP address of the instance."  |
|               | }                                               |
+---------------+-------------------------------------------------+

$ openstack server list
+------------------------+------------------------+--------+-------------------------+------------+
| ID                     | Name                   | Status | Networks                | Image Name |
+------------------------+------------------------+--------+-------------------------+------------+
| 144c9222-dd87-4ca0     | stack-server-          | ACTIVE | ext-net=192.168.116.233 | cirros     |
| -899a-051c7fff79eb     | oqjxndmd5dk3           |        |                         |            |
+------------------------+------------------------+--------+-------------------------+------------+

Delete the stack.

$ openstack stack delete --yes stack

Note: The list operation will show no running stack.:

You can explore other heat commands by referring to theHeat chapter of the OpenStack Command-Line Interface Reference then read the Template Guide and start authoring your own templates.

猜你喜欢

转载自blog.csdn.net/liyuenan93/article/details/82117614