Hi Thomas, many thanks for pointing me to the documentation with the updates. Your proposed code is exactly what I am looking for.
I really like Puppet 4 Functions!! Best, Martin On 01 Sep 2015, at 14:33, Thomas Hallgren <[email protected]> wrote: > A correction to my last reply. You must use Pattern, not Regexp (a Regexp is > for regexp instances whereas a Pattern matches strings). > > - thomas > > > On 2015-09-01 14:28, Thomas Hallgren wrote: >> On 2015-09-01 13:27, Martin Alfke wrote: >>> Hi Thomas, >>> On 01 Sep 2015, at 09:59, Thomas Hallgren >>> <[email protected]> >>> wrote: >>> >>> >>>> Hi Martin, >>>> >>>> The function API has evolved slightly since the blog entry that you're >>>> referring to was written. The arg_count was removed since it was redundant >>>> and confusing after we introduced the 'optional_param' and >>>> 'repeated_param'. You can find the documentation for Puppet 4.2 functions >>>> here: >>>> >>>> >>>> https://docs.puppetlabs.com/references/4.2.latest/developer/Puppet/Functions.html >>> Many thanks for pointing to the new updated documentation. >>> >>> My idea is to create a functions which has 3 use cases: >>> - no parameter: return hostname of puppet master >>> - ip as parameter: return DNS resolved name >>> - hostname/fqdn as parameter: return IP address from DNS >>> >>> How to check for explizit “no parameter”? >>> >> Create two dispatch entries. One that require a parameter and one where no >> parameter is declared. The one without a parameter will be used when no >> argument is given. In this scenario, the check for ip or hostname must be >> done in the method targeted by the dispatch with one parameter. >> >> Alternatively, you could use three dispatch entries. One without a parameter >> (as before) and then two with parameters using mutually exclusive regular >> expression types. One matching the IP and another matching hostname/fdqn. >> Something like this: >> >> dispatch :no_param do >> end >> >> dispatch :ip_param do >> param 'Regexp[/^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/]', :ip >> end >> >> dispatch :fqdn_param do >> param 'Regexp[/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/]', fdqn >> end >> >> def no_param >> return puppet master hostname >> def >> >> def ip_param(ip) >> ... >> end >> >> def fqdn_param(ip) >> ... >> end >> >> - thomas >> >> >> - thomas >> > > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Developers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/puppet-dev/55E59B25.7030604%40puppetlabs.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/81C3FA66-415A-4BC3-A6C0-DEFC2C5D3692%40gmail.com. For more options, visit https://groups.google.com/d/optout.
