summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-12-13 17:59:21 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-12-13 17:59:21 +0000
commitc35988aafbbbe3882ff1a5a7ff3ee472f77fb4c1 (patch)
tree1c403719ba7383efd2b9276381e4ecc8afff468f /lib
parentab604527648e91b84529c3fb83761b5e9b269b77 (diff)
downloadpuppet-c35988aafbbbe3882ff1a5a7ff3ee472f77fb4c1.tar.gz
puppet-c35988aafbbbe3882ff1a5a7ff3ee472f77fb4c1.tar.xz
puppet-c35988aafbbbe3882ff1a5a7ff3ee472f77fb4c1.zip
Another round of bug fixing. Now everything passes except mounts, at least on OS X.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1918 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/event.rb233
-rw-r--r--lib/puppet/metatype/manager.rb1
-rw-r--r--lib/puppet/provider/nameservice/netinfo.rb3
-rw-r--r--lib/puppet/type/state.rb2
4 files changed, 5 insertions, 234 deletions
diff --git a/lib/puppet/event.rb b/lib/puppet/event.rb
index 307c3540a..98ea92c9d 100644
--- a/lib/puppet/event.rb
+++ b/lib/puppet/event.rb
@@ -7,243 +7,10 @@ module Puppet
# eventually, these will be passed on to some central event system
class Event
include Puppet
-
- # subscriptions are permanent associations determining how different
- # objects react to an event
- class Subscription
- include Puppet
- attr_accessor :event, :callback
-
- # Remove the existing subscriptions and such
- def self.clear
- self.init
- end
-
- # Remove a subscription
- def self.delete(sub)
- type, name = sub.targetarray
- if @dependencies[type][name].include?(sub)
- @dependencies[type][name].delete(sub)
- end
-
- type, name = sub.sourcearray
- if @subscriptions[type][name].include?(sub)
- @subscriptions[type][name].delete(sub)
- end
- end
-
- # Initialize our class variables. This is in a method so it can
- # be called to clear the variables, too.
- def self.init
- # A hash of subscriptions and another of dependencies, organized by
- # type, then by name. I'm storing them all here, so that I don't
- # have to store the subscriptions with the individual objects,
- # which makes creating and destroying objects as necessary much
- # easier.
- @subscriptions = Hash.new { |hash, key|
- hash[key] = Hash.new { |shash, skey|
- # Each object has an array of subscriptions
- shash[skey] = []
- }
- }
-
- @dependencies = Hash.new { |hash, key|
- hash[key] = Hash.new { |shash, skey|
- # Each object has an array of subscriptions
- shash[skey] = []
- }
- }
- end
-
- self.init
-
- # Store the new subscription in a central hash.
- def self.newsub(sub)
- # The dependencies map allows me to look up a subscription by
- # target -- find out which objects a given object is subscribed
- # to, and thus find out which objects that given object depends
- # upon.
- # DEPENDENCIES == TARGET
- ttype, tname = sub.targetarray
- @dependencies[ttype][tname] << sub
-
- # Subscriptions are the list of subscriptions for a given object,
- # i.e., the list of all objects that care about a given object's
- # events.
- # SUBSCRIPTION == SOURCE
- stype, sname = sub.sourcearray
- @subscriptions[stype][sname] << sub
- end
-
- # Collect all of the subscriptions that target a specific event.
- def self.targets_of(event, source)
- type, name = self.split(source)
-
- @subscriptions[type][name].each { |sub|
- if sub.match?(event)
- yield sub
- end
- }
- end
-
- # Trigger the subscriptions related to an event, and then pass it up
- # as appropriate
- def self.trigger(source, event)
- type, name = self.split(source)
-
- @subscriptions[type][name].each { |sub|
- if sub.match?(event)
- yield sub
- #sub.trigger(transaction)
- end
- }
- end
-
- # Look up an object by type and name. This is used because we
- # store symbolic links in our subscription hash rather than storing
- # actual object references.
- def self.retrieve(ary)
- type, name = ary
- typeobj = Puppet::Type.type(type)
-
- unless typeobj
- return nil
- end
-
- obj = typeobj[name]
- return obj
- end
-
- # Split an object into its type and name
- def self.split(object)
- return [object.class.name, object.title]
- end
-
- # Retrieve all of the subscriptions that result in a dependency.
- # We return the whole dependency here, because it is being returned
- # to the object that made the subscription.
- def self.dependencies(target)
- type, name = self.split(target)
- return @dependencies[type][name]
- end
-
- # Return all objects that are subscribed to us. We are only willing
- # to return the object, not the subscription object, because the
- # source shouldn't need to know things like the event or method that
- # we're subscribed to.
- def self.subscribers(source)
- type, name = self.split(source)
- return @subscriptions[type][name].collect { |sub|
- sub.target
- }.reject { |o|
- o.nil?
- }
- end
-
- def delete
- self.class.delete(self)
- end
-
- # The hash here must include the target and source objects, the event,
- # and the callback to call.
- def initialize(hash)
- hash.each { |param,value|
- # assign each value appropriately
- # this is probably wicked-slow
- self.send(param.to_s + "=",value)
- }
-
- self.class.newsub(self)
- #Puppet.debug "New Subscription: '%s' => '%s'" %
- # [@source,@event]
- end
-
- # Determine whether the passed event matches our event
- def match?(event)
- if event == :NONE or @event == :NONE
- return false
- elsif @event == :ALL_EVENTS or event == :ALL_EVENTS or event == @event
- return true
- else
- return false
- end
- end
-
- # The source is the event source.
- def source=(object)
- type, name = self.class.split(object)
- @source = [type, name]
- end
-
- def source
- if source = self.class.retrieve(@source)
- return source
- else
- raise Puppet::Error,
- "Could not retrieve dependency %s[%s] for %s[%s]" %
- [@source[0], @source[1], @target[0], @target[1]]
- end
- end
-
- def sourcearray
- @source
- end
-
- # The target is the object who will receive the callbacks, i.e.,
- # a source generates an event, which results in a callback on the
- # target.
- def target=(object)
- type, name = self.class.split(object)
- @target = [type, name]
- end
-
- def target
- self.class.retrieve(@target)
- end
-
- def targetarray
- @target
- end
-
- # Trigger a subscription, which basically calls the associated method
- # on the target object. XXX This is currently unused.
- def trigger(transaction)
- event = nil
-
- if @event == :NONE
- # just ignore these subscriptions
- return
- end
-
- if transaction.triggered?(self.target, @callback) > 0
- self.target.info "already applied %s" % [@callback]
- else
- # We need to call the method, so that it gets retrieved
- # as a real object.
- target = self.target
- #Puppet.debug "'%s' matched '%s'; triggering '%s' on '%s'" %
- # [@source,@event,@method,target]
- if target.respond_to?(@callback)
- target.log "triggering %s" % @callback
- event = target.send(@callback)
- else
- Puppet.debug(
- "'%s' of type '%s' does not respond to '%s'" %
- [target,target.class,@callback.inspect]
- )
- end
- transaction.triggered(target, @callback)
- end
- return event
- end
- end
-
attr_accessor :event, :source, :transaction
@@events = []
- @@subscriptions = []
-
def initialize(args)
unless args.include?(:event) and args.include?(:source)
raise Puppet::DevError, "Event.new called incorrectly"
diff --git a/lib/puppet/metatype/manager.rb b/lib/puppet/metatype/manager.rb
index bad41570a..53cb5951d 100644
--- a/lib/puppet/metatype/manager.rb
+++ b/lib/puppet/metatype/manager.rb
@@ -9,7 +9,6 @@ module Manager
# remove all type instances; this is mostly only useful for testing
def allclear
- Puppet::Event::Subscription.clear
@types.each { |name, type|
type.clear
}
diff --git a/lib/puppet/provider/nameservice/netinfo.rb b/lib/puppet/provider/nameservice/netinfo.rb
index 879bb7757..313b41753 100644
--- a/lib/puppet/provider/nameservice/netinfo.rb
+++ b/lib/puppet/provider/nameservice/netinfo.rb
@@ -168,6 +168,9 @@ class NetInfo < Puppet::Provider::NameService
def modifycmd(param, value)
cmd = [command(:niutil)]
+ # if value.is_a?(Array)
+ # warning "Netinfo providers cannot currently handle multiple values"
+ # end
cmd << "-createprop" << "/" << "/%s/%s" %
[self.class.netinfodir, @model[:name]]
diff --git a/lib/puppet/type/state.rb b/lib/puppet/type/state.rb
index 6dd5f1567..24dec6903 100644
--- a/lib/puppet/type/state.rb
+++ b/lib/puppet/type/state.rb
@@ -461,6 +461,7 @@ class State < Puppet::Parameter
else
@parent.create
end
+ nil # return nil so the event is autogenerated
end
newvalue(:absent) do
@@ -469,6 +470,7 @@ class State < Puppet::Parameter
else
@parent.destroy
end
+ nil # return nil so the event is autogenerated
end
defaultto do