Help: instantiating parsedfile in another type ( help with populating the record object )

3 views
Skip to first unread message

Manish Chakravarty

unread,
May 16, 2009, 10:30:17 AM5/16/09
to puppe...@googlegroups.com
Hello,

I want to instantiate parsedfile in a provider that I am writing [1] and then use that instance to manage my config file.
I cannot inherit from parsedfile as I am already inheriting from base.rb


I want to write a method like 
    def write_something_to_file
       # use parsedfile here to do the actual writing

To investigate further, I decided to run instantiate a parsedfile object in irb:

Here's the trace:
manish@freedom ~ % irb
>> require 'Puppet'
/Library/Ruby/Site/1.8/Puppet.rb:28: warning: already initialized constant PUPPETVERSION
=> true
>> require 'Puppet/Provider'
=> []
>> require 'Puppet/Provider/ParsedFile'
=> []
>> pf = Puppet::Provider::ParsedFile.new
ArgumentError: wrong number of arguments (0 for 1)
from (irb):7:in `initialize'
from (irb):7:in `new'
from (irb):7
>> pf = Puppet::Provider::ParsedFile.new(record)
(record)

The "initialize" method in parsedfile.rb says:
    def initialize(record)
        super
<snipped documentation>
        if @property_hash.empty?
            @property_hash = self.class.record?(resource[:name]) || {:record_type => self.class.name, :ensure => :absent}
        end
    end

Can someone please guide me as to how to populate the property hash and record objects so that I can play around with parsedfile ?








Luke Kanies

unread,
May 18, 2009, 11:05:10 AM5/18/09
to puppe...@googlegroups.com
On May 16, 2009, at 9:30 AM, Manish Chakravarty wrote:

> Hello,
>
> I want to instantiate parsedfile in a provider that I am writing [1]
> and then use that instance to manage my config file.
> I cannot inherit from parsedfile as I am already inheriting from
> base.rb

I think I mentioned that this probably isn't the right answer, but
I'll help you continue with your experiment and see where it gets you.
I *do* recommend you look at resource generation over this, though.


ParsedFile instances (and maybe all providers?) require either a
resource instance or a hash at initialization. If you provide a hash,
then this is considered to be the current state of the resource on
disk. You still need to use the settors to change the state.

This is a bit the flaw of using a provider directly - you have to
handle the transactional bits yourself.

--
Ours is the age that is proud of machines that think and suspicious of
men who try to. -- H. Mumford Jones
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com

Reply all
Reply to author
Forward
0 new messages