puppet-nova/manifests/generic_service.pp
Takashi Kajinami 7688084aed Add strict validation about boolean parameters
This ensures the parameters used by if-else logic accept only boolean
values because non-boolean can result in unexpected behavior.

Change-Id: I3a27d94e453f9cfbea701337308a7086693c89bb
2023-03-18 16:14:03 +09:00

79 lines
1.9 KiB
Puppet

# == Define: nova::generic_service
#
# This defined type implements basic nova services.
# It is introduced to attempt to consolidate
# common code.
#
# It also allows users to specify ad-hoc services
# as needed
#
# This define creates a service resource with title nova-${name} and
# conditionally creates a package resource with title nova-${name}
#
# === Parameters:
#
# [*package_name*]
# (mandatory) The package name (for the generic_service)
#
# [*service_name*]
# (mandatory) The service name (for the generic_service)
#
# [*enabled*]
# (optional) Define if the service must be enabled or not
# Defaults to false.
#
# [*manage_service*]
# (optional) Manage or not the service (if a service_name is provided).
# Defaults to true.
#
# [*ensure_package*]
# (optional) Control the ensure parameter for the package resource.
# Defaults to 'present'.
#
define nova::generic_service(
$package_name,
$service_name,
$enabled = true,
$manage_service = true,
$ensure_package = 'present'
) {
include nova::deps
include nova::params
validate_legacy(Boolean, 'validate_bool', $enabled)
validate_legacy(Boolean, 'validate_bool', $manage_service)
$nova_title = "nova-${name}"
# I need to mark that ths package should be
# installed before nova_config
if ($package_name) {
if !defined(Package[$nova_title]) and !defined(Package[$package_name]) {
package { $nova_title:
ensure => $ensure_package,
name => $package_name,
tag => ['openstack', 'nova-package'],
}
}
}
if $service_name {
if $manage_service {
if $enabled {
$service_ensure = 'running'
} else {
$service_ensure = 'stopped'
}
service { $nova_title:
ensure => $service_ensure,
name => $service_name,
enable => $enabled,
hasstatus => true,
tag => 'nova-service',
}
}
}
}