Heat テンプレートの例
Heat テンプレートは、OpenStack HOT 仕様の定義に準拠した、有効な Heat Orchestration Template (HOT) です。
Heat Orchestration Template について詳しくは、OpenStack の「Template Guide」(http://docs.openstack.org/developer/heat/template_guide/) を参照してください。このガイドには、以下の情報があります。
- 概要および基本的な例 (http://docs.openstack.org/developer/heat/template_guide/hot_guide.html)
- Heat Orchestration Template 仕様 (http://docs.openstack.org/developer/heat/template_guide/hot_spec.html)
- OpenStack リソース・タイプおよび関連パラメーター (http://docs.openstack.org/developer/heat/template_guide/openstack.html)
テンプレートを作成する際には、パラメーターを使用し、ハードコーディングした値を使用しないようにすることをお勧めします。
以下の例 (例 1 および例 2) は OpenStack の「Template Guide」から引用したものであり、ハードコーディングした値を使用した場合とパラメーターを使用した場合の違いを示しています。
例 3 は、検索アノテーションを使用して、パラメーターに使用できる値のリストを生成する方法を示しています。これはユーザーが有効なパラメーター値を選択するのに役立ちます。
例 4 に、user_data セクションを使用して仮想マシンの admin パスワードを設定する方法を示します。
例 5 に、使用するストレージ接続グループと、ブート・ボリュームを配置するストレージ・テンプレートを指定して PowerVC に AIX サーバーまたは Linux on Power® サーバーをデプロイする方法を示します。
以下の検索アノテーションがサポートされます。
- SCOIMAGE
- リージョンのイメージ・リポジトリーからイメージを検索します。
- SCOFLAVOR
- リージョンで使用可能な選択からフレーバー・サイズを検索します。
- SCONETWORK
- リージョンで使用可能なネットワークを検索します。
- SCOKEY
- プロジェクトの登録キーを検索します。
注: Heat Orchestration Template は、フォーマットに関する問題の影響を受けやすくなっています。
テンプレート検証エラーを回避するために、正しいインデントを使用してください。
例 1
以下の例では、単一の仮想システムをデプロイする単純な Heat テンプレートを示します。これは、テンプレートでハードコーディングしたイメージ値、キー値、およびフレーバー値の単一の組み合わせに制限されています。
heat_template_version: 2013-05-23
description: Simple template to deploy a single compute instance with hardcoded values
resources:
my_instance:
type: OS::Nova::Server
properties:
key_name: my_key_pair_1
image: cirros-0.3.1-x86_64
flavor: m1.tiny
例 2
以下の例では、パラメーターを使用して単一の仮想システムをデプロイする Heat テンプレートを示します。パラメーターを使用しているため、これは他の構成で再使用可能です。
heat_template_version: 2013-05-23
description: Simple template to deploy a single compute instance with parameters
parameters:
key_name:
type: string
label: Key Name
description: Name of key-pair to be used for compute instance
image_id:
type: string
label: Image ID
description: Image to be used for compute instance
instance_type:
type: string
label: Instance Type
description: Type of instance (flavor) to be used
resources:
my_instance:
type: OS::Nova::Server
properties:
key_name: { get_param: key_name }
image: { get_param: image_id }
flavor: { get_param: instance_type }
例 3
以下の例は、パラメーター用の検索アノテーションを使用して、2 つの仮想マシン・インスタンスを持つスタックをデプロイするための単純な Heat テンプレートを示しています。
heat_template_version: 2013-05-23
description: Simple template to deploy a stack with two virtual machine instances
parameters:
image_name_1:
type: string
label: Image Name
description: SCOIMAGE Specify an image name for instance1
default: cirros-0.3.1-x86_64
image_name_2:
type: string
label: Image Name
description: SCOIMAGE Specify an image name for instance2
default: cirros-0.3.1-x86_64
network_id:
type: string
label: Network ID
description: SCONETWORK Network to be used for the compute instance
resources:
my_instance1:
type: OS::Nova::Server
properties:
image: { get_param: image_name_1 }
flavor: m1.small
networks:
- network : { get_param : network_id }
my_instance2:
type: OS::Nova::Server
properties:
image: { get_param: image_name_2 }
flavor: m1.tiny
networks:
- network : { get_param : network_id }
例 4
以下の例では、user_data セクションを使用して仮想マシンの admin パスワードを設定する単純な Heat テンプレートを示します。
heat_template_version: 2013-05-23
description: Simple template to set the admin password for a virtual machine
parameters:
key_name:
type: string
label: Key Name
description: SCOKEY Name of the key pair to be used for the compute instance
image_name:
type: string
label: Image Name
description: SCOIMAGE Name of the image to be used for the compute instance
password:
type: string
label: password
description: admin password
hidden: true
resources:
my_instance:
type: OS::Nova::Server
properties:
key_name: { get_param: key_name }
admin_user: sampleuser
image: { get_param: image_name }
flavor: m1.small
user_data:
str_replace:
template: |
#!/bin/bash
echo "Setting password to " $password
echo $password |passwd --stdin sampleuser
params:
$password: { get_param: password }
例 5
以下に示す例は、使用するストレージ接続グループと、ブート・ボリュームを配置するストレージ・テンプレートを指定して PowerVC に AIX サーバーまたは Linux on Power サーバーをデプロイするための単純な Heat テンプレートです。
heat_template_version: 2013-05-23
description: Template to Deploy on NPIV v7k storage only
parameters:
network_id1:
type: string
description: SCONETWORK ID of the (nova) network a server should be deployed to.
flavor_id:
type: string
description: SCOFLAVOR The flavor to be applied to the server DatabaseTierVM.
image:
type: string
label: Image
description: SCOIMAGE The Image to be deployed
resources:
heat:
type: OS::Nova::Server
properties:
image: { get_param: image }
flavor: { get_param: flavor_id }
availability_zone: D0EB
metadata: { selected-scg: d91acbbe-3d81-4279-b389-54b3ad4a1c8c, selected-storage-template: 0431b2f3-fea6-4aa5-b3fb-d0e82ccf5ebb }
networks:
- network : { get_param : network_id1 }
注: PowerVM® サーバーの可用性ゾーンを作成するには、OpenStack ダッシュボードの「ホスト集合」パネルを使用します。新しい可用性ゾーンを作成した場合は、必ず関連したドメインおよびプロジェクトに追加してから使用してください。selected-scg (ストレージ接続グループ) および selected-storage-template は、使用しようとしているイメージの Image_topology にあります。OpenStack コントローラーでは、glance image-show <image
id> コマンドを実行します。イメージ・トポロジーは、
そのイメージによってサポートされるストレージ接続グループおよびストレージ・テンプレートを指定します。