summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-10-01 21:03:42 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-10-01 21:03:42 +0000
commit6af0e0e5959e7b405191e0a916be097454a656e4 (patch)
tree886fc7cdebf9c7955aff6467302ec701012e792d /lib/puppet
parent0d6241ca97ded8e003338c6cf316e280530ea8ee (diff)
downloadpuppet-6af0e0e5959e7b405191e0a916be097454a656e4.tar.gz
puppet-6af0e0e5959e7b405191e0a916be097454a656e4.tar.xz
puppet-6af0e0e5959e7b405191e0a916be097454a656e4.zip
added overrides ability
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@711 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/type.rb98
-rw-r--r--lib/puppet/type/pfile.rb40
2 files changed, 84 insertions, 54 deletions
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 421cdf6ca..e0c31777b 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -435,20 +435,6 @@ class Type < Puppet::Element
end
end
- # remove a state from the object; useful in testing or in cleanup
- # when an error has been encountered
- def destroy
- self.class.delete(self)
-
- Puppet::Event::Subscription.dependencies(self).each { |dep|
- self.unsubscribe(dep)
- }
-
- if defined? @parent and @parent
- @parent.delete(self)
- end
- end
-
# iterate across all children, and then iterate across states
# we do children first so we're sure that all dependent objects
# are checked first
@@ -577,6 +563,25 @@ class Type < Puppet::Element
}
end
+ # Remove an object. The argument determines whether the object's
+ # subscriptions get eliminated, too.
+ def remove(rmdeps)
+ @children.each { |child|
+ child.remove
+ }
+ self.class.delete(self)
+
+ if rmdeps
+ Puppet::Event::Subscription.dependencies(self).each { |dep|
+ self.unsubscribe(dep)
+ }
+ end
+
+ if defined? @parent and @parent
+ @parent.delete(self)
+ end
+ end
+
# return an actual type by name; to return the value, use 'inst[name]'
# FIXME this method should go away
def state(name)
@@ -618,40 +623,51 @@ class Type < Puppet::Element
hash.delete(:implicit)
end
- if name = hash["name"] || hash[:name] ||
+ name = nil
+ unless name = hash["name"] || hash[:name] ||
hash[self.namevar] || hash[self.namevar.to_s]
- # if the object already exists
- if retobj = self[name]
- # if only one of our objects is implicit, then it's easy to see
- # who wins -- the non-implicit one.
+ raise Puppet::Error, "You must specify a name for objects of type %s" %
+ self.to_s
+ end
+ # if the object already exists
+ if retobj = self[name]
+ # if only one of our objects is implicit, then it's easy to see
+ # who wins -- the non-implicit one.
+ if retobj.implicit? and ! implicit
+ Puppet.warning "Removing implicit %s" % retobj.name
+ # Remove all of the objects, but do not remove their subscriptions.
+ retobj.remove(false)
+
+ # now pass through and create the new object
+ elsif implicit
+ Puppet.warning "Ignoring implicit %s" % name
+
+ return retobj
+ else
# merge the new data
retobj.merge(hash)
return retobj
- else
- # create it anew
- # if there's a failure, destroy the object if it got that far
- begin
- obj = new(hash)
- rescue => detail
- if Puppet[:debug]
- if detail.respond_to?(:stack)
- puts detail.stack
- end
- end
- Puppet.err "Could not create %s: %s" % [name, detail.to_s]
- if obj
- Puppet.err obj
- obj.destroy
- elsif obj = self[name]
- obj.destroy
- end
- return nil
+ end
+ end
+
+ # create it anew
+ # if there's a failure, destroy the object if it got that far
+ begin
+ obj = new(hash)
+ rescue => detail
+ if Puppet[:debug]
+ if detail.respond_to?(:stack)
+ puts detail.stack
end
end
- else
- raise Puppet::Error, "You must specify a name for objects of type %s" %
- self.to_s
+ Puppet.err "Could not create %s: %s" % [name, detail.to_s]
+ if obj
+ obj.remove(true)
+ elsif obj = self[name]
+ obj.remove(true)
+ end
+ return nil
end
end
diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb
index 82581998a..858b1995d 100644
--- a/lib/puppet/type/pfile.rb
+++ b/lib/puppet/type/pfile.rb
@@ -1165,24 +1165,38 @@ module Puppet
else
klass = self.class
end
+
+ # We know we're creating an implicit child. If the child we're
+ # trying to create already exists, then we know it should still
+ # be there, since if it shouldn't be, it would have already been
+ # removed. Either it's entirely explicit, in which case it
+ # should win, or it's implicit but resulting from a more explicit
+ # child.
if child = klass[path]
- unless @children.include?(child)
- raise Puppet::Error,
- "Planned child file %s of %s already exists with parent %s" %
- [path, self.name, child.parent]
- end
- args.each { |var,value|
- next if var == :path
- next if var == :name
- # behave idempotently
- unless child.should(var) == value
- child[var] = value
- end
- }
+ Puppet.warning "Not managing more explicit %s" % child
+ return nil
+ #unless @children.include?(child)
+ # raise Puppet::Error,
+ # "Planned child file %s of %s already exists with parent %s" %
+ # [path, self.name, child.parent]
+ #end
+ #args.each { |var,value|
+ # next if var == :path
+ # next if var == :name
+ # # behave idempotently
+ # unless child.should(var) == value
+ # child[var] = value
+ # end
+ #}
else # create it anew
#notice "Creating new file with args %s" % args.inspect
begin
child = klass.implicitcreate(args)
+
+ # implicit creation can return nil
+ if child.nil?
+ return nil
+ end
child.parent = self
@children << child
rescue Puppet::Error => detail