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: 
1

    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: 
2

        motd::content: {get_param: MotdMessage}
      step_config: | 
3

        if hiera('step') >= 2 {
          include ::motd
        }
Copy to Clipboard Toggle word wrap
1
该模板包含一个 MotdMessage 参数,用于定义当日消息。参数包含默认消息,但您可以使用自定义环境文件中的相同参数来覆盖该消息。
2
outputs 部分定义 config_settings 中的一些服务 hieradata。motd::content hieradata 存储 MotdMessage 参数中的内容。motd Puppet 类最终读取此 hieradata,并将用户定义的消息传递给 /etc/motd 文件。
3
outputs 部分包含 step_config 中的 Puppet 清单片断。该片段检查配置是否已达到第 2 步,如果是如此,则运行 motd Puppet 类。
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat