/usr/share/puppet/modules.available/openstacklib/lib/puppet/provider/openstack_config/ruby.rb is in puppet-module-openstacklib 9.4.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | require File.expand_path('../../../util/openstackconfig', __FILE__)
Puppet::Type.type(:openstack_config).provide(:ruby) do
def self.instances
if self.respond_to?(:file_path)
config = Puppet::Util::OpenStackConfig.new(file_path)
resources = []
config.section_names.each do |section_name|
config.get_settings(section_name).each do |setting, value|
resources.push(
new(
:name => namevar(section_name, setting),
:value => value,
:ensure => :present
)
)
end
end
resources
else
raise(Puppet::Error,
'OpenStackConfig only support collecting instances when a file path ' +
'is hard coded'
)
end
end
def self.namevar(section_name, setting)
"#{section_name}/#{setting}"
end
def exists?
if resource[:value] == ensure_absent_val
resource[:ensure] = :absent
end
!config.get_value(section, setting).nil?
end
def create
config.set_value(section, setting, resource[:value])
config.save
@config = nil
end
def destroy
config.remove_setting(section, setting)
config.save
@config = nil
end
def value=(value)
config.set_value(section, setting, resource[:value])
config.save
end
def value
val = config.get_value(section, setting)
if !val.kind_of?(Array)
[val]
else
val
end
end
def section
resource[:name].split('/', 2).first
end
def setting
resource[:name].split('/', 2).last
end
def ensure_absent_val
# :array_matching => :all values comes in form of array even when they
# are passed as single string
if resource[:value].kind_of?(Array) and not resource[:ensure_absent_val].kind_of?(Array)
[resource[:ensure_absent_val]]
else
resource[:ensure_absent_val]
end
end
def file_path
self.class.file_path
end
private
def config
@config ||= Puppet::Util::OpenStackConfig.new(file_path)
end
end
|