diff options
author | Luke Kanies <luke@madstop.com> | 2008-12-08 18:02:21 -0600 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-12-09 15:15:38 -0600 |
commit | e88746b48cfd4ce7cd9acd0baf61d9b660b460e9 (patch) | |
tree | e58bd5a140342ade2cfeae50412c533f36e82926 /lib/puppet | |
parent | 832198f56cfabc7a6ab1a97b99f61e278c16bc8b (diff) | |
download | puppet-e88746b48cfd4ce7cd9acd0baf61d9b660b460e9.tar.gz puppet-e88746b48cfd4ce7cd9acd0baf61d9b660b460e9.tar.xz puppet-e88746b48cfd4ce7cd9acd0baf61d9b660b460e9.zip |
Adding Trans{Object,Bucket} backward compatibility to Puppet::Resource
This is further progress toward #1808.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/resource.rb | 57 | ||||
-rw-r--r-- | lib/puppet/resource_reference.rb | 12 |
2 files changed, 69 insertions, 0 deletions
diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb index 8dc09e521..9bbec2a4c 100644 --- a/lib/puppet/resource.rb +++ b/lib/puppet/resource.rb @@ -98,8 +98,65 @@ class Puppet::Resource end end + # Translate our object to a backward-compatible transportable object. + def to_trans + if @reference.builtin_type? + result = to_transobject + else + result = to_transbucket + end + + result.file = self.file + result.line = self.line + + return result + end + private + # Create an old-style TransBucket instance, for non-builtin resource types. + def to_transbucket + bucket = Puppet::TransBucket.new([]) + + bucket.type = self.type + bucket.name = self.title + + # TransBuckets don't support parameters, which is why they're being deprecated. + return bucket + end + + # Create an old-style TransObject instance, for builtin resource types. + def to_transobject + # Now convert to a transobject + result = Puppet::TransObject.new(@reference.title, @reference.type) + to_hash.each do |p, v| + if v.is_a?(Puppet::ResourceReference) + v = v.to_trans_ref + elsif v.is_a?(Array) + v = v.collect { |av| + if av.is_a?(Puppet::ResourceReference) + av = av.to_trans_ref + end + av + } + end + + # If the value is an array with only one value, then + # convert it to a single value. This is largely so that + # the database interaction doesn't have to worry about + # whether it returns an array or a string. + result[p.to_s] = if v.is_a?(Array) and v.length == 1 + v[0] + else + v + end + end + + result.tags = self.tags + + return result + end + # Produce a canonical method name. def parameter_name(param) param.to_s.downcase.to_sym diff --git a/lib/puppet/resource_reference.rb b/lib/puppet/resource_reference.rb index a3e0a7514..43479ff0c 100644 --- a/lib/puppet/resource_reference.rb +++ b/lib/puppet/resource_reference.rb @@ -51,6 +51,18 @@ class Puppet::ResourceReference end end + # Convert to the reference format that TransObject uses. Yay backward + # compatibility. + def to_trans_ref + # We have to return different cases to provide backward compatibility + # from 0.24.x to 0.23.x. + if builtin_type? + return [type.to_s.downcase, title.to_s] + else + return [type.to_s, title.to_s] + end + end + # Convert to the standard way of referring to resources. def to_s "%s[%s]" % [@type, @title] |