diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-01-13 20:55:13 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-01-13 20:55:13 +0000 |
| commit | a6e367e5989d0646c2f53c2de839893be76988cb (patch) | |
| tree | 188239cf15caa5f0a31caf32c8f68e86159b8ce5 /lib | |
| parent | c8b64014f1018dd437d1a0bd17db96b312e8af8a (diff) | |
| download | puppet-a6e367e5989d0646c2f53c2de839893be76988cb.tar.gz puppet-a6e367e5989d0646c2f53c2de839893be76988cb.tar.xz puppet-a6e367e5989d0646c2f53c2de839893be76988cb.zip | |
Changing host and port aliases to also create Puppet aliases. This involved futzing around with the attr* methods in Type.rb, to make sure states are always checked first.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@823 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet/type.rb | 40 | ||||
| -rwxr-xr-x | lib/puppet/type/parsedtype/host.rb | 21 | ||||
| -rwxr-xr-x | lib/puppet/type/parsedtype/port.rb | 16 |
3 files changed, 51 insertions, 26 deletions
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index 9c5f17ac9..0e4c1425d 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -196,17 +196,21 @@ class Type < Puppet::Element # the objects multiple times when iterating over them. def self.alias(name, obj) if @objects.include?(name) - raise Puppet::Error.new( - "Cannot create alias %s: object already exists" % - [name] - ) + unless @objects[name] == obj + raise Puppet::Error.new( + "Cannot create alias %s: object already exists" % + [name] + ) + end end if @aliases.include?(name) - raise Puppet::Error.new( - "Object %s already has alias %s" % - [@aliases[name].name, name] - ) + unless @aliases[name] == obj + raise Puppet::Error.new( + "Object %s already has alias %s" % + [@aliases[name].name, name] + ) + end end @aliases[name] = obj @@ -263,6 +267,9 @@ class Type < Puppet::Element if defined? @objects @objects.clear end + if defined? @aliases + @aliases.clear + end end # remove a specified object @@ -484,9 +491,9 @@ class Type < Puppet::Element # Find the class associated with any given attribute. def self.attrclass(name) case self.attrtype(name) - when :param: @paramhash[name] - when :meta: @@metaparamhash[name] when :state: @validstates[name] + when :meta: @@metaparamhash[name] + when :param: @paramhash[name] end end @@ -546,9 +553,9 @@ class Type < Puppet::Element # What type of parameter are we dealing with? def self.attrtype(name) case - when @paramhash.include?(name): return :param - when @@metaparamhash.include?(name): return :meta when @validstates.include?(name): return :state + when @@metaparamhash.include?(name): return :meta + when @paramhash.include?(name): return :param else raise Puppet::DevError, "Invalid attribute '%s' for class '%s'" % [name, self.name] @@ -644,9 +651,8 @@ class Type < Puppet::Element raise Puppet::Error.new("Got nil value for %s" % name) end - if Puppet::Type.metaparam?(name) - self.newmetaparam(self.class.metaparamclass(name), value) - elsif stateklass = self.class.validstate?(name) + case self.class.attrtype(name) + when :state if value.is_a?(Puppet::State) self.debug "'%s' got handed a state for '%s'" % [self,name] @states[name] = value @@ -662,7 +668,9 @@ class Type < Puppet::Element end end end - elsif self.class.validparameter?(name) + when :meta + self.newmetaparam(self.class.metaparamclass(name), value) + when :param # if they've got a method to handle the parameter, then do it that way self.newparam(self.class.attrclass(name), value) else diff --git a/lib/puppet/type/parsedtype/host.rb b/lib/puppet/type/parsedtype/host.rb index 69c1dbe06..93d0a9002 100755 --- a/lib/puppet/type/parsedtype/host.rb +++ b/lib/puppet/type/parsedtype/host.rb @@ -9,9 +9,12 @@ module Puppet desc "The host's IP address." end - newstate(:aliases) do - desc "Any aliases the host might have. Multiple values must be - specified as an array." + newstate(:alias) do + desc "Any alias the host might have. Multiple values must be + specified as an array. Note that this state has the same name + as one of the metaparams; using this state to set aliases will + make those aliases available in your Puppet scripts and also on + disk." # We have to override the feeding mechanism; it might be nil or # white-space separated @@ -36,6 +39,12 @@ module Puppet raise Puppet::Error, "Aliases cannot include whitespace" end end + + munge do |value| + # Add the :alias metaparam in addition to the state + @parent.newmetaparam(@parent.class.metaparamclass(:alias), value) + value + end end newparam(:name) do @@ -51,7 +60,7 @@ module Puppet @instances = [] @path = "/etc/hosts" - @fields = [:ip, :name, :aliases] + @fields = [:ip, :name, :alias] @filetype = Puppet::FileType.filetype(:flat) # case Facter["operatingsystem"].value @@ -83,8 +92,8 @@ module Puppet raise Puppet::Error, "Could not match '%s'" % line end - if hash[:aliases] == "" - hash.delete(:aliases) + if hash[:alias] == "" + hash.delete(:alias) end hash2obj(hash) diff --git a/lib/puppet/type/parsedtype/port.rb b/lib/puppet/type/parsedtype/port.rb index 65549d7da..be63c11be 100755 --- a/lib/puppet/type/parsedtype/port.rb +++ b/lib/puppet/type/parsedtype/port.rb @@ -44,9 +44,11 @@ module Puppet desc "The port description." end - newstate(:aliases) do + newstate(:alias) do desc "Any aliases the port might have. Multiple values must be specified - as an array." + as an array. Note that this state has the same name as one of the + metaparams; using this state to set aliases will make those aliases + available in your Puppet scripts and also on disk." # We have to override the feeding mechanism; it might be nil or # white-space separated @@ -71,6 +73,12 @@ module Puppet raise Puppet::Error, "Aliases cannot have whitespace in them" end end + + munge do |value| + # Add the :alias metaparam in addition to the state + @parent.newmetaparam(@parent.class.metaparamclass(:alias), value) + value + end end newparam(:name) do @@ -84,7 +92,7 @@ module Puppet will have different solutions." @path = "/etc/services" - @fields = [:ip, :name, :aliases] + @fields = [:ip, :name, :alias] @filetype = Puppet::FileType.filetype(:flat) # case Facter["operatingsystem"].value @@ -121,7 +129,7 @@ module Puppet line.sub!(/^([^#]+)\s*/) do |value| aliases = $1 unless aliases =~ /^\s*$/ - hash[:aliases] = aliases + hash[:alias] = aliases end "" |
