4.3. Puppet 模块配置示例


OpenStack 模块主要旨在配置核心服务。大多数模块还包含额外的清单来配置其他服务,有时也称为 后端、代理或 插件例如,cinder 模块包含一个名为 backends 的目录,它包含用于不同存储设备的配置选项,包括 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)

}

结果:

  • 定义 语句创建一个名为 cinder::backend::nfs 的定义的类型。一个定义的类型与类类似,主要区别是 Puppet 多次评估定义的类型。例如,您可能需要多个 NFS 后端,因此配置为每个 NFS 共享需要多个评估。
  • 接下来几行在这一配置中定义参数及其默认值。如果用户将新值传递给定义的 cinder::backend::nfs,则默认值会被覆盖。
  • 文件 函数是调用创建文件的资源声明。此文件包含 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;

    将以下代码片段保存到 cinder.conf 文件中:

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

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

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

© 2024 Red Hat, Inc.