diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-19 02:08:11 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-19 02:08:11 +0000 |
| commit | dc5f4dc0d01dc2ccb4679afbf3802a7ab0f3c126 (patch) | |
| tree | 6082433e05ad445aa4323a05de7d5820c5c023d6 /lib/puppet/parser/collector.rb | |
| parent | 5a52855c1da2cb4716587bf0223c6d20eddaf00a (diff) | |
| download | puppet-dc5f4dc0d01dc2ccb4679afbf3802a7ab0f3c126.tar.gz puppet-dc5f4dc0d01dc2ccb4679afbf3802a7ab0f3c126.tar.xz puppet-dc5f4dc0d01dc2ccb4679afbf3802a7ab0f3c126.zip | |
Fixing most of the rails stuff. I think everything basically works now, and now I am just going through and making sure things get deleted when they are supposed (i.e., you remove a resource and it gets deleted from the host's config).
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1950 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/parser/collector.rb')
| -rw-r--r-- | lib/puppet/parser/collector.rb | 83 |
1 files changed, 46 insertions, 37 deletions
diff --git a/lib/puppet/parser/collector.rb b/lib/puppet/parser/collector.rb index ea54c2dcf..841d8585f 100644 --- a/lib/puppet/parser/collector.rb +++ b/lib/puppet/parser/collector.rb @@ -6,13 +6,16 @@ class Puppet::Parser::Collector # Collect exported objects. def collect_exported require 'puppet/rails' - Puppet.info "collecting %s" % @type # First get everything from the export table. Just reuse our # collect_virtual method but tell it to use 'exported? for the test. resources = collect_virtual(true) count = 0 + unless @scope.host + raise Puppet::DevError, "Cannot collect resources for a nil host" + end + # We're going to collect objects from rails, but we don't want any # objects from this host. host = Puppet::Rails::Host.find_by_name(@scope.host) @@ -23,53 +26,23 @@ class Puppet::Parser::Collector else #Puppet.info "Host %s is uninitialized" % @scope.host end - Puppet.info "collecting %s" % @type # Now look them up in the rails db. When we support attribute comparison # and such, we'll need to vary the conditions, but this works with no # attributes, anyway. time = Puppet::Util.thinmark do - Puppet::Rails::Resource.find_all_by_type_and_exported(@type, true, + Puppet::Rails::Resource.find_all_by_restype_and_exported(@type, true, args ).each do |obj| - if existing = @scope.findresource(obj.type, obj.title) - # See if we exported it; if so, just move on - if @scope.host == obj.host.name - next - else - # Next see if we've already collected this resource - if existing.rails_id == obj.id - # This is the one we've already collected - next - else - raise Puppet::ParseError, - "Exported resource %s[%s] cannot override local resource" % - [obj.type, obj.title] - end - end + if resource = export_resource(obj) + count += 1 + resources << resource end - count += 1 - begin - resource = obj.to_resource(self.scope) - - # XXX Because the scopes don't expect objects to return values, - # we have to manually add our objects to the scope. This is - # uber-lame. - scope.setresource(resource) - rescue => detail - if Puppet[:trace] - puts detail.backtrace - end - raise - end - resource.exported = false - - resources << resource end end - scope.debug("Collected %s %s resources in %.2f seconds" % - [count, @type, time]) + scope.debug("Collected %s %s resource%s in %.2f seconds" % + [count, @type, count == 1 ? "" : "s", time]) return resources end @@ -148,6 +121,42 @@ class Puppet::Parser::Collector return true end end + + def export_resource(obj) + if existing = @scope.findresource(obj.restype, obj.title) + # See if we exported it; if so, just move on + if @scope.host == obj.host.name + return nil + else + # Next see if we've already collected this resource + if existing.rails_id == obj.id + # This is the one we've already collected + return nil + else + raise Puppet::ParseError, + "Exported resource %s cannot override local resource" % + [obj.ref] + end + end + end + + begin + resource = obj.to_resource(self.scope) + + # XXX Because the scopes don't expect objects to return values, + # we have to manually add our objects to the scope. This is + # ber-lame. + scope.setresource(resource) + rescue => detail + if Puppet[:trace] + puts detail.backtrace + end + raise + end + resource.exported = false + + return resource + end end # $Id$ |
