Files
puppet-keystone/lib/puppet_x/keystone/composite_namevar.rb
Sofer Athlan-Guyot d3f03c6732 Keystone user issues on Puppet Enterprise.
Puppet Enterprise doesn't work for:
 - keystone_user;
 - keystone_tenant;
 - keystone_user_role;

    Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not autoload puppet/type/keystone_user: Malformed version number string 3.8.1 (Puppet Enterprise 3.8.1)

This is due to the modified version string that Puppet Enterprise uses.
This patch takes this string into consideration.  It has been tested
successfully on Puppet Enterprise.

Change-Id: I8c79b9331134762620509ca0a6c09e16e534ad9b
Closes-Bug: #1516687
2015-11-16 17:40:05 +01:00

72 lines
2.1 KiB
Ruby

# Cherry pick PUP-1073 from puppetlabs: support of composite namevar for alias.
if Gem::Version.new(Puppet.version.sub(/\(Puppet Enterprise .*/i, '').strip) < Gem::Version.new('4.0.0')
Puppet::Resource::Catalog.class_eval do
def create_resource_aliases(resource)
# Skip creating aliases and checking collisions for non-isomorphic resources.
return unless resource.respond_to?(:isomorphic?) and resource.isomorphic?
# Add an alias if the uniqueness key is valid and not the
# title, which has already been checked.
ukey = resource.uniqueness_key
if ukey.any? and ukey != [resource.title]
self.alias(resource, ukey)
end
end
end
Puppet::Resource.class_eval do
def uniqueness_key
# Temporary kludge to deal with inconsistent use patterns; ensure we don't return nil for namevar/:name
h = self.to_hash
name = h[namevar] || h[:name] || self.name
h[namevar] ||= name
h[:name] ||= name
h.values_at(*key_attributes.sort_by { |k| k.to_s })
end
end
end
require 'puppet_x/keystone/composite_namevar/helpers'
module PuppetX
module Keystone
module CompositeNamevar
class Unset; end
def self.not_two_colon_regex
# Anything but 2 consecutive colons.
Regexp.new(/(?:[^:]|:[^:])+/)
end
def self.basic_split_title_patterns(prefix, suffix, separator = '::', *regexps)
associated_regexps = []
if regexps.empty? and separator == '::'
associated_regexps += [not_two_colon_regex, not_two_colon_regex]
else
if regexps.count != 2
raise(Puppet::DevError, 'You must provide two regexps')
else
associated_regexps += regexps
end
end
prefix_re = associated_regexps[0]
suffix_re = associated_regexps[1]
[
[
/^(#{prefix_re})#{separator}(#{suffix_re})$/,
[
[prefix],
[suffix]
]
],
[
/^(#{prefix_re})$/,
[
[prefix]
]
]
]
end
end
end
end