hi! I''ve seen it reported that there is no official doc for parsedfile; does anyone know if this is still true? I''m trying to make a new type and getting stuck on how parsedfile works . . . Any help would be appreciated: regarding the "Puppet::Type.type(:newType).provide" line: 1. What does the ":parsed" label do? Are there other options? 2. Are there other types of ":filetypes" besides ":flat"? Does labeling as :flat have any affect on the parsing? regarding "record_line": 1. can the "name" parameter be anything? is ":parsed" anything special? Is the name used for anything? 2. what exactly do the parenthetic groupings do, e.g. /^\s+(.*)=(.*):$/ ? 3. Is there a relationship between the parenthetic groupings and the ":fields" label? 4. what is the relationship between :fields in provider, "newparams" in type & fields in manifest/init.pp? 4a. Why do i get the following error when I don''t have stuff_1 as ":optional": Could not evaluate: Field ''stuff_1'' is required 5. What does :post_parse do? 6 What does :pre_gen do? 7 Are there any other "mystery" parameter? Thanks soooooooo much!! Guy -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On 12/10/11 19:12, Guy Matz wrote:> hi! > I''ve seen it reported that there is no official doc for parsedfile; does > anyone know if this is still true? > > I''m trying to make a new type and getting stuck on how parsedfile works > . . . Any help would be appreciated: > > regarding the "Puppet::Type.type(:newType).provide" line: > 1. What does the ":parsed" label do? Are there other options?It''s the provider name. I don''t think it really matters, except that there can''t be two provider of the same name for a given puppet type.> 2. Are there other types of ":filetypes" besides ":flat"? Does labeling > as :flat have any affect on the parsing?It looks like there''s a handful of variations of crontab formats. Use :flat.> regarding "record_line": > 1. can the "name" parameter be anything? is ":parsed" anything > special? Is the name used for anything?I believe it can be anything. I think the name is used if you ever want to look up for a given record_line.> 2. what exactly do the parenthetic groupings do, e.g. /^\s+(.*)=(.*):$/ ?It''s a regex capture.> 3. Is there a relationship between the parenthetic groupings and the > ":fields" label?Yes. I think the first capture will end up in the first ''field'' and so on for the subsequent capture/field.> 4. what is the relationship between :fields in provider, "newparams" in > type & fields in manifest/init.pp?The role of a given provider is to fill in resource properties and later on, commit updated properties to the target "physical" resource. So, yes you need a field per newproperty in the type.> 4a. Why do i get the following error when I don''t have stuff_1 as > ":optional": Could not evaluate: Field ''stuff_1'' is requiredWe need to see the code to help with specific errors.> 5. What does :post_parse do?It allows to run some specific code after the parsing of a given record line happens. It allows to modify was what read, or munge some values...> 6 What does :pre_gen do?It allows to run provider specific code before the to_line operation happens.> 7 Are there any other "mystery" parameter?There''s at least process, if you want to use your own parsing instead of relying on the regex. And there is a bunch of options to modify how the parsing happens. Check for more information: Puppet::Util::FileParsing and Puppet::Provider::ParsedFile Hope that will help you :) -- Brice Figureau My Blog: http://www.masterzen.fr/ -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Thanks for the reply!! One more thing I can''t quite figure out: How to get a new entry in my target file! I can parse, but an entry in manifests doesn''t magically appear. Do I need to add something to my provider or type to get that to happen? Any help would be soooo appreciated; i''m getting tired of struggling with this! vncserver/manifests/init.pp class vncserver { vncserver { ''guymatz'': port => ''92'', geometry => ''1024x768'', ensure => ''present'' } } # class vncserver vncserver/lib/puppet/type/vncserver.rb require ''puppet/property/list'' require ''puppet/provider/parsedfile'' Puppet::Type.newtype(:vncserver) do ensurable newparam(:port) do desc "The vnc servers port assignment. Will be +5900 on the server" end newparam(:name) do isnamevar desc "The user who will own the VNC session." end newparam(:geometry) do desc "Resolution for VNC, in XxY, e.g. 1024x768." end newparam(:password) do desc "Password to be put into users .vnc/passwd." end newparam(:args) do desc "Optional arguments to be added to the vncserver command-line." end @doc = "Installs and manages entries for vncservers. For Redhat-bases systems, and likely many others, these entries will be in /etc/sysconfig/vncservers." end and, finally, my very unfinished provider: vncserver/lib/puppet/provider/vncserver/parsed.rb: require ''puppet/provider/parsedfile'' vncservers = "/etc/sysconfig/vncservers" Puppet::Type.type(:vncserver).provide(:parsed, :parent => Puppet::Provider::ParsedFile, :default_target => vncservers, :filetype => :flat ) do desc "The vncserver provider that uses the ParsedFile class" confine :exists => vncservers text_line :comment, :match => /^\s*#/; text_line :blank, :match => /^\s*$/; record_line :parsed, :joiner => '''', :fields => %w{port geometry optional_args}, :optional => %w{port geometry }, :match => /^VNCSERVERARGS\[(\d+)\]="-geometry (\d+x\d+)(.*)$/, :to_line => proc { |record| "VNCSERVERARGS[#{record[:port]}]=\"-geometry #{record[:geometry]} #{record[:optional_args]}\"" } record_line :parsed_again, :joiner => '''', :fields => %w{port_name}, :optional => %w{port_name}, :match => /^VNCSERVERS="(.*)"$/, :to_line => proc { |record| "VNCSERVERS=\"#{record[:port_name]}\"" } end -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Unfortunately, the parsedfile provider is mainly documented by code that uses it. I''ve been meaning to write up a document on it, but I''ve been unable to find the time. In the mean time, the OSUOSL has some providers for gentoo that use the parsedfile provider, found at https://github.com/ramereth/puppet-gentoo/blob/master/lib/puppet/provider/package_use/parsed.rb that may give you a bit more insight. Sorry for the non-answer here, but this might get you a bit further along. On Thu, Oct 13, 2011 at 2:47 PM, Guy Matz <gmatz@matz.org> wrote:> Thanks for the reply!! One more thing I can''t quite figure out: How to get > a new entry in my target file! I can parse, but an entry in manifests > doesn''t magically appear. Do I need to add something to my provider or type > to get that to happen? Any help would be soooo appreciated; i''m getting > tired of struggling with this! > > vncserver/manifests/init.pp > class vncserver { > vncserver { ''guymatz'': > port => ''92'', > geometry => ''1024x768'', > ensure => ''present'' > } > } # class vncserver > > > vncserver/lib/puppet/type/vncserver.rb > require ''puppet/property/list'' > require ''puppet/provider/parsedfile'' > > Puppet::Type.newtype(:vncserver) do > > ensurable > > newparam(:port) do > desc "The vnc servers port assignment. Will be +5900 on the server" > end > > newparam(:name) do > isnamevar > desc "The user who will own the VNC session." > end > > newparam(:geometry) do > desc "Resolution for VNC, in XxY, e.g. 1024x768." > end > > newparam(:password) do > desc "Password to be put into users .vnc/passwd." > end > > newparam(:args) do > desc "Optional arguments to be added to the vncserver command-line." > end > > @doc = "Installs and manages entries for vncservers. For Redhat-bases > systems, and likely many others, these entries will be in > /etc/sysconfig/vncservers." > > end > > > and, finally, my very unfinished provider: > vncserver/lib/puppet/provider/vncserver/parsed.rb: > require ''puppet/provider/parsedfile'' > > vncservers = "/etc/sysconfig/vncservers" > > Puppet::Type.type(:vncserver).provide(:parsed, > :parent => > Puppet::Provider::ParsedFile, > :default_target => vncservers, > :filetype => :flat > ) do > desc "The vncserver provider that uses the ParsedFile class" > confine :exists => vncservers > text_line :comment, :match => /^\s*#/; > text_line :blank, :match => /^\s*$/; > > record_line :parsed, > :joiner => '''', > :fields => %w{port geometry optional_args}, > :optional => %w{port geometry }, > :match => /^VNCSERVERARGS\[(\d+)\]="-geometry (\d+x\d+)(.*)$/, > :to_line => proc { |record| > "VNCSERVERARGS[#{record[:port]}]=\"-geometry > #{record[:geometry]} #{record[:optional_args]}\"" > } > > record_line :parsed_again, > :joiner => '''', > :fields => %w{port_name}, > :optional => %w{port_name}, > :match => /^VNCSERVERS="(.*)"$/, > :to_line => proc { |record| > "VNCSERVERS=\"#{record[:port_name]}\"" > } > end > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Hi, On Thu, 2011-10-13 at 17:47 -0400, Guy Matz wrote:> Thanks for the reply!! One more thing I can''t quite figure out: How > to get a new entry in my target file! I can parse, but an entry in > manifests doesn''t magically appear. Do I need to add something to my > provider or type to get that to happen? Any help would be soooo > appreciated; i''m getting tired of struggling with this! > > vncserver/manifests/init.pp > class vncserver { > vncserver { ''guymatz'': > port => ''92'', > geometry => ''1024x768'', > ensure => ''present''Those are properties: you want to manage them.> } > } # class vncserver > > > vncserver/lib/puppet/type/vncserver.rb > require ''puppet/property/list'' > require ''puppet/provider/parsedfile'' > > Puppet::Type.newtype(:vncserver) do > > ensurable > > newparam(:port) do > desc "The vnc servers port assignment. Will be +5900 on the > server" > end > > newparam(:name) do > isnamevar > desc "The user who will own the VNC session." > end > > newparam(:geometry) do > desc "Resolution for VNC, in XxY, e.g. 1024x768." > end > > newparam(:password) do > desc "Password to be put into users .vnc/passwd." > end > > newparam(:args) do > desc "Optional arguments to be added to the vncserver > command-line." > endBut you defined them as parameters. Use newproperty instead of newparam.> @doc = "Installs and manages entries for vncservers. For > Redhat-bases > systems, and likely many others, these entries will be in > /etc/sysconfig/vncservers." > > end > > > and, finally, my very unfinished provider: > vncserver/lib/puppet/provider/vncserver/parsed.rb: > require ''puppet/provider/parsedfile'' > > vncservers = "/etc/sysconfig/vncservers" > > Puppet::Type.type(:vncserver).provide(:parsed, > :parent => > Puppet::Provider::ParsedFile, > :default_target => vncservers, > :filetype => :flat > ) do > desc "The vncserver provider that uses the ParsedFile class" > confine :exists => vncservers > text_line :comment, :match => /^\s*#/; > text_line :blank, :match => /^\s*$/; > > record_line :parsed, > :joiner => '''', > :fields => %w{port geometry optional_args}, > :optional => %w{port geometry }, > :match => /^VNCSERVERARGS\[(\d+)\]="-geometry (\d+x\d > +)(.*)$/, > :to_line => proc { |record| > "VNCSERVERARGS[#{record[:port]}]=\"-geometry > #{record[:geometry]} #{record[:optional_args]}\"" > } > > record_line :parsed_again, > :joiner => '''', > :fields => %w{port_name}, > :optional => %w{port_name}, > :match => /^VNCSERVERS="(.*)"$/, > :to_line => proc { |record| > "VNCSERVERS=\"#{record[:port_name]}\"" > } > endAlso, you don''t have any property in the type for port_name. -- Brice Figureau Follow the latest Puppet Community evolutions on www.planetpuppet.org! -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Thanks! That begs the question: What''s the difference between newparam & newproperty? One other thing: Does anyone know why I would get the following error after switching from newparam to newproperty? err: Could not retrieve catalog from remote server: Could not intern from pson: undefined method `merge'' for []:Array Thanks again, Guy On Fri, Oct 14, 2011 at 4:31 AM, Brice Figureau < brice-puppet@daysofwonder.com> wrote:> Hi, > > On Thu, 2011-10-13 at 17:47 -0400, Guy Matz wrote: > > Thanks for the reply!! One more thing I can''t quite figure out: How > > to get a new entry in my target file! I can parse, but an entry in > > manifests doesn''t magically appear. Do I need to add something to my > > provider or type to get that to happen? Any help would be soooo > > appreciated; i''m getting tired of struggling with this! > > > > vncserver/manifests/init.pp > > class vncserver { > > vncserver { ''guymatz'': > > port => ''92'', > > geometry => ''1024x768'', > > ensure => ''present'' > > Those are properties: you want to manage them. > > > } > > } # class vncserver > > > > > > vncserver/lib/puppet/type/vncserver.rb > > require ''puppet/property/list'' > > require ''puppet/provider/parsedfile'' > > > > Puppet::Type.newtype(:vncserver) do > > > > ensurable > > > > newparam(:port) do > > desc "The vnc servers port assignment. Will be +5900 on the > > server" > > end > > > > newparam(:name) do > > isnamevar > > desc "The user who will own the VNC session." > > end > > > > newparam(:geometry) do > > desc "Resolution for VNC, in XxY, e.g. 1024x768." > > end > > > > newparam(:password) do > > desc "Password to be put into users .vnc/passwd." > > end > > > > newparam(:args) do > > desc "Optional arguments to be added to the vncserver > > command-line." > > end > > But you defined them as parameters. > Use newproperty instead of newparam. > > > @doc = "Installs and manages entries for vncservers. For > > Redhat-bases > > systems, and likely many others, these entries will be in > > /etc/sysconfig/vncservers." > > > > end > > > > > > and, finally, my very unfinished provider: > > vncserver/lib/puppet/provider/vncserver/parsed.rb: > > require ''puppet/provider/parsedfile'' > > > > vncservers = "/etc/sysconfig/vncservers" > > > > Puppet::Type.type(:vncserver).provide(:parsed, > > :parent => > > Puppet::Provider::ParsedFile, > > :default_target => vncservers, > > :filetype => :flat > > ) do > > desc "The vncserver provider that uses the ParsedFile class" > > confine :exists => vncservers > > text_line :comment, :match => /^\s*#/; > > text_line :blank, :match => /^\s*$/; > > > > record_line :parsed, > > :joiner => '''', > > :fields => %w{port geometry optional_args}, > > :optional => %w{port geometry }, > > :match => /^VNCSERVERARGS\[(\d+)\]="-geometry (\d+x\d > > +)(.*)$/, > > :to_line => proc { |record| > > "VNCSERVERARGS[#{record[:port]}]=\"-geometry > > #{record[:geometry]} #{record[:optional_args]}\"" > > } > > > > record_line :parsed_again, > > :joiner => '''', > > :fields => %w{port_name}, > > :optional => %w{port_name}, > > :match => /^VNCSERVERS="(.*)"$/, > > :to_line => proc { |record| > > "VNCSERVERS=\"#{record[:port_name]}\"" > > } > > end > > Also, you don''t have any property in the type for port_name. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.