找回密码
 注册
查看: 4880|回复: 3

编排新添加模板

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2017-11-20 15:59:49 | 显示全部楼层 |阅读模式
创建一个模板¶
Orchestration服务使用模版来描述栈。想要学习模版语言,参考`Heat developer documentation <http://docs.openstack.org/developer/heat/index.html>`__中的`the Template Guide <http://docs.openstack.org/develo ... e/index.html>`__
  • 使用下面的内容创建``demo-template.yml``文件:
    heat_template_version: 2015-10-15description: Launch a basic instance using the ``m1.tiny`` flavor and one network.parameters:  ImageID:    type: string    description: Image to use for the instance.  NetID:    type: string    description: Network ID to use for the instance.resources:  server:    type: OS::Nova::Server    properties:      image: { get_param: ImageID }      flavor: m1.tiny      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  }$ x& q/ p( I1 }* p, g: ^1 c" h
5 j* [9 n- R% i# `( x
创建一个栈¶
使用``demo-template.yml`` 模版创建一个栈。
  • 加载 ``demo``凭证,作为非管理员项目执行下面的步骤:
    $ source demo-openrc.sh
  • 检测可用网络。
    $ neutron net-list+--------------------------------------+---------+-----------------------------------------------------+| id                                   | name    | subnets                                             |+--------------------------------------+---------+-----------------------------------------------------+| 9c13da20-4c4f-486f-a4e9-692e9ea397f1 | public  | 85140549-1f54-4bc6-a2c5-f08428de3f7a 203.0.113.0/24 || 303a9aaf-40fd-4fc8-9213-39bff933467b | private | ddeba0b1-21eb-471a-8f31-10f0e290cc36 172.16.1.0/24  |+--------------------------------------+---------+-----------------------------------------------------+
    # n& _# s- E7 F/ [: c& {/ K
      [+ C4 H% y7 {8 Q4 [
    6 Z9 u) k/ j- `/ i( y: t4 B注解4 A( ~2 l  U" g: S, c( |2 P  ]
    这个输出可能跟你的环境有所不同。
  • 设置``NET_ID``环境变量表示网络ID。例如,使用``public`` 网络:
    $ export NET_ID=$(neutron net-list | awk '/ public / { print $2 }')
  • 在公共网络上创建一个CirrOS实例的栈:
    $ heat stack-create -f demo-template.yml -P "ImageID=cirros;NetID=$NET_ID" stack+--------------------------------------+------------+--------------------+---------------------+--------------+| id                                   | stack_name | stack_status       | creation_time       | updated_time |+--------------------------------------+------------+--------------------+---------------------+--------------+| dbf46d1b-0b97-4d45-a0b3-9662a1eb6cf3 | stack      | CREATE_IN_PROGRESS | 2015-10-13T15:27:20 | None         |+--------------------------------------+------------+--------------------+---------------------+--------------+
  • 等一段时间,验证栈的创建是否成功:
    $ heat stack-list+--------------------------------------+------------+-----------------+---------------------+--------------+| id                                   | stack_name | stack_status    | creation_time       | updated_time |+--------------------------------------+------------+-----------------+---------------------+--------------+| dbf46d1b-0b97-4d45-a0b3-9662a1eb6cf3 | stack      | CREATE_COMPLETE | 2015-10-13T15:27:20 | None         |+--------------------------------------+------------+-----------------+---------------------+--------------+
  • 查看实例的名称和IB地址并和``nova`` 命令的输出比较:
    $ heat output-show --all stack[  {    "output_value": "stack-server-3nzfyfofu6d4",    "description": "Name of the instance.",    "output_key": "instance_name"  },  {    "output_value": "10.4.31.106",    "description": "IP address of the instance.",    "output_key": "instance_ip"  }$ nova list+--------------------------------------+---------------------------+--------+------------+-------------+---------------------------------+| ID                                   | Name                      | Status | Task State | Power State | Networks                        |+--------------------------------------+---------------------------+--------+------------+-------------+---------------------------------+| 0fc2af0c-ae79-4d22-8f36-9e860c257da5 | stack-server-3nzfyfofu6d4 | ACTIVE | -          | Running     | public=10.4.31.106              |+--------------------------------------+---------------------------+--------+------------+-------------+---------------------------------+
  • 删除栈。
    $ heat stack-delete stack) M- C- T( S5 q5 d3 S6 {

7 N/ k* U1 y( H4 |3 X* _" I

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2017-11-20 16:30:03 | 显示全部楼层
环境文件就是一个特殊类型的模板,它为 Heat 模板提供了自定义的功能。这个文件包括两个主要的部分:! u0 ]+ E" ?5 Y0 K
参数 - 应用到一个模板参数的常规设置。它们在环境文件的 parameters 项中设置。2 [+ D8 X* R8 F$ S+ `# l
参数默认值 - 这些参数被用来修改模板中的参数的默认值。它们在环境文件的 parameter_defaults 项中设置。8 N* U+ Q% l# I: ~: d8 t2 I' E  m
资源注册表 - 它设置了自定义资源名,并连接到其它 Heat 模板。这提供了一个创建没有存在于核心资源集合中的自定义资源的方法。它在环境文件的 resource_registry 项中设置。
- F2 b$ X4 J0 a3 ~" E7 y; x以下是一个基本环境文件的实例:/ i' Y) P3 j, X/ l- Z! z  X
resource_registry:* `9 d1 L4 C- q! @
  OS::Nova::Server::MyServer: myserver.yaml& I# L# O5 L/ X! ?
( v+ \( B& b$ |& |4 F
parameter_defaults:* A# ~0 ^3 ?6 a0 m9 P
  NetworkName: my_network& b3 U0 o9 q! D/ l

/ z4 H( O8 Q$ E8 lparameters:
, F0 Q/ V# r3 n  t( g. B  MyIP: 192.168.0.1% w+ K% T; C; ~6 n, a2 ~4 A

- j2 d1 d9 W) {; t  t- T( W这会创建一个新的、名为 OS::Nova::Server::MyServer 的资源类型。myserver.yaml 是一个 Heat 模板文件,它被用来创建这个资源类型来覆盖内建的资源类型。
# S* u  L/ K- X& Z+ V% B8 T' g

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2017-11-20 16:30:45 | 显示全部楼层
Heat 模板% b/ y6 ^, i+ X. w3 F$ F/ r+ b" ]: r
9 c( @  l8 k2 b2 z( _( v
director 使用 Heat Orchestration Templates(HOT)作为模板格式来组成 Overcloud 的部署计划。HOT 格式的模板通常使用 YAML 格式。一个模板的目的是创建一个堆栈(stack),堆栈中包括了一组资源集合,Heat 会创建并配置每个资源。资源就是 OpenStack 中的对象(object),它包括计算资源、网络配置、安全组、扩展规则和自定义资源。+ @& t% B1 Z+ T2 W
一个 Heat 模板有以下 3 个主要项:
2 c& H4 I: e5 N" M2 U+ D( M; t参数 - 一组传递给 Heat 的参数,可以被用来自定义一个堆栈,并设置在没有传递值时相关参数所使用的默认值。这些参数在模板的 parameters 项中定义。
6 T9 B- t  ]. a: B3 g资源 - 一组作为堆栈的一部分需要创建和配置的对象。OpenStack 包括一组分布在所有组件中的资源,它们在模板的 resources 项中定义。: b" P$ _1 z* l, t
输出 - 一组在堆栈创建后传递给 Heat 的值。您可以通过 Heat API 或客户端工具程序来访问这些值。它们在模板的 output 项中定义。' _) d+ D! [; ~. A
以下是一个基本 Heat 模板的示例:3 E  o6 \5 s+ e/ ~
  t& `) O' Y4 n( c! S; [
heat_template_version: 2013-05-23
: @/ j0 {2 o4 }7 B7 J
3 O. D, }" \6 R$ v- tdescription: > A very basic Heat template.
( _0 x' k7 Y: t( X6 o+ Z; R1 [
! M, Q6 D- K) `, [5 ^7 }+ Z  n6 u; lparameters:: C0 A/ L; M1 _9 I
  key_name:
9 e/ m& e" {( V9 X) P# Y( R    type: string
+ x5 M- E0 i. ]% g8 m" a    default: lars- V& y7 a) c; T" Q: ?  L
    description: Name of an existing key pair to use for the instance/ T1 t/ g' U8 S5 t, {) Y3 s
  flavor:
# g" s& s2 N9 I+ d# ~    type: string# ^# g# J; L/ a# {
    description: Instance type for the instance to be created
& g9 e% D: `0 M( R' ]( T    default: m1.small% @( h: y# k+ R- V& [
  image:
$ O5 C# X- X5 ?4 ~$ r    type: string
8 d" H& T0 G0 e' w6 j    default: cirros. k2 O  `( F- R
    description: ID or name of the image to use for the instance
8 }0 o( K* Q  M" a0 g) i
3 P5 Q, q% q3 W$ N# q5 Jresources:
* o% M5 ~! s$ s! `; J3 }  my_instance:, S1 V1 X4 t, p1 D! g+ x
    type: OS::Nova::Server$ W/ D" ^" r" Q
    properties:
' L+ U  z; o2 z6 W4 @      name: My Cirros Instance
% M: W5 @& n9 ^0 k2 n; M      image: { get_param: image }
; f6 b& n- P: ?2 E" q; `$ B      flavor: { get_param: flavor }
) I+ g3 n: Y; [% l      key_name: { get_param: key_name }: T* x( s2 Y( s
% m  l4 G/ q! G! @9 i) U- {
output:
& x" g' B( Q- r  ]& E" U6 q+ F) U  instance_name:
6 x3 G9 U& z" r6 ]" V4 B    description: Get the instance's name
, a6 g# n* H) k# n$ B: k    value: { get_attr: [ my_instance, name ] }
( ^+ [1 g. E& B( B8 Z" @. i: n) Z, g% _/ N8 B% I
这个模板使用资源类型 type: OS::Nova::Server 创建一个名为 my_instance 的实例,它具有特定的 flavor、镜像和关键字。这个堆栈会返回 instance_name 的值(My Cirros Instance)。

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2017-11-20 16:47:30 | 显示全部楼层
示例 1. K2 \  z! x( j  r
以下示例是一个用于部署单个虚拟系统的简单 Heat 模板,该示例限制为此模板中硬编码的映像、密钥和虚拟硬件样板值的单一组合:8 N8 f0 I) z% o) x7 {' l4 X5 j. @
heat_template_version: 2013-05-23- b; R, Z5 l( R* C' f, v7 x: g
5 J. X; g4 N! ^! N0 D* b2 }' L& ]
description: Simple template to deploy a single compute instance with hardcoded values; C0 q, m4 V+ j9 J, X; B. ?
, D& B6 l1 z# z8 v1 V2 r
resources:( O, C; B- x. w# \7 Z1 J
  my_instance:
: q7 o# V; }. [! z8 b+ N' t    type: OS::Nova::Server- V) P4 Z  i0 \) j5 |* K, a5 U
    properties:
: n! k! P( u$ V( k4 i      key_name: my_key_pair_1; z" [& C+ O: R) O# t1 s& {" I- L
      image: cirros-0.3.1-x86_64
1 d( U9 f- _3 F7 @* C* l      flavor: m1.tiny
$ \8 ?0 R6 B& f8 TCopy) X) b) }; N5 b' q
示例 2( o$ d3 z3 e+ ~9 w% P
以下示例是一个 Heat 模板,它使用参数来部署单个虚拟系统,因此可以复用于其他配置:
! {/ L0 y5 F4 L# }4 Uheat_template_version: 2013-05-23: z6 \6 k% Z2 C: ?
description: Simple template to deploy a single compute instance with parameters8 D) q* B* H* n

: Y5 P. r0 B- E9 c+ E. ?parameters:. h4 B7 C$ D2 X/ b7 c
  key_name:4 M) Q4 t/ w0 N0 j; J8 S
    type: string8 }9 U8 e8 c& v6 Y
    label: Key Name3 R4 R9 E6 t& ^- s% L
    description: Name of key-pair to be used for compute instance
7 W3 O. D, v- [3 R7 R  q  image_id:! Z& W+ ~, z' c3 J
    type: string
8 G) [8 f& _3 U/ \    label: Image ID
- m# h0 X( O& ?3 x$ w    description: Image to be used for compute instance( b- y, K- v* G* r8 \9 C
  instance_type:1 _; k6 W; ^# s/ \+ b$ s
    type: string
' Q' x& B; ]9 X    label: Instance Type1 A+ W6 B" o7 ^, |
    description: Type of instance (flavor) to be used
7 o/ W8 h+ j6 b6 m5 Tresources:
' w. H0 ]9 p: p! `' E5 C6 U2 ~( u. s  my_instance:/ R, |8 w* r$ e) j4 p) v7 J5 t
    type: OS::Nova::Server" `' j9 [1 ~- Y; q% E0 s$ b
    properties:5 c; l; w# }7 \' M, h
      key_name: { get_param: key_name }
% P! M: o0 @7 X( n1 k) [* b      image: { get_param: image_id }
  {+ W% @" Q# R      flavor: { get_param: instance_type }
  t' |, K6 L6 V1 c6 Z! k. M; QCopy9 z- |6 E! E& F) @& x
示例 3
8 C# }2 ]: a0 X" b7 O以下示例是一个简单的 Heat 模板,它通过使用参数的查找注释来部署具有两个虚拟机实例的堆栈:7 M5 E* f% R: a' w% r
heat_template_version: 2013-05-236 g9 T* H, G4 J. X6 q) B

6 u9 [" d2 v( z8 Tdescription: Simple template to deploy a stack with two virtual machine instances8 m# `6 W) ?2 t$ o! w( c  U  |$ }

; i1 `$ M6 x/ V# J" r3 Rparameters:0 ?4 {3 |/ d7 w, }) L
  image_name_1:
' e" K9 T& e% j- n; V0 L9 Y    type: string
/ M# y3 f4 ]6 F6 t3 e- u    label: Image Name # [& d2 k" N5 D/ A1 \' t
    description: SCOIMAGE Specify an image name for instance1
7 N3 f  j! @! J8 W. u5 I$ G    default: cirros-0.3.1-x86_64# Q4 d; W/ ~7 ~
  image_name_2:
  D" g* y4 e% ~: S% H    type: string % Y+ @+ F; `( J& h5 _' q
    label: Image Name
0 m% @% P, I9 E    description: SCOIMAGE Specify an image name for instance2
! V5 n5 r! f( T    default: cirros-0.3.1-x86_64
* z$ [$ o$ P$ n/ V1 B: {, v  network_id:& y0 z  C$ l+ e
    type: string% Z/ k; Q3 z# M7 b5 {. T3 y
    label: Network ID- c4 J$ s$ U/ H; I6 M
    description: SCONETWORK Network to be used for the compute instance, F! L: i+ F1 \/ l0 P; e
, B: n: F. {, z7 @
resources: : l5 f- ^; n4 }% @2 {- o
  my_instance1:
4 ~+ Z* A5 z8 J9 }" q) C    type: OS::Nova::Server
# u' Y/ Y/ e& t$ y; X    properties:
. {. N0 ~, C. r1 E      image: { get_param: image_name_1 } : R3 o- F8 _% ]: m
      flavor: m1.small
% C2 P4 X  N, Z6 U      networks:& {0 S) `% [) L$ ]& W9 D, u- z1 p% z
        - network : { get_param : network_id }7 L0 P( O: t1 l- ?( t9 k
  my_instance2: 9 g% r$ y4 T5 I8 @6 o
    type: OS::Nova::Server
6 _% |& P/ |; Y: c) ]0 {5 N    properties:
! x/ C) Z; F/ w/ _) d      image: { get_param: image_name_2 }
' I4 {5 V1 _8 U! Q/ m0 q+ i0 Z2 S      flavor: m1.tiny* M7 Q5 g6 C3 Y
      networks:
: I) J9 S* B0 f( k% n0 i$ m        - network : { get_param : network_id }
7 h& b3 J0 @" a/ l; `8 M! h  LCopy4 g$ f0 S( m, \: B2 z+ b
示例 4
6 b2 [! a+ c9 x) Z, [0 J7 d) [以下示例是一个简单的 Heat 模板,此模板通过使用 user_data 节来针对虚拟机设置 admin 密码:
9 X- X5 K. `# gheat_template_version: 2013-05-230 [/ j9 Q) V5 O& |. Z8 _: ]* n$ u

1 A1 I. Y8 r' pdescription: Simple template to set the admin password for a virtual machine5 Y  B+ T' Z' Y# S
, z+ e7 l* x( t
parameters:
  Z4 g2 H3 R+ x  key_name:
! A& {' t1 u/ H% r( \9 E6 X    type: string
) T/ V( M% ?0 Y" m    label: Key Name8 Q' f% G2 U8 [- M. ]) b+ p: n
    description: SCOKEY Name of the key pair to be used for the compute instance9 R4 ?' D& N% Q$ j4 q1 y
  image_name:  }. {' X; e0 H+ m2 U
    type: string
. o2 [- L+ z* w5 {0 {: |" D$ Z$ Q    label: Image Name+ ~+ G5 D" ~& l, V
    description: SCOIMAGE Name of the image to be used for the compute instance4 D2 A/ O. f- }/ u- S
  password:: y5 w( U6 B' ~
    type: string
, x- N3 T0 {+ t+ y% {) @    label: password* A5 m& a+ V1 X$ ~2 V
    description: admin password) L( x4 I& b2 @6 d; m( u
    hidden: true
" A* J2 ^/ n% {! h( }* N; L- x' y8 K5 U% E0 b' I* A9 Z
* O6 F, h% q! z, @8 T
resources:
4 t5 o# Y( S3 f# M- r$ Y8 f  my_instance:
2 L* O2 m3 A$ [6 r& q1 Q* O    type: OS::Nova::Server- _9 M5 n: E. H) G6 ^& L
    properties:
! j8 k( U" `) H# n      key_name: { get_param: key_name }
( q% Z8 J% S% e8 V; n5 n7 q9 L      admin_user: sampleuser
- m7 k" |9 m. b' V9 S7 Q      image: { get_param: image_name }
4 R8 j8 r- O( k! ?. C1 h5 V      flavor: m1.small
/ F  k% D5 I: R/ F. S& ?5 Y, p      user_data:
1 q" E8 z$ g- h( E( P, `        str_replace:7 t$ F! {, s7 q- k# o/ g
          template: |
, @( b6 ?( _, L' a0 C6 Y            #!/bin/bash
. \. V, o5 R, M  g; G            echo "Setting  password to  " $password           
3 `. _) d$ y2 u5 T' G            echo $password |passwd --stdin sampleuser
9 N, d" V7 P; ^5 I# |! p" y2 F% z0 {3 F8 f4 w2 F+ }
          params:$ P5 `, H, m# }6 w* b
            $password: { get_param: password }( F& V6 l% @# ]) `" W: n& V  Z6 ?
Copy& T$ v# s, p4 P- V* ?* L
示例 5+ J: c7 G7 t4 l9 m, ]
以下示例是一个简单的 Heat 模板,此模板用于在您指定了要使用的存储连接组以及引导卷部署所在的存储模板的 PowerVC 上,部署 AIX 或 Linux on Power 服务器:
8 S; p5 u3 v' Y; G$ S- {' Yheat_template_version: 2013-05-23 / c9 {# q% A, a
description: Template to Deploy on NPIV v7k storage only
- N9 d$ x  U/ F+ B& m$ Y  y1 d: J# d, h% s: s
parameters:. P$ l: M) Z7 Z2 V1 C
  network_id1:3 S, d) M$ I! S1 L0 x! Z: z
    type: string
; ]+ q. q$ Z+ w6 Q& w    description: SCONETWORK ID of the (nova) network a server should be deployed to.
+ [5 m' L" m/ f8 }2 G" x  flavor_id:
0 N  K: y5 U3 @6 d    type: string8 x9 S: b4 u; J) a, R- A5 d
    description: SCOFLAVOR The flavor to be applied to the server DatabaseTierVM.
* P" B% j# E7 G; ?2 [/ M  image:
) w% |6 s( ?. a6 U6 q# s- j* O7 `    type: string" }6 \) M8 ^4 J+ V9 ~/ f
    label: Image
# N2 Z& w0 n5 o/ y% Y* q5 C+ O' S    description: SCOIMAGE The Image to be deployed3 G3 g0 c+ R1 a- e  J; K2 V/ s7 X
resources:, a8 B$ i5 b6 ~4 a8 A- o+ s
  heat:
( O: k. t4 _7 v    type: OS::Nova::Server
3 H( Y( E  O1 `1 U* e    properties:# B, |' j% G+ ?% v9 Z
      image: { get_param: image }  |; M+ Z. |: T$ H: j
      flavor: { get_param: flavor_id }
" Y3 r' q  q9 n4 ^1 u      availability_zone: D0EB* ^; @, a5 ]5 X) O3 ?8 }4 W
      metadata: { selected-scg: d91acbbe-3d81-4279-b389-54b3ad4a1c8c, selected-storage-template: 0431b2f3-fea6-4aa5-b3fb-d0e82ccf5ebb }- O6 I- p6 F8 B; l1 H7 _1 t3 N
      networks:
  T; B) P1 z0 Y2 q) Y5 X* x         - network : { get_param : network_id1 }
" d9 d- s2 h) _! U! Y  ]/ C/ zCopy+ I; `" u9 d! ]/ E" v' {) ?
注:
1 P: T! E6 X! @  A. s您可以使用 OpenStack Dashboard 中的“主机聚集”面板为 PowerVM® 服务器创建可用性专区。 请先确保您创建的新可用性专区添加到相关域和项目,然后再尝试使用这些可用性专区。 您可以在要使用的映像的 Image_topology 中找到 selected-scg(存储连接组)和 selected-storage-template。 请在 OpenStack Controller 上运行 glance image-show <image id> 命令。 映像拓扑指定该特定映像所支持的存储连接组和存储模板。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

返回首页|Archiver|手机版|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )

GMT+8, 2026-6-12 01:04 , Processed in 0.021497 second(s), 22 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表