diff options
author | Jiri Stransky <jistr@redhat.com> | 2015-06-04 16:07:48 +0200 |
---|---|---|
committer | Jiri Stransky <jistr@redhat.com> | 2015-06-12 18:40:50 +0200 |
commit | 9793b3c97203e7ecc95aead151e8b983ae2552e0 (patch) | |
tree | 4e8de93b7c96df4c66d75ce1aaf46748bb9d6060 /lib/puppet/parser/functions | |
parent | a077eaf307998b3a9996fc5c0846f6604139a3e7 (diff) |
Configure fencing devices
Adds a class to configure fence devices and a helper function which
helps to select the devices for configuration on appropriate nodes.
Depends on patches outside OpenStack's Gerrit:
https://github.com/redhat-openstack/puppet-pacemaker/pull/50
https://github.com/redhat-openstack/puppet-pacemaker/pull/52
Change-Id: I819fc8c126ec47cd207c59b3dcf92ff699649c5a
Diffstat (limited to 'lib/puppet/parser/functions')
-rw-r--r-- | lib/puppet/parser/functions/local_fence_devices.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/puppet/parser/functions/local_fence_devices.rb b/lib/puppet/parser/functions/local_fence_devices.rb new file mode 100644 index 0000000..1ebce67 --- /dev/null +++ b/lib/puppet/parser/functions/local_fence_devices.rb @@ -0,0 +1,34 @@ +module Puppet::Parser::Functions + newfunction(:local_fence_devices, :arity =>2, :type => :rvalue, + :doc => ("Given an array of fence device configs, limit them" + + "to fence devices whose MAC address is present on" + + "some of the local NICs, and prepare a hash which can be" + + "passed to create_resources function")) do |args| + agent = args[0] + devices = args[1] + unless agent.is_a?(String) && agent.length > 0 + raise Puppet::ParseError, "local_fence_devices: Argument 'agent' must be a non-empty string. The value given was: #{agent_type}" + end + unless devices.is_a?(Array) + raise Puppet::ParseError, "local_fence_devices: Argument 'devices' must be an array. The value given was: #{devices}" + end + + # filter by agent type + agent_type_devices = devices.select { |device| device['agent'] == agent } + + # filter by local mac address + local_devices = agent_type_devices.select do |device| + function_has_interface_with(['macaddress', device['host_mac']]) + end + + # construct a hash for create_resources + return local_devices.each_with_object({}) do |device, hash| + # disallow collisions + if hash[device['host_mac']] + raise Puppet::ParseError, "local_fence_devices: Only single fence device per agent per host is allowed. Collision on #{device['host_mac']} for #{agent}" + end + + hash[device['host_mac']] = device['params'] || {} + end + end +end |