On Jan 10, 2011, at 10:02 AM, Peter Meier wrote:

> Hi
> 
> so I found one issue while using the code a bit more in production:
> 
>> +  def unexport(node)
>> +    # fetch all exported resource
>> +    query = {:include => {:param_values => :param_name}}
>> +    query[:conditions] = ["exported=? AND host_id=?", true, node.id]
>> +
>> +    Puppet::Rails::Resource.find(:all, query).each do |resource|
> 
> While this:
> 
>> +      if 
>> Puppet::Type.type(resource.restype.downcase.to_sym).validattr?(:ensure)
> 
> works fine for exported types, it won't work for exported defines. As a
> define won't be found by Puppet::Type.type. Looking at the code it looks
> to me as exported defines are usually found via the current scope in the
> catalog. Hence, as during catalog compilation there is already some sort
> of autoloading around which will also load the define if it exists.
> 
> I'm unsure how to do that in the clean app. Any hints how I could get
> the same autoload behavior as one has within the catalog to get it
> outside of any scope etc. working?

Without going into the full context of what you're doing, the answer to your 
final question is pretty straightforward.

The whole compile process has a list of known resource types (which includes 
nodes, classes, and definitions), available via Environment:

Puppet::Node::Environment.new.known_resource_types.hostclasses

Scopes just give you a search path for unqualified types/etc, which you won't 
need in your case.  So, you can just ask for the type directly.

Note that each type (node, definition, hostclass) has multiple methods:

hostclass(name) # finds an existing class
find_hostclass(name) # loads a class into memory if it's not there
hostclasses # return all known hostclasses. or maybe just names?

There are similar methods for the other types.  You can look through 
lib/puppet/resource/type_collection.rb for the available methods (an instance 
of this is what's available at Environment.new.known_resource_types.

-- 
I don't deserve this award, but I have arthritis and I don't deserve
that either.    -- Jack Benny
---------------------------------------------------------------------
Luke Kanies  -|-   http://puppetlabs.com   -|-   +1(615)594-8199




-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to