6.2. 创建用户定义的可组合服务
本示例将探讨如何创建用户定义的可组合服务并专注于实施当日消息(motd)服务。在本例中,overcloud 镜像包含一个自定义 motd Puppet 模块,通过配置 hook 加载或修改 overcloud 镜像。更多信息请参阅 第 3 章 使用 overcloud 镜像。
在创建自己的服务时,您必须在服务的 heat 模板中定义以下项目:
- parameters
以下是您必须在服务模板中包含的 compulsory 参数:
-
ServiceNetMap- 服务映射到网络.使用空 hash ({})作为默认值,因为此参数使用父 Heat 模板中的值覆盖。 -
DefaultPasswords- 默认密码列表。使用空 hash ({})作为默认值,因为此参数使用父 Heat 模板中的值覆盖。 -
EndpointMap- OpenStack 服务端点的列表,供协议使用。使用空 hash ({})作为默认值,因为此参数使用父 Heat 模板中的值覆盖。
定义服务所需的任何其他参数。
-
- 输出
- 以下输出参数定义主机上的服务配置。更多信息请参阅 附录 A, 可组合的服务参数。
以下是 motd 服务的示例 heat 模板(service.yaml):
heat_template_version: 2016-04-08
description: >
Message of the day service configured with Puppet
parameters:
ServiceNetMap:
default: {}
type: json
DefaultPasswords:
default: {}
type: json
EndpointMap:
default: {}
type: json
MotdMessage:
default: |
Welcome to my Red Hat OpenStack Platform environment!
type: string
description: The message to include in the motd
outputs:
role_data:
description: Motd role using composable services.
value:
service_name: motd
config_settings:
motd::content: {get_param: MotdMessage}
step_config: |
if hiera('step') >= 2 {
include ::motd
}
- 1
- 该模板包含一个
MotdMessage参数,用于定义当日消息。参数包含默认消息,但您可以使用自定义环境文件中的相同参数来覆盖该消息。 - 2
outputs部分定义config_settings中的一些服务 hieradata。motd::contenthieradata 存储MotdMessage参数中的内容。motdPuppet 类最终读取此 hieradata,并将用户定义的消息传递给/etc/motd文件。- 3
outputs部分包含step_config中的 Puppet 清单片断。该片段检查配置是否已达到第 2 步,如果是如此,则运行motdPuppet 类。