Created
December 2, 2014 19:46
-
-
Save hkumarmk/1960e77f14001c4ed08c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########## Type | |
################## | |
Puppet::Type.newtype(:rjil_tempest_config) do | |
ensurable | |
newparam(:name, :namevar => true) do | |
desc 'Section/setting name to manage from tempest.conf' | |
newvalues(/\S+\/\S+/) | |
end | |
newproperty(:value) do | |
desc 'The value of the setting to be defined.' | |
munge do |value| | |
value = value.to_s.strip | |
value.capitalize! if value =~ /^(true|false)$/i | |
value | |
end | |
def is_to_s( currentvalue ) | |
if resource.secret? | |
return '[old secret redacted]' | |
else | |
return currentvalue | |
end | |
end | |
def should_to_s( newvalue ) | |
if resource.secret? | |
return '[new secret redacted]' | |
else | |
return newvalue | |
end | |
end | |
end | |
newparam(:secret, :boolean => true) do | |
desc 'Whether to hide the value from Puppet logs. Defaults to `false`.' | |
newvalues(:true, :false) | |
defaultto false | |
end | |
newparam(:path) do | |
desc 'The ini file Puppet will ensure contains the specified setting.' | |
validate do |value| | |
unless (Puppet.features.posix? and value =~ /^\//) or (Puppet.features.microsoft_windows? and (value =~ /^.:\// or value =~ /^\/\/[^\/]+\/[^\/]+/)) | |
raise(Puppet::Error, "File paths must be fully qualified, not '#{value}'") | |
end | |
end | |
end | |
newparam(:set_id) do | |
desc 'Write id of given value rather than value itself. | |
Tempest need id for glance image and public network. | |
The values glance_image and network are valid.' | |
validate do |value| | |
if value !~ /(glance_image|network)/ | |
raise(Puppet::Error, "Invalid values, Valid values are: glance_image, network") | |
end | |
end | |
end | |
end | |
## Provider | |
################## | |
Puppet::Type.type(:rjil_tempest_config).provide( | |
:ini_setting, | |
:parent => Puppet::Type.type(:ini_setting).provider(:ruby) | |
) do | |
def section | |
resource[:name].split('/', 2).first | |
end | |
def setting | |
resource[:name].split('/', 2).last | |
end | |
def separator | |
'=' | |
end | |
def glance_image_id | |
@image_id ||= Puppet::Resource.indirection.find("Glance_image/#{resource[:value]}")[:id] | |
@image_id if @image_id != :absent | |
end | |
def get_network_id | |
@network_id ||= Puppet::Resource.indirection.find("Neutron_network/#{resource[:value]}")[:id] | |
@network_id if @network_id != :absent | |
end | |
def getval | |
if ! resource[:set_id] | |
return resource[:value] | |
elsif resource[:set_id] == 'glance_image' | |
return glance_image_id | |
elsif resource[:set_id] == 'network' | |
return get_network_id | |
end | |
end | |
def create | |
ini_file.set_value(section, setting, getval) | |
ini_file.save | |
@ini_file = nil | |
end | |
def value | |
if ini_file.get_value(section, setting) == getval | |
return resource[:value] | |
end | |
end | |
def value=(value) | |
ini_file.set_value(section, setting, getval) | |
ini_file.save | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment