Refactoring of the override_resources type for the IaC feature
This commit changes override_resources type allowing to - specify any puppet resource - pass any number of resources It also introduces the logic to decide whether override_resources should create a new resource, if it hasn't been found in the catalog. The resource overrides as well as additional settings are taken from Hiera. This logic essentially allows to create any Puppet resource via passing the right hash to the Hiera. It replaces/extends the old 'Advanced configuration' feature. Change-Id: I81099ac41c3e2abdaf6fde3a19161709b7ba4b8c Blueprint: puppet-resource-override
This commit is contained in:
parent
526b25ae5e
commit
cfca05c588
|
@ -1,2 +1,3 @@
|
|||
class { '::openstack_tasks::ceilometer::compute' :}
|
||||
class { '::osnailyfacter::upgrade::restart_services' :}
|
||||
class { '::osnailyfacter::override_resources': }
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
class { '::openstack_tasks::ceilometer::controller' :}
|
||||
class { '::osnailyfacter::upgrade::restart_services' :}
|
||||
class { '::osnailyfacter::override_resources': }
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
class { '::openstack_tasks::glance::glance' :}
|
||||
class { '::osnailyfacter::upgrade::restart_services' :}
|
||||
class { '::osnailyfacter::override_resources': }
|
||||
|
|
|
@ -4,3 +4,4 @@ class mysql::server {}
|
|||
class mysql::config {}
|
||||
include mysql::server
|
||||
include mysql::config
|
||||
class { '::osnailyfacter::override_resources': }
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
class { '::openstack_tasks::keystone::keystone' :}
|
||||
class { '::osnailyfacter::upgrade::restart_services' :}
|
||||
class { '::osnailyfacter::override_resources': }
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
class { '::openstack_tasks::openstack_cinder::openstack_cinder' :}
|
||||
class { '::osnailyfacter::upgrade::restart_services' :}
|
||||
class { '::osnailyfacter::override_resources': }
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
class { '::openstack_tasks::openstack_controller::openstack_controller' :}
|
||||
class { '::osnailyfacter::upgrade::restart_services' :}
|
||||
class { '::osnailyfacter::override_resources': }
|
||||
|
|
|
@ -2,3 +2,4 @@ class neutron {}
|
|||
class { 'neutron' :}
|
||||
class { '::openstack_tasks::openstack_network::agents::dhcp' :}
|
||||
class { '::osnailyfacter::upgrade::restart_services' :}
|
||||
class { '::osnailyfacter::override_resources': }
|
||||
|
|
|
@ -2,3 +2,4 @@ class neutron {}
|
|||
class { 'neutron' :}
|
||||
class { '::openstack_tasks::openstack_network::agents::l3' :}
|
||||
class { '::osnailyfacter::upgrade::restart_services' :}
|
||||
class { '::osnailyfacter::override_resources': }
|
||||
|
|
|
@ -2,3 +2,4 @@ class neutron {}
|
|||
class { 'neutron' :}
|
||||
class { '::openstack_tasks::openstack_network::agents::metadata' :}
|
||||
class { '::osnailyfacter::upgrade::restart_services' :}
|
||||
class { '::osnailyfacter::override_resources': }
|
||||
|
|
|
@ -2,3 +2,4 @@ class neutron {}
|
|||
class { 'neutron' :}
|
||||
class { '::openstack_tasks::openstack_network::agents::sriov' :}
|
||||
class { '::osnailyfacter::upgrade::restart_services' :}
|
||||
class { '::osnailyfacter::override_resources': }
|
||||
|
|
|
@ -2,3 +2,4 @@ class neutron {}
|
|||
class { 'neutron' :}
|
||||
|
||||
class { '::openstack_tasks::openstack_network::plugins::ml2' :}
|
||||
class { '::osnailyfacter::override_resources': }
|
||||
|
|
|
@ -2,3 +2,4 @@ class neutron { }
|
|||
class { 'neutron' : }
|
||||
|
||||
class { '::openstack_tasks::openstack_network::server_config' :}
|
||||
class { '::osnailyfacter::override_resources': }
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
class { '::openstack_tasks::roles::compute' :}
|
||||
class { '::osnailyfacter::upgrade::restart_services' :}
|
||||
class { '::osnailyfacter::override_resources': }
|
||||
|
|
|
@ -42,27 +42,6 @@ class openstack_tasks::ceilometer::compute {
|
|||
$rabbit_heartbeat_timeout_threshold = pick($ceilometer_hash['rabbit_heartbeat_timeout_threshold'], $rabbit_hash['heartbeat_timeout_threshold'], 60)
|
||||
$rabbit_heartbeat_rate = pick($ceilometer_hash['rabbit_heartbeat_rate'], $rabbit_hash['rabbit_heartbeat_rate'], 2)
|
||||
|
||||
$override_configuration = hiera_hash('configuration', {})
|
||||
|
||||
$override_values = values($override_configuration)
|
||||
if !empty($override_values) and has_key($override_values[0], 'data') {
|
||||
# Create resources of type 'override_resources'. These, in turn,
|
||||
# will either update existing resources in the catalog with new data,
|
||||
# or create these resources, if they do not actually exist.
|
||||
create_resources(override_resources, $override_configuration)
|
||||
} else {
|
||||
# override ceilometer.conf options
|
||||
override_resources { 'ceilometer_config':
|
||||
data => $override_configuration['ceilometer']
|
||||
}
|
||||
# override ceilometer api paste options
|
||||
override_resources { 'ceilometer_api_paste_ini':
|
||||
data => $override_configuration['ceilometer_api_paste_ini']
|
||||
}
|
||||
|
||||
Override_resources <||> ~> Service <| tag == 'ceilometer-service' |>
|
||||
}
|
||||
|
||||
if ($ceilometer_enabled) {
|
||||
|
||||
class { '::ceilometer':
|
||||
|
|
|
@ -64,28 +64,6 @@ class openstack_tasks::ceilometer::controller {
|
|||
$rabbit_heartbeat_timeout_threshold = pick($ceilometer_hash['rabbit_heartbeat_timeout_threshold'], $rabbit_hash['heartbeat_timeout_threshold'], 60)
|
||||
$rabbit_heartbeat_rate = pick($ceilometer_hash['rabbit_heartbeat_rate'], $rabbit_hash['rabbit_heartbeat_rate'], 2)
|
||||
|
||||
$override_configuration = hiera_hash('configuration', {})
|
||||
|
||||
$override_values = values($override_configuration)
|
||||
if !empty($override_values) and has_key($override_values[0], 'data') {
|
||||
# Create resources of type 'override_resources'. These, in turn,
|
||||
# will either update existing resources in the catalog with new data,
|
||||
# or create these resources, if they do not actually exist.
|
||||
create_resources(override_resources, $override_configuration)
|
||||
} else {
|
||||
# override ceilometer.conf options
|
||||
override_resources { 'ceilometer_config':
|
||||
data => $override_configuration['ceilometer']
|
||||
}
|
||||
# override ceilometer api paste options
|
||||
override_resources { 'ceilometer_api_paste_ini':
|
||||
data => $override_configuration['ceilometer_api_paste_ini']
|
||||
}
|
||||
|
||||
Override_resources <||> ~> Service <| tag == 'ceilometer-service' |>
|
||||
}
|
||||
|
||||
|
||||
if $mongo_hash['enabled'] and $ceilometer_hash['enabled'] {
|
||||
$external_mongo_hash = hiera_hash('external_mongo')
|
||||
$db_user = $external_mongo_hash['mongo_user']
|
||||
|
|
|
@ -32,38 +32,6 @@ class openstack_tasks::glance::glance {
|
|||
$rabbit_heartbeat_timeout_threshold = pick($glance_hash['rabbit_heartbeat_timeout_threshold'], $rabbit_hash['heartbeat_timeout_threshold'], 60)
|
||||
$rabbit_heartbeat_rate = pick($glance_hash['rabbit_heartbeat_rate'], $rabbit_hash['rabbit_heartbeat_rate'], 2)
|
||||
|
||||
$override_configuration = hiera_hash('configuration', {})
|
||||
|
||||
$override_values = values($override_configuration)
|
||||
if !empty($override_values) and has_key($override_values[0], 'data') {
|
||||
# Create resources of type 'override_resources'. These, in turn,
|
||||
# will either update existing resources in the catalog with new data,
|
||||
# or create these resources, if they do not actually exist.
|
||||
create_resources(override_resources, $override_configuration)
|
||||
} else {
|
||||
# override glance api options
|
||||
override_resources { 'glance_api_config':
|
||||
data => $override_configuration['glance_api']
|
||||
}
|
||||
# override glance registry options
|
||||
override_resources { 'glance_registry_config':
|
||||
data => $override_configuration['glance_registry']
|
||||
}
|
||||
|
||||
# override glance cache options
|
||||
override_resources { 'glance_cache_config':
|
||||
data => $override_configuration['glance_cache']
|
||||
}
|
||||
|
||||
# override glare config options
|
||||
override_resources { 'glance_glare_config':
|
||||
data => $override_configuration['glare_config']
|
||||
}
|
||||
|
||||
Override_resources <||> ~> Service <| tag == 'glance-service' |>
|
||||
}
|
||||
|
||||
|
||||
$db_type = pick($glance_hash['db_type'], 'mysql+pymysql')
|
||||
$db_host = pick($glance_hash['db_host'], $database_vip)
|
||||
$db_user = pick($glance_hash['db_user'], 'glance')
|
||||
|
|
|
@ -56,24 +56,6 @@ class openstack_tasks::heat::heat {
|
|||
$rabbit_heartbeat_timeout_threshold = pick($heat_hash['rabbit_heartbeat_timeout_threshold'], $rabbit_hash['heartbeat_timeout_threshold'], 60)
|
||||
$rabbit_heartbeat_rate = pick($heat_hash['rabbit_heartbeat_rate'], $rabbit_hash['rabbit_heartbeat_rate'], 2)
|
||||
|
||||
$override_configuration = hiera_hash('configuration', {})
|
||||
|
||||
$override_values = values($override_configuration)
|
||||
if !empty($override_values) and has_key($override_values[0], 'data') {
|
||||
create_resources(override_resources, $override_configuration)
|
||||
} else {
|
||||
# override heat.conf options
|
||||
override_resources { 'heat_config':
|
||||
data => $override_configuration['heat']
|
||||
}
|
||||
# override heat api paste options
|
||||
override_resources { 'heat_api_paste_ini':
|
||||
data => $override_configuration['heat_api_paste_ini']
|
||||
}
|
||||
|
||||
Override_resources <||> ~> Service <| tag == 'heat-service' |>
|
||||
}
|
||||
|
||||
$storage_hash = hiera_hash('storage', {})
|
||||
|
||||
$db_type = pick($heat_hash['db_type'], 'mysql+pymysql')
|
||||
|
|
|
@ -2,17 +2,6 @@ class openstack_tasks::keystone::keystone {
|
|||
|
||||
notice('MODULAR: keystone/keystone.pp')
|
||||
|
||||
# Override confguration options
|
||||
$override_configuration = hiera_hash('configuration', {})
|
||||
$override_values = values($override_configuration)
|
||||
if !empty($override_values) and has_key($override_values[0], 'data') {
|
||||
create_resources(override_resources, $override_configuration)
|
||||
} else {
|
||||
override_resources { 'keystone_config':
|
||||
data => $override_configuration['keystone_config']
|
||||
} ~> Service['httpd']
|
||||
}
|
||||
|
||||
$network_scheme = hiera_hash('network_scheme', {})
|
||||
$network_metadata = hiera_hash('network_metadata', {})
|
||||
prepare_network_config($network_scheme)
|
||||
|
|
|
@ -49,29 +49,6 @@ class openstack_tasks::openstack_cinder::openstack_cinder {
|
|||
$rabbit_heartbeat_rate = pick($cinder_hash['rabbit_heartbeat_rate'], $rabbit_hash['rabbit_heartbeat_rate'], 2)
|
||||
|
||||
$queue_provider = hiera('queue_provider', 'rabbit')
|
||||
$override_configuration = hiera_hash('configuration', {})
|
||||
|
||||
$override_values = values($override_configuration)
|
||||
if !empty($override_values) and has_key($override_values[0], 'data') {
|
||||
# Create resources of type 'override_resources'. These, in turn,
|
||||
# will either update existing resources in the catalog with new data,
|
||||
# or create these resources, if they do not actually exist.
|
||||
create_resources(override_resources, $override_configuration)
|
||||
} else {
|
||||
# override cinder.conf options
|
||||
override_resources { 'cinder_config':
|
||||
data => $override_configuration['cinder']
|
||||
}
|
||||
|
||||
# override cinder api paste options
|
||||
override_resources { 'cinder_api_paste_ini':
|
||||
data => $override_configuration['cinder_api_paste_ini']
|
||||
}
|
||||
|
||||
Override_resources <||> ~> Service <| tag == 'cinder-service' |>
|
||||
}
|
||||
|
||||
|
||||
|
||||
$keystone_auth_protocol = get_ssl_property($ssl_hash, {}, 'keystone', 'internal', 'protocol', 'http')
|
||||
$keystone_auth_host = get_ssl_property($ssl_hash, {}, 'keystone', 'internal', 'hostname', [hiera('keystone_endpoint', ''), $service_endpoint, $management_vip])
|
||||
|
|
|
@ -5,26 +5,6 @@ class openstack_tasks::openstack_controller::openstack_controller {
|
|||
|
||||
notice('MODULAR: openstack_controller/openstack_controller.pp')
|
||||
|
||||
$override_configuration = hiera_hash('configuration', {})
|
||||
$override_values = values($override_configuration)
|
||||
if !empty($override_values) and has_key($override_values[0], 'data') {
|
||||
# Create resources of type 'override_resources'. These, in turn,
|
||||
# will either update existing resources in the catalog with new data,
|
||||
# or create these resources, if they do not actually exist.
|
||||
create_resources(override_resources, $override_configuration)
|
||||
} else {
|
||||
# override nova options
|
||||
override_resources { 'nova_config':
|
||||
data => $override_configuration['nova_config']
|
||||
}
|
||||
# override nova-api options
|
||||
override_resources { 'nova_paste_api_ini':
|
||||
data => $override_configuration['nova_paste_api_ini']
|
||||
}
|
||||
|
||||
Override_resources <||> ~> Service <| tag == 'nova-service' |>
|
||||
}
|
||||
|
||||
$network_scheme = hiera_hash('network_scheme', {})
|
||||
$network_metadata = hiera_hash('network_metadata', {})
|
||||
prepare_network_config($network_scheme)
|
||||
|
|
|
@ -2,20 +2,6 @@ class openstack_tasks::openstack_network::agents::dhcp {
|
|||
|
||||
notice('MODULAR: openstack_network/agents/dhcp.pp')
|
||||
|
||||
# override neutron options
|
||||
$override_configuration = hiera_hash('configuration', {})
|
||||
$override_values = values($override_configuration)
|
||||
if !empty($override_values) and has_key($override_values[0], 'data') {
|
||||
# Create resources of type 'override_resources'. These, in turn,
|
||||
# will either update existing resources in the catalog with new data,
|
||||
# or create these resources, if they do not actually exist.
|
||||
create_resources(override_resources, $override_configuration)
|
||||
} else {
|
||||
override_resources { 'neutron_dhcp_agent_config':
|
||||
data => $override_configuration['neutron_dhcp_agent_config']
|
||||
} ~> Service['neutron-dhcp-service']
|
||||
}
|
||||
|
||||
$debug = hiera('debug', true)
|
||||
$resync_interval = '30'
|
||||
$neutron_config = hiera_hash('neutron_config')
|
||||
|
|
|
@ -10,22 +10,6 @@ class openstack_tasks::openstack_network::agents::l3 {
|
|||
$controller = roles_include($neutron_controller_roles)
|
||||
$compute = roles_include($neutron_compute_roles)
|
||||
|
||||
if $controller or ($dvr and $compute) {
|
||||
# override neutron options
|
||||
$override_configuration = hiera_hash('configuration', {})
|
||||
$override_values = values($override_configuration)
|
||||
if !empty($override_values) and has_key($override_values[0], 'data') {
|
||||
# Create resources of type 'override_resources'. These, in turn,
|
||||
# will either update existing resources in the catalog with new data,
|
||||
# or create these resources, if they do not actually exist.
|
||||
create_resources(override_resources, $override_configuration)
|
||||
} else {
|
||||
override_resources { 'neutron_l3_agent_config':
|
||||
data => $override_configuration['neutron_l3_agent_config']
|
||||
} ~> Service['neutron-l3']
|
||||
}
|
||||
}
|
||||
|
||||
if $controller or ($dvr and $compute) {
|
||||
$debug = hiera('debug', true)
|
||||
$metadata_port = '8775'
|
||||
|
|
|
@ -19,22 +19,6 @@ class openstack_tasks::openstack_network::agents::metadata {
|
|||
min(max($::processorcount, 2), $workers_max))
|
||||
}
|
||||
|
||||
if $controller or ($dvr and $compute) {
|
||||
# override neutron options
|
||||
$override_configuration = hiera_hash('configuration', {})
|
||||
$override_values = values($override_configuration)
|
||||
if !empty($override_values) and has_key($override_values[0], 'data') {
|
||||
# Create resources of type 'override_resources'. These, in turn,
|
||||
# will either update existing resources in the catalog with new data,
|
||||
# or create these resources, if they do not actually exist.
|
||||
create_resources(override_resources, $override_configuration)
|
||||
} else {
|
||||
override_resources { 'neutron_metadata_agent_config':
|
||||
data => $override_configuration['neutron_metadata_agent_config']
|
||||
} ~> Service['neutron-metadata']
|
||||
}
|
||||
}
|
||||
|
||||
if $controller or ($dvr and $compute) {
|
||||
$debug = hiera('debug', true)
|
||||
$ha_agent = dig44($neutron_advanced_config, ['metadata_agent_ha'], true)
|
||||
|
|
|
@ -25,21 +25,6 @@ class openstack_tasks::openstack_network::agents::sriov {
|
|||
name => 'binutils',
|
||||
ensure => 'installed',
|
||||
}
|
||||
|
||||
# override neutron options
|
||||
$override_configuration = hiera_hash('configuration', {})
|
||||
$override_values = values($override_configuration)
|
||||
if !empty($override_values) and has_key($override_values[0], 'data') {
|
||||
# Create resources of type 'override_resources'. These, in turn,
|
||||
# will either update existing resources in the catalog with new data,
|
||||
# or create these resources, if they do not actually exist.
|
||||
create_resources(override_resources, $override_configuration)
|
||||
} else {
|
||||
override_resources { 'neutron_sriov_agent_config':
|
||||
data => $override_configuration['neutron_sriov_agent_config']
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,20 +2,6 @@ class openstack_tasks::openstack_network::plugins::ml2 {
|
|||
|
||||
notice('MODULAR: openstack_network/plugins/ml2.pp')
|
||||
|
||||
# override neutron options
|
||||
$override_configuration = hiera_hash('configuration', {})
|
||||
$override_values = values($override_configuration)
|
||||
if !empty($override_values) and has_key($override_values[0], 'data') {
|
||||
# Create resources of type 'override_resources'. These, in turn,
|
||||
# will either update existing resources in the catalog with new data,
|
||||
# or create these resources, if they do not actually exist.
|
||||
create_resources(override_resources, $override_configuration)
|
||||
} else {
|
||||
override_resources { 'neutron_agent_ovs':
|
||||
data => $override_configuration['neutron_agent_ovs']
|
||||
} ~> Service['neutron-ovs-agent-service']
|
||||
}
|
||||
|
||||
include ::neutron::params
|
||||
|
||||
$node_name = hiera('node_name')
|
||||
|
|
|
@ -2,26 +2,6 @@ class openstack_tasks::openstack_network::server_config {
|
|||
|
||||
notice('MODULAR: openstack_network/server_config.pp')
|
||||
|
||||
# override neutron options
|
||||
$override_configuration = hiera_hash('configuration', {})
|
||||
$override_values = values($override_configuration)
|
||||
if !empty($override_values) and has_key($override_values[0], 'data') {
|
||||
# Create resources of type 'override_resources'. These, in turn,
|
||||
# will either update existing resources in the catalog with new data,
|
||||
# or create these resources, if they do not actually exist.
|
||||
create_resources(override_resources, $override_configuration)
|
||||
} else {
|
||||
override_resources { 'neutron_api_config':
|
||||
data => $override_configuration['neutron_api_config']
|
||||
} ~> Service['neutron-server']
|
||||
override_resources { 'neutron_config':
|
||||
data => $override_configuration['neutron_config']
|
||||
} ~> Service['neutron-server']
|
||||
override_resources { 'neutron_plugin_ml2':
|
||||
data => $override_configuration['neutron_plugin_ml2']
|
||||
} ~> Service['neutron-server']
|
||||
}
|
||||
|
||||
$neutron_config = hiera_hash('neutron_config')
|
||||
$neutron_server_enable = pick($neutron_config['neutron_server_enable'], true)
|
||||
$database_vip = hiera('database_vip')
|
||||
|
|
|
@ -3,32 +3,11 @@ class openstack_tasks::roles::compute {
|
|||
notice('MODULAR: roles/compute.pp')
|
||||
|
||||
$network_scheme = hiera_hash('network_scheme', {})
|
||||
$override_configuration = hiera_hash('configuration', {})
|
||||
$network_metadata = hiera_hash('network_metadata', {})
|
||||
$nova_report_interval = hiera('nova_report_interval', '60')
|
||||
$nova_service_down_time = hiera('nova_service_down_time', '180')
|
||||
prepare_network_config($network_scheme)
|
||||
|
||||
$override_values = values($override_configuration)
|
||||
if !empty($override_values) and has_key($override_values[0], 'data') {
|
||||
# Create resources of type 'override_resources'. These, in turn,
|
||||
# will either update existing resources in the catalog with new data,
|
||||
# or create these resources, if they do not actually exist.
|
||||
create_resources(override_resources, $override_configuration)
|
||||
} else {
|
||||
# override nova options
|
||||
override_resources { 'nova_config':
|
||||
data => $override_configuration['nova_config']
|
||||
}
|
||||
|
||||
# override nova-api options
|
||||
override_resources { 'nova_paste_api_ini':
|
||||
data => $override_configuration['nova_paste_api_ini']
|
||||
}
|
||||
|
||||
Override_resources <||> ~> Service <| tag == 'nova-service' |>
|
||||
}
|
||||
|
||||
# Pulling hiera
|
||||
$compute_hash = hiera_hash('compute', {})
|
||||
$public_vip = hiera('public_vip')
|
||||
|
|
|
@ -1,67 +1,320 @@
|
|||
require 'puppet'
|
||||
require 'puppet/parameter/boolean'
|
||||
|
||||
# This Puppet metatype's purpose is to update the parameters of other type in the catalog
|
||||
# with the values from the configuration data structure, or even create the new ones.
|
||||
#
|
||||
# Configuration structure:
|
||||
#
|
||||
# configuration:
|
||||
# nova_config:
|
||||
# DEFAULT/debug
|
||||
# ensure: present
|
||||
# value: true
|
||||
# DEFAULT/verbose
|
||||
# ensure: absent
|
||||
#
|
||||
# file:
|
||||
# test_file:
|
||||
# ensure: present
|
||||
# path: /tmp/test
|
||||
# content: 123
|
||||
# web_file:
|
||||
# ensure: present
|
||||
# path: /var/www/html/index.html
|
||||
# content: '<html/>'
|
||||
#
|
||||
# service:
|
||||
# apache:
|
||||
# ensure: running
|
||||
# enable: true
|
||||
# require: File[web_file]
|
||||
#
|
||||
# Applying this structure will update the parameters of specified resources to the values in
|
||||
# the configuration structure. If the "create" option is enabled the missing resources will be added to
|
||||
# the catalog.
|
||||
#
|
||||
# Configuration options:
|
||||
# # These two options allows you to provide a list of resource types and/or resource titles
|
||||
# # which should be processed by this override_resources instance. If the lists are missing
|
||||
# # or empty no filtering will be used and all resources types and titles will be processed.
|
||||
# types_filter: []
|
||||
# titles_filter: []
|
||||
# # Enable the creation of all resources. New instances will be added to the catalog if an
|
||||
# # existing instance have not been found there.
|
||||
# create: true/false
|
||||
# # These two options allows you to set the exception lists for the new resource creation.
|
||||
# # If the "create" option is set to true, these lists of types and titles are used as
|
||||
# # the list of resources that should not be created. The resources mentioned in the lists
|
||||
# # will not be created and the resources not mentioned in the lists will be created.
|
||||
# # If the "create" option is set to false, these lists of types and titles are used as
|
||||
# # the list of resources that should be created. The resources mentioned in the lists
|
||||
# # will be created and the resources not mentioned in the lists will not be created.
|
||||
# types_create_exception: []
|
||||
# titles_create_exception: []
|
||||
# # This structure allows you to set the default parameters for every Puppet type.
|
||||
# # If you want all resources of the same type to share the same parameter value
|
||||
# # (i.e. ensure: present) you can set this value for all resources of this type here.
|
||||
# # The value wil be added to every updated or created resource of this type unless
|
||||
# # the other value is provided for a resource in the configuration data.
|
||||
# defaults:
|
||||
# <type>:
|
||||
# <parameter>: <value>
|
||||
#
|
||||
# These options can be set as the "options" parameter, or can be accessed individually
|
||||
# trough the corresponding resource parameters which will override the values set in the
|
||||
# "options" structure.
|
||||
#
|
||||
# Example usage:
|
||||
#
|
||||
# override_resources { 'my_test_override' :
|
||||
# configuration => hiera_hash('configuration', {}),
|
||||
# options => hiera_hash('configuration_options', {}),
|
||||
# # you can locally override the values in the hiera options like this
|
||||
# # types_filter => ['package','service'],
|
||||
# # create => false,
|
||||
# }
|
||||
#
|
||||
Puppet::Type.newtype(:override_resources) do
|
||||
|
||||
newparam(:type) do
|
||||
newparam(:name) do
|
||||
desc 'The uniq name of this override)resources type. Serves no purpose other then reference.'
|
||||
isnamevar
|
||||
end
|
||||
|
||||
newparam(:data) do
|
||||
newparam(:configuration) do
|
||||
desc 'The configuration data structure to work with.'
|
||||
defaultto {}
|
||||
validate do |value|
|
||||
fail "Configuration data should contain a resources hash! Got: #{value.class}" unless value.is_a? Hash
|
||||
end
|
||||
end
|
||||
|
||||
newparam(:options) do
|
||||
desc 'The options data structure to work with.'
|
||||
defaultto {}
|
||||
validate do |value|
|
||||
fail "Options data should contain an options hash! Got: #{value.class}" unless value.is_a? Hash
|
||||
end
|
||||
end
|
||||
|
||||
newparam(:types_filter, :array_matching => :all) do
|
||||
desc 'The list of Puppet types to process. If the list is empty all the types in the configuration data will be processed.'
|
||||
defaultto []
|
||||
end
|
||||
|
||||
newparam(:titles_filter, :array_matching => :all) do
|
||||
desc 'The list of Puppet resource titles to process. If the list is empty all the resources in the configuration data will be processed.'
|
||||
defaultto []
|
||||
end
|
||||
|
||||
newparam(:create, :boolean => true, :parent => Puppet::Parameter::Boolean) do
|
||||
desc 'Should this type try to create the new resources in the configuration data or only update the existing ones?'
|
||||
end
|
||||
|
||||
newparam(:types_create_exception, :array_matching => :all) do
|
||||
desc 'The list of Puppet types that should be created if the "create" option is not set, or, not created, if the "create" option is set.'
|
||||
defaultto []
|
||||
end
|
||||
|
||||
newparam(:titles_create_exception, :array_matching => :all) do
|
||||
desc 'The list of Puppet titles that should be created if the "create" option is not set, or, not created, if the "create" option is set.'
|
||||
defaultto []
|
||||
end
|
||||
|
||||
newparam(:defaults) do
|
||||
desc 'The default parameters. This data structure should be a hash with the type name as a key and a hash of default parameters as a value.'
|
||||
defaultto {}
|
||||
validate do |value|
|
||||
fail "Defaults data should contain a defaults hash! Got: #{value.class}" unless value.is_a? Hash
|
||||
end
|
||||
end
|
||||
|
||||
newparam(:create_res) do
|
||||
defaultto true
|
||||
##########
|
||||
|
||||
# Get the configuration data structure
|
||||
# @return [Hash<String>]
|
||||
def configuration
|
||||
self[:configuration] || {}
|
||||
end
|
||||
|
||||
# Get the options data structure
|
||||
# @return [Hash<String>]
|
||||
def options
|
||||
self[:options] || {}
|
||||
end
|
||||
|
||||
# Get the list of filtered in types
|
||||
# @return [Array<String>]
|
||||
def types_filter
|
||||
types_filter = self[:types_filter] || []
|
||||
return types_filter if types_filter.any?
|
||||
options.fetch 'types_filter', []
|
||||
end
|
||||
|
||||
# Get the list of filtered in titles
|
||||
# @return [Array<String>]
|
||||
def titles_filter
|
||||
titles_filter = self[:titles_filter] || []
|
||||
return titles_filter if titles_filter.any?
|
||||
options.fetch 'titles_filter', []
|
||||
end
|
||||
|
||||
# Get the value of the create option
|
||||
# @return [true,false]
|
||||
def create?
|
||||
create = self[:create]
|
||||
return create unless create.nil?
|
||||
options.fetch 'create', false
|
||||
end
|
||||
|
||||
# Get the list of type create exceptions
|
||||
# @return [Array<String>]
|
||||
def types_create_exception
|
||||
types_create_exception = self[:types_create_exception] || []
|
||||
return types_create_exception if types_create_exception.any?
|
||||
options.fetch 'types_create_exception', []
|
||||
end
|
||||
|
||||
# Get the list of title create exceptions
|
||||
# @return [Array<String>]
|
||||
def titles_create_exception
|
||||
titles_create_exception = self[:titles_create_exception] || []
|
||||
return titles_create_exception if titles_create_exception.any?
|
||||
options.fetch 'titles_create_exception', []
|
||||
end
|
||||
|
||||
# Get the defaults data structure
|
||||
# @return [Hash<String>]
|
||||
def defaults
|
||||
defaults = self[:defaults] || {}
|
||||
return defaults if defaults.any?
|
||||
options.fetch 'defaults', {}
|
||||
end
|
||||
|
||||
##########
|
||||
# Check if this type should be created
|
||||
# either by the create value or by the exception
|
||||
# @param [String] type
|
||||
# @return [true,false]
|
||||
def type_create?(type)
|
||||
if create?
|
||||
not types_create_exception.include? type
|
||||
else
|
||||
types_create_exception.include? type
|
||||
end
|
||||
end
|
||||
|
||||
# Check if this title should be created
|
||||
# either by the create value or by the exception
|
||||
# @param [String] title
|
||||
# @return [true,false]
|
||||
def title_create?(title)
|
||||
if create?
|
||||
not titles_create_exception.include? title
|
||||
else
|
||||
titles_create_exception.include? title
|
||||
end
|
||||
end
|
||||
|
||||
# Check if this type's processing is enabled
|
||||
# or the filter is empty
|
||||
# @param [String] type
|
||||
# @return [true,false]
|
||||
def type_enabled?(type)
|
||||
return true unless types_filter.any?
|
||||
types_filter.include? type
|
||||
end
|
||||
|
||||
# Check if this title's processing is enabled
|
||||
# or the filter is empty
|
||||
# @param [String] title
|
||||
# @return [true,false]
|
||||
def title_enabled?(title)
|
||||
return true unless titles_filter.any?
|
||||
titles_filter.include? title
|
||||
end
|
||||
|
||||
# Get the default parameters for a given type
|
||||
# @param [String] type
|
||||
# @return [Hash<String>]
|
||||
def defaults_for(type)
|
||||
default_parameters = defaults.fetch type.to_s, {}
|
||||
fail "Default for the type: #{type} should be a hash of parameters. Got: #{default_parameters.inspect}" unless default_parameters.is_a? Hash
|
||||
default_parameters
|
||||
end
|
||||
|
||||
# Find a resource in the catalog and set its parameters
|
||||
# to the provided values.
|
||||
# @param [String] type
|
||||
# @param [String] title
|
||||
# @param [Hash<String>] parameters
|
||||
def update_resource(type, title, parameters = {})
|
||||
fail 'First argument should be the type of the resource!' unless type and not type.empty?
|
||||
fail 'Second argument should be the title of the resource!' unless title and not title.empty?
|
||||
fail 'Third argument should contain resource parameters hash!' unless parameters.is_a? Hash
|
||||
resource = catalog.resource type, title
|
||||
unless resource
|
||||
debug "#{type}[#{title}]: was not found in the catalog!"
|
||||
return
|
||||
return false
|
||||
end
|
||||
parameters.each do |parameter, value|
|
||||
resource[parameter] = value
|
||||
end
|
||||
if parameters.has_key?('value') and resource.property('ensure')
|
||||
resource['ensure'] = :present
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
# Check if a resource with the given type and title
|
||||
# is present in the catalog.
|
||||
# @param [String] type
|
||||
# @param [String] title
|
||||
# @return [true,false]
|
||||
def resource_present?(type, title)
|
||||
!!catalog.resource(type, title)
|
||||
end
|
||||
|
||||
# Create a new resource by the Puppet type name,
|
||||
# resource title and parameters and return the instance.
|
||||
# @param [String] type
|
||||
# @param [String] title
|
||||
# @param [Hash<String>] parameters
|
||||
# @return [Puppet::Type]
|
||||
def create_resource(type, title, parameters = {})
|
||||
parameters = parameters.merge(:name => title)
|
||||
Puppet::Type.type(type.to_sym).new(parameters)
|
||||
end
|
||||
|
||||
# The main method of this metatype. Updates the existing resources
|
||||
# according to the configuration, and, if crete is enabled,
|
||||
# returns the array of the new resources that should be added to
|
||||
# the catalog.
|
||||
# @return [Array<Puppet::Type>]
|
||||
def eval_generate
|
||||
type = self[:type]
|
||||
data = self[:data] || {}
|
||||
defaults = self[:defaults] || {}
|
||||
create_res = self[:create_res] || false
|
||||
|
||||
fail 'Title should be a resource type to override!' unless type and not type.empty?
|
||||
fail 'Data should contain resource hash!' unless data.is_a? Hash
|
||||
fail 'Defaults should contain resource defaults hash!' unless defaults.is_a? Hash
|
||||
|
||||
new_resources = []
|
||||
configuration.each do |type, resources|
|
||||
fail "The 'type' should be the name of the Puppet type and not be empty! Got: #{type.inspect}" unless type and not type.empty?
|
||||
fail "The 'resources' should be a hash with the override Puppet resources! Got: #{resources.inspect}" unless resources.is_a? Hash
|
||||
next unless type_enabled? type
|
||||
debug "Processing type: #{type}"
|
||||
resources.each do |title, parameters|
|
||||
fail "The 'title' should be the title of the Puppet resource nd should not be empty! Got: #{title.inspect}" unless title and not title.empty?
|
||||
fail "The 'parameters' should be a hash of the resource parameters! Got: #{parameters.inspect}" unless parameters.is_a? Hash
|
||||
next unless title_enabled? title
|
||||
debug "Processing resource: #{type}[#{title}]"
|
||||
parameters = defaults_for(type).merge parameters
|
||||
|
||||
if resource_present? type, title
|
||||
debug "#{type.capitalize}[#{title}] was found in the catalog, updating it!"
|
||||
update_resource type, title, parameters
|
||||
else
|
||||
if type_create? type or title_create? title
|
||||
debug "#{type.capitalize}[#{title}] was not found in the catalog, creating it!"
|
||||
new_resources << create_resource(type, title, parameters)
|
||||
else
|
||||
debug "#{type.capitalize}[#{title}] was not found in the catalog, skipping it!"
|
||||
next
|
||||
end
|
||||
end
|
||||
|
||||
data.each do |title, parameters|
|
||||
parameters = defaults.merge parameters
|
||||
resource = catalog.resource type, title
|
||||
if resource
|
||||
debug "#{type}[#{title}]: found in the catalog, updating it"
|
||||
update_resource type, title, parameters
|
||||
elsif create_res
|
||||
debug "#{type}[#{title}]: was not found in the catalog, creating it"
|
||||
new_resources << create_resource(type, title, parameters)
|
||||
end
|
||||
end
|
||||
|
||||
new_resources
|
||||
end
|
||||
|
||||
|
|
|
@ -13,8 +13,6 @@ class osnailyfacter::cluster_haproxy::cluster_haproxy {
|
|||
$colocate_haproxy = hiera('colocate_haproxy', false)
|
||||
$ssl_default_ciphers = hiera('ssl_default_ciphers', 'HIGH:!aNULL:!MD5:!kEDH')
|
||||
|
||||
$override_configuration = hiera_hash('configuration', {})
|
||||
$user_defined_options = $override_configuration['haproxy']
|
||||
if !$external_lb {
|
||||
#FIXME(mattymo): Replace with only VIPs for roles assigned to this node
|
||||
$stats_ipaddresses = delete_undef_values([$management_vip, $database_vip, $service_endpoint, '127.0.0.1'])
|
||||
|
@ -27,7 +25,6 @@ class osnailyfacter::cluster_haproxy::cluster_haproxy {
|
|||
other_networks => direct_networks($network_scheme['endpoints']),
|
||||
stats_ipaddresses => $stats_ipaddresses,
|
||||
colocate_haproxy => $colocate_haproxy,
|
||||
user_defined_options => $user_defined_options,
|
||||
ssl_default_ciphers => $ssl_default_ciphers,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,8 +38,6 @@ class osnailyfacter::database::database {
|
|||
$backend_port = '3307'
|
||||
$backend_timeout = '10'
|
||||
|
||||
$configuration = hiera_hash('configuration', {})
|
||||
$mysql_user_defined_configuration = pick($configuration['mysql'], {})
|
||||
#############################################################################
|
||||
validate_string($status_password)
|
||||
validate_string($mysql_root_password)
|
||||
|
@ -256,7 +254,7 @@ class osnailyfacter::database::database {
|
|||
$syslog_options
|
||||
)
|
||||
$galera_options = mysql_deepmerge($wsrep_options, $vendor_override_options)
|
||||
$override_options = mysql_deepmerge($mysql_override_options, $galera_options, $mysql_user_defined_configuration)
|
||||
$override_options = mysql_deepmerge($mysql_override_options, $galera_options)
|
||||
|
||||
class { '::galera':
|
||||
vendor_type => $vendor_type,
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
class osnailyfacter::override_resources {
|
||||
|
||||
$override_configuration = hiera_hash(configuration, {})
|
||||
$override_configuration_options = hiera_hash(configuration_options, {})
|
||||
|
||||
override_resources {'override-resources':
|
||||
configuration => $override_configuration,
|
||||
options => $override_configuration_options,
|
||||
}
|
||||
|
||||
}
|
|
@ -70,14 +70,7 @@ class osnailyfacter::rabbitmq::rabbitmq {
|
|||
$epmd_bind_ip_address = $rabbitmq_bind_ip_address
|
||||
}
|
||||
|
||||
$configuration = hiera_hash('configuration', {})
|
||||
|
||||
$config_vars = pick($configuration['rabbitmq'], {})
|
||||
|
||||
$config_kernel_variables = pick(
|
||||
$config_vars['kernel'],
|
||||
hiera_hash('rabbit_config_kernel_variables', {})
|
||||
)
|
||||
$config_kernel_variables = hiera_hash('rabbit_config_kernel_variables', {})
|
||||
$config_kernel_variables_default = {
|
||||
'inet_dist_listen_min' => '41055',
|
||||
'inet_dist_listen_max' => '41055',
|
||||
|
@ -99,10 +92,10 @@ class osnailyfacter::rabbitmq::rabbitmq {
|
|||
'num_tcp_acceptors' => 10,
|
||||
}
|
||||
|
||||
$config_variables = pick($config_vars['application'], hiera_hash('rabbit_config_variables', {}))
|
||||
$config_variables = hiera_hash('rabbit_config_variables', {})
|
||||
$config_variables_merged = merge($config_variables_default, $config_variables)
|
||||
|
||||
$config_management_variables = pick($config_vars['management'], hiera_hash('rabbit_config_management_variables', {}))
|
||||
$config_management_variables = hiera_hash('rabbit_config_management_variables', {})
|
||||
|
||||
$config_management_variables_default ={
|
||||
'rates_mode' => 'none',
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
class { '::osnailyfacter::cluster_haproxy::cluster_haproxy' :}
|
||||
class { '::osnailyfacter::upgrade::restart_services' :}
|
||||
class { '::osnailyfacter::override_resources': }
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
class { '::osnailyfacter::database::database' :}
|
||||
class { '::osnailyfacter::override_resources': }
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
class { '::osnailyfacter::rabbitmq::rabbitmq' :}
|
||||
class { '::osnailyfacter::override_resources': }
|
||||
|
|
|
@ -1,20 +1,71 @@
|
|||
require 'puppet'
|
||||
require 'puppet/type/override_resources'
|
||||
require_relative '../../../lib/puppet/type/override_resources'
|
||||
require 'yaml'
|
||||
|
||||
describe Puppet::Type.type(:override_resources) do
|
||||
|
||||
before :each do
|
||||
@overres = Puppet::Type.type(:override_resources).new(
|
||||
:type => 'keystone_config',
|
||||
:data => {},
|
||||
:defaults => {},
|
||||
:create_res => true
|
||||
let(:override_resources) do
|
||||
Puppet::Type.type(:override_resources).new(
|
||||
:name => 'foo',
|
||||
:configuration => configuration,
|
||||
:options => options,
|
||||
)
|
||||
end
|
||||
|
||||
it 'should accept a config' do
|
||||
@overres[:name] = 'keystone_config'
|
||||
expect(@overres[:name]).to eq('keystone_config')
|
||||
subject { override_resources }
|
||||
|
||||
let(:configuration) do
|
||||
YAML.load <<-eof
|
||||
---
|
||||
nova_config:
|
||||
DEFAULT/debug:
|
||||
value: true
|
||||
DEFAULT/verbose:
|
||||
ensure: absent
|
||||
file:
|
||||
'/tmp/test':
|
||||
content: 123
|
||||
'/etc/httpd/httpd.conf':
|
||||
source: 'puppet:///modules/httpd/httpd.conf'
|
||||
owner: httpd
|
||||
group: httpd
|
||||
notify: 'Service[httpd]'
|
||||
my_symlink:
|
||||
ensure: symlink
|
||||
path: '/tmp/test1'
|
||||
target: '/tmp/test'
|
||||
service:
|
||||
httpd:
|
||||
ensure: running
|
||||
enable: true
|
||||
nginx:
|
||||
ensure: stopped
|
||||
enable: false
|
||||
package:
|
||||
mc:
|
||||
htop:
|
||||
ensure: absent
|
||||
ntpd:
|
||||
ensure: latest
|
||||
my_package:
|
||||
ensure: 1
|
||||
eof
|
||||
end
|
||||
|
||||
let(:options) do
|
||||
YAML.load <<-eof
|
||||
---
|
||||
types_filter: []
|
||||
titles_filter: []
|
||||
create: false
|
||||
types_create_exception: []
|
||||
titles_create_exception: []
|
||||
defaults:
|
||||
package:
|
||||
ensure: present
|
||||
file:
|
||||
ensure: present
|
||||
eof
|
||||
end
|
||||
|
||||
it 'should require a name' do
|
||||
|
@ -23,45 +74,56 @@ describe Puppet::Type.type(:override_resources) do
|
|||
}.to raise_error(Puppet::Error, 'Title or name must be provided')
|
||||
end
|
||||
|
||||
it 'should be a resource type to override' do
|
||||
it 'should require configuration to be a hash' do
|
||||
expect {
|
||||
@overres[:type] = ''
|
||||
@overres.eval_generate
|
||||
}.to raise_error(Puppet::Error, /Title should be a resource type to override!$/)
|
||||
end
|
||||
|
||||
it 'should contain resource hash' do
|
||||
expect {
|
||||
@overres[:data] = 'string => data'
|
||||
@overres.eval_generate
|
||||
}.to raise_error(Puppet::Error, /Data should contain resource hash!$/)
|
||||
override_resources[:configuration] = 'string => data'
|
||||
override_resources.eval_generate
|
||||
}.to raise_error(Puppet::ResourceError, /Configuration data should contain a resources hash!/)
|
||||
end
|
||||
|
||||
it 'should contain resource defaults hash' do
|
||||
expect {
|
||||
@overres[:defaults] = 'string => data'
|
||||
@overres.eval_generate
|
||||
}.to raise_error(Puppet::Error, /Defaults should contain resource defaults hash!$/)
|
||||
override_resources[:defaults] = 'string => data'
|
||||
override_resources.eval_generate
|
||||
}.to raise_error(Puppet::ResourceError, /Defaults data should contain a defaults hash!/)
|
||||
end
|
||||
|
||||
it 'should accept a resource type' do
|
||||
it 'should accept a resource type into types_filter' do
|
||||
type = 'keystone_config'
|
||||
@overres[:type] = type
|
||||
expect(@overres[:type]).to eq(type)
|
||||
override_resources[:types_filter] = type
|
||||
expect(override_resources[:types_filter]).to eq(type)
|
||||
end
|
||||
|
||||
it 'should accept an override data' do
|
||||
it 'should accept a resource type into types_create_exception' do
|
||||
type = 'keystone_config'
|
||||
override_resources[:types_create_exception] = type
|
||||
expect(override_resources[:types_create_exception]).to eq(type)
|
||||
end
|
||||
|
||||
it 'should accept a resource type into titles_filter' do
|
||||
title = 'bar'
|
||||
override_resources[:titles_filter] = title
|
||||
expect(override_resources[:titles_filter]).to eq(title)
|
||||
end
|
||||
|
||||
it 'should accept a resource title into titles_create_exception' do
|
||||
title = 'bar'
|
||||
override_resources[:titles_create_exception] = title
|
||||
expect(override_resources[:titles_create_exception]).to eq(title)
|
||||
end
|
||||
|
||||
it 'should accept defaults data' do
|
||||
data = {
|
||||
'DEFAULT/debug' => { 'value' => false },
|
||||
'DEFAULT/max_param_size' => { 'value' => 128 }
|
||||
}
|
||||
@overres[:data] = data
|
||||
expect(@overres[:data]).to eq(data)
|
||||
override_resources[:defaults] = data
|
||||
expect(override_resources[:defaults]).to eq(data)
|
||||
end
|
||||
|
||||
it 'should accept create flag' do
|
||||
cr = true
|
||||
@overres[:create_res] = cr
|
||||
expect(@overres[:create_res]).to eq(cr)
|
||||
override_resources[:create] = cr
|
||||
expect(override_resources[:create]).to eq(cr)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue