4.3. 为 Puppet 模块添加配置


OpenStack 模块主要用于配置核心服务。大多数还包含额外的清单来配置其他服务,有时也称为 后端、代理或 插件例如,cinder 模块包含一个名为 后端 的目录,其中包含不同存储设备的配置选项,包括 NFS、iSCSI、Red Hat Ceph Storage 等。

例如,manifests/backends/nfs.pp 文件包含以下配置

define cinder::backend::nfs (
  $volume_backend_name  = $name,
  $nfs_servers          = [],
  $nfs_mount_options    = undef,
  $nfs_disk_util        = undef,
  $nfs_sparsed_volumes  = undef,
  $nfs_mount_point_base = undef,
  $nfs_shares_config    = '/etc/cinder/shares.conf',
  $nfs_used_ratio       = '0.95',
  $nfs_oversub_ratio    = '1.0',
  $extra_options        = {},
) {

  file {$nfs_shares_config:
    content => join($nfs_servers, "\n"),
    require => Package['cinder'],
    notify  => Service['cinder-volume']
  }

  cinder_config {
    "${name}/volume_backend_name":  value => $volume_backend_name;
    "${name}/volume_driver":        value =>
      'cinder.volume.drivers.nfs.NfsDriver';
    "${name}/nfs_shares_config":    value => $nfs_shares_config;
    "${name}/nfs_mount_options":    value => $nfs_mount_options;
    "${name}/nfs_disk_util":        value => $nfs_disk_util;
    "${name}/nfs_sparsed_volumes":  value => $nfs_sparsed_volumes;
    "${name}/nfs_mount_point_base": value => $nfs_mount_point_base;
    "${name}/nfs_used_ratio":       value => $nfs_used_ratio;
    "${name}/nfs_oversub_ratio":    value => $nfs_oversub_ratio;
  }

  create_resources('cinder_config', $extra_options)

}
Copy to Clipboard Toggle word wrap

这可实现以下几项:

  • define 语句创建名为 cinder::backend::nfs 的定义的类型。定义的类型与类类似;主要的区别是 Puppet 多次评估定义的类型。例如,您可能需要多个 NFS 后端,因此每个 NFS 共享需要多个评估。
  • 接下来的几行定义了此配置中的参数及其默认值。如果用户将新值传递给 cinder::backend::nfs 定义的类型,则默认值会被覆盖。
  • file 函数是一个资源声明,调用用于创建文件。此文件包含在参数中定义 NFS 共享和名称的列表($nfs_shares_config = '/etc/cinder/shares.conf')。请注意附加属性:
  • content 属性使用 $nfs_servers 参数创建一个列表。
  • require 属性确保安装了 cinder 软件包。
  • notify 属性告知 cinder-volume 服务重置。
  • cinder_config 函数是一个资源声明,它使用模块中的 lib/puppet/ 目录中的插件。此插件将配置添加到 /etc/cinder/cinder.conf 文件中。此资源的每一行都向 cinder.conf 文件中的相关部分添加配置选项。例如,如果 $name 参数是 mynfs,则以下属性:

      "${name}/volume_backend_name":  value => $volume_backend_name;
      "${name}/volume_driver":        value =>
        'cinder.volume.drivers.nfs.NfsDriver';
      "${name}/nfs_shares_config":    value => $nfs_shares_config;
    Copy to Clipboard Toggle word wrap

    将以下内容保存到 cinder.conf 文件中:

    [mynfs]
    volume_backend_name=mynfs
    volume_driver=cinder.volume.drivers.nfs.NfsDriver
    nfs_shares_config=/etc/cinder/shares.conf
    Copy to Clipboard Toggle word wrap
  • create_resources 函数将哈希转换为一组资源。在这种情况下,清单会将 $extra_options 哈希转换为后端的一组附加配置选项。这提供了一种灵活的方法来添加未包含在清单核心参数中的更多配置选项。

这显示了包括清单来配置硬件 OpenStack 驱动程序的重要性。清单提供了一种简单的方法,供 director 包含与您的硬件相关的配置选项。这充当 director 的主要集成点,将 Overcloud 配置为使用您的硬件。

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2026 Red Hat