I''ve almost finished a pretty simple type/provider to manage
RabbitMQ users and virtual hosts.
I''m using the ''ensurable'' keyword in my type to save
a bit of boilerplate.
Type is below (the provider is just a wrapper around the
''rabbitmqctl''
command.
Have a feeling there''s a developer guide somewhere I haven''t
found
(been working from the puppetlabs site and @kartars blog).
Couple of basic questions:
1. how can I set the type to default to ''ensure => present, isadmin
=>
false'' ?
Not sure if the ensurable mechanism is causing the first to be hard,
but I can''t see a way to set defaults in general
2. is there a way to mark attributes as required?
I''ve provided a validation for the initial_password parameter, but it
only
seems to fire if the parameter is there;
it doesn''t get checked if the parameter is absent.
======================================================# cat
lib/puppet/type/rabbitmq_user.rb
Puppet::Type.newtype(:rabbitmq_user) do
@doc = "Manage RabbitMQ users"
ensurable
newparam(:name) do
desc "The name of the user"
validate do |n|
raise ArgumentError, "cannot be empty" if n.empty?
raise ArgumentError, "can''t contain spaces" if ( n =~
%r(\s+) )
resource[:provider] = :rabbitmq_user
end
isnamevar
end
newparam(:initial_password) do
desc "the password for the user - only set on creation time"
validate do |n|
raise ArgumentError, "cannot be empty" if (n.empty? or n.nil?)
resource[:provider] = :rabbitmq_user
end
end
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.
On Fri, Jan 21, 2011 at 8:31 AM, Dick Davies <rasputnik@hellooperator.net>wrote:> I''ve almost finished a pretty simple type/provider to manage > RabbitMQ users and virtual hosts. > I''m using the ''ensurable'' keyword in my type to save a bit of boilerplate. > > Type is below (the provider is just a wrapper around the ''rabbitmqctl'' > command. > > Have a feeling there''s a developer guide somewhere I haven''t found > (been working from the puppetlabs site and @kartars blog). > Couple of basic questions: > > 1. how can I set the type to default to ''ensure => present, isadmin => > false'' ? > Not sure if the ensurable mechanism is causing the first to be hard, > but I can''t see a way to set defaults in general >you can call the defaultto method in the param/property.> 2. is there a way to mark attributes as required? >unfortunately not in the param/property blocks, there is supposed to be a method called isrequired,but it does not work. You can do this with the validate method on the type> I''ve provided a validation for the initial_password parameter, but it only > seems to fire if the parameter is there; > it doesn''t get checked if the parameter is absent. > > >> ======================================================> # cat lib/puppet/type/rabbitmq_user.rb > Puppet::Type.newtype(:rabbitmq_user) do > @doc = "Manage RabbitMQ users" > > ensurable > > newparam(:name) do > desc "The name of the user" > > validate do |n| > raise ArgumentError, "cannot be empty" if n.empty? > raise ArgumentError, "can''t contain spaces" if ( n =~ %r(\s+) ) > resource[:provider] = :rabbitmq_user > end > > isnamevar > end > > newparam(:initial_password) do > desc "the password for the user - only set on creation time" > > defaultto ''foo''> validate do |n| > raise ArgumentError, "cannot be empty" if (n.empty? or n.nil?) > resource[:provider] = :rabbitmq_user > end > end >validate do raise ArgumentError "initial_password is a required param" unless self[:initial_password] end> 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<puppet-users%2Bunsubscribe@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.
Thanks for point 2, much appreciated. Is the ''global'' validate
option documented anywhere?
on point 1, using the ''ensurable'' magic means I don''t
have anywhere
to stick the defaultto keyword (I tried
ensurable do
defaultto ''present''
end
but didn''t seem to do the trick (blows up with a
"change from present to present failed: The rabbitmq_user provider can not
handle attribute ensure" . Am I out of luck without an
explicit newparam{} block to work in?
On Fri, Jan 21, 2011 at 4:40 PM, Dan Bode <dan@puppetlabs.com> wrote:
>
>
> On Fri, Jan 21, 2011 at 8:31 AM, Dick Davies
<rasputnik@hellooperator.net>wrote:
>
>> I''ve almost finished a pretty simple type/provider to manage
>> RabbitMQ users and virtual hosts.
>> I''m using the ''ensurable'' keyword in my type
to save a bit of boilerplate.
>>
>> Type is below (the provider is just a wrapper around the
''rabbitmqctl''
>> command.
>>
>> Have a feeling there''s a developer guide somewhere I
haven''t found
>> (been working from the puppetlabs site and @kartars blog).
>> Couple of basic questions:
>>
>> 1. how can I set the type to default to ''ensure => present,
isadmin =>
>> false'' ?
>> Not sure if the ensurable mechanism is causing the first to be
hard,
>> but I can''t see a way to set defaults in general
>>
>
> you can call the defaultto method in the param/property.
>
>
>> 2. is there a way to mark attributes as required?
>>
>
> unfortunately not in the param/property blocks, there is supposed to be a
> method called isrequired,but it does not work. You can do this with the
> validate method on the type
>
>
>
>> I''ve provided a validation for the initial_password parameter,
but it only
>> seems to fire if the parameter is there;
>> it doesn''t get checked if the parameter is absent.
>>
>>
>>
>
>> ======================================================>> # cat
lib/puppet/type/rabbitmq_user.rb
>> Puppet::Type.newtype(:rabbitmq_user) do
>> @doc = "Manage RabbitMQ users"
>>
>> ensurable
>>
>> newparam(:name) do
>> desc "The name of the user"
>>
>> validate do |n|
>> raise ArgumentError, "cannot be empty" if n.empty?
>> raise ArgumentError, "can''t contain spaces" if
( n =~ %r(\s+) )
>> resource[:provider] = :rabbitmq_user
>> end
>>
>> isnamevar
>> end
>>
>> newparam(:initial_password) do
>> desc "the password for the user - only set on creation
time"
>>
>> defaultto ''foo''
>
>
>> validate do |n|
>> raise ArgumentError, "cannot be empty" if (n.empty? or
n.nil?)
>> resource[:provider] = :rabbitmq_user
>> end
>> end
>>
>
> validate do
> raise ArgumentError "initial_password is a required
param" unless
> self[:initial_password]
> end
>
>> 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<puppet-users%2Bunsubscribe@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<puppet-users%2Bunsubscribe@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.
On Fri, Jan 21, 2011 at 11:13 AM, Dick Davies <rasputnik@hellooperator.net>wrote:> Thanks for point 2, much appreciated. Is the ''global'' validate > option documented anywhere? >ummm.. maybe.> on point 1, using the ''ensurable'' magic means I don''t have anywhere > to stick the defaultto keyword (I tried > > ensurable do > defaultto ''present'' > end > >> but didn''t seem to do the trick (blows up with a > "change from present to present failed: The rabbitmq_user provider can not > handle attribute ensure" . Am I out of luck without an > explicit newparam{} block to work in? > > On Fri, Jan 21, 2011 at 4:40 PM, Dan Bode <dan@puppetlabs.com> wrote: > >> >> >> On Fri, Jan 21, 2011 at 8:31 AM, Dick Davies <rasputnik@hellooperator.net >> > wrote: >> >>> I''ve almost finished a pretty simple type/provider to manage >>> RabbitMQ users and virtual hosts. >>> I''m using the ''ensurable'' keyword in my type to save a bit of >>> boilerplate. >>> >>> Type is below (the provider is just a wrapper around the ''rabbitmqctl'' >>> command. >>> >>> Have a feeling there''s a developer guide somewhere I haven''t found >>> (been working from the puppetlabs site and @kartars blog). >>> Couple of basic questions: >>> >>> 1. how can I set the type to default to ''ensure => present, isadmin => >>> false'' ? >>> Not sure if the ensurable mechanism is causing the first to be hard, >>> but I can''t see a way to set defaults in general >>> >> >> you can call the defaultto method in the param/property. >> >> >>> 2. is there a way to mark attributes as required? >>> >> >> unfortunately not in the param/property blocks, there is supposed to be a >> method called isrequired,but it does not work. You can do this with the >> validate method on the type >> >> >> >>> I''ve provided a validation for the initial_password parameter, but it >>> only seems to fire if the parameter is there; >>> it doesn''t get checked if the parameter is absent. >>> >>> >>> >> >>> ======================================================>>> # cat lib/puppet/type/rabbitmq_user.rb >>> Puppet::Type.newtype(:rabbitmq_user) do >>> @doc = "Manage RabbitMQ users" >>> >>> ensurable >>> >>> newparam(:name) do >>> desc "The name of the user" >>> >>> validate do |n| >>> raise ArgumentError, "cannot be empty" if n.empty? >>> raise ArgumentError, "can''t contain spaces" if ( n =~ %r(\s+) ) >>> resource[:provider] = :rabbitmq_user >>> end >>> >>> isnamevar >>> end >>> >>> newparam(:initial_password) do >>> desc "the password for the user - only set on creation time" >>> >>> defaultto ''foo'' >> >> >>> validate do |n| >>> raise ArgumentError, "cannot be empty" if (n.empty? or n.nil?) >>> resource[:provider] = :rabbitmq_user >>> end >>> end >>> >> >> validate do >> raise ArgumentError "initial_password is a required param" unless >> self[:initial_password] >> end >> >>> 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<puppet-users%2Bunsubscribe@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<puppet-users%2Bunsubscribe@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<puppet-users%2Bunsubscribe@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.
When you look into puppet source type.rb, ensurable accept a block. If
you pass a block like this
ensurable do
[...]
end
it is exactly the same as if you''d written
newproperty(:ensure, :parent => Puppet::Property::Ensure) do
[...]
end
If you do not pass a block puppet will fill it with one methodcall:
defaultvalues. You can now look into property/ensure.rb what this
actually means. It defines two accepted values :present and :absent
and the default will be :present.
-Stefan
On Fri, Jan 21, 2011 at 07:13:50PM +0000, Dick Davies
wrote:> Thanks for point 2, much appreciated. Is the ''global''
validate
> option documented anywhere?
>
> on point 1, using the ''ensurable'' magic means I
don''t have anywhere
> to stick the defaultto keyword (I tried
>
> ensurable do
> defaultto ''present''
> end
>
> but didn''t seem to do the trick (blows up with a
> "change from present to present failed: The rabbitmq_user provider can
not
> handle attribute ensure" . Am I out of luck without an
> explicit newparam{} block to work in?
>
> On Fri, Jan 21, 2011 at 4:40 PM, Dan Bode <dan@puppetlabs.com> wrote:
>
> >
> >
> > On Fri, Jan 21, 2011 at 8:31 AM, Dick Davies
<rasputnik@hellooperator.net>wrote:
> >
> >> I''ve almost finished a pretty simple type/provider to
manage
> >> RabbitMQ users and virtual hosts.
> >> I''m using the ''ensurable'' keyword in my
type to save a bit of boilerplate.
> >>
> >> Type is below (the provider is just a wrapper around the
''rabbitmqctl''
> >> command.
> >>
> >> Have a feeling there''s a developer guide somewhere I
haven''t found
> >> (been working from the puppetlabs site and @kartars blog).
> >> Couple of basic questions:
> >>
> >> 1. how can I set the type to default to ''ensure =>
present, isadmin =>
> >> false'' ?
> >> Not sure if the ensurable mechanism is causing the first to be
hard,
> >> but I can''t see a way to set defaults in general
> >>
> >
> > you can call the defaultto method in the param/property.
> >
> >
> >> 2. is there a way to mark attributes as required?
> >>
> >
> > unfortunately not in the param/property blocks, there is supposed to
be a
> > method called isrequired,but it does not work. You can do this with
the
> > validate method on the type
> >
> >
> >
> >> I''ve provided a validation for the initial_password
parameter, but it only
> >> seems to fire if the parameter is there;
> >> it doesn''t get checked if the parameter is absent.
> >>
> >>
> >>
> >
> >> ======================================================>
>> # cat lib/puppet/type/rabbitmq_user.rb
> >> Puppet::Type.newtype(:rabbitmq_user) do
> >> @doc = "Manage RabbitMQ users"
> >>
> >> ensurable
> >>
> >> newparam(:name) do
> >> desc "The name of the user"
> >>
> >> validate do |n|
> >> raise ArgumentError, "cannot be empty" if n.empty?
> >> raise ArgumentError, "can''t contain
spaces" if ( n =~ %r(\s+) )
> >> resource[:provider] = :rabbitmq_user
> >> end
> >>
> >> isnamevar
> >> end
> >>
> >> newparam(:initial_password) do
> >> desc "the password for the user - only set on creation
time"
> >>
> >> defaultto ''foo''
> >
> >
> >> validate do |n|
> >> raise ArgumentError, "cannot be empty" if
(n.empty? or n.nil?)
> >> resource[:provider] = :rabbitmq_user
> >> end
> >> end
> >>
> >
> > validate do
> > raise ArgumentError "initial_password is a required
param" unless
> > self[:initial_password]
> > end
> >
> >> 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<puppet-users%2Bunsubscribe@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<puppet-users%2Bunsubscribe@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.
>
On Jan 21, 11:13 am, Dick Davies <rasput...@hellooperator.net> wrote:> ensurable do > defaultto ''present'' > endI''ve always specified the methods: ensurable do newvalue(:present) do provider.create end newvalue(:absent) do provider.destroy end defaultto :present end Which I admit may (habit|superstition). -- 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.
No, that works a treat. Thanks a lot (to all who answered). On Sat, Jan 22, 2011 at 1:00 PM, donavan <donavan@desinc.net> wrote:> On Jan 21, 11:13 am, Dick Davies <rasput...@hellooperator.net> wrote: >> ensurable do >> defaultto ''present'' >> end > > I''ve always specified the methods: > ensurable do > newvalue(:present) do > provider.create > end > newvalue(:absent) do > provider.destroy > end > defaultto :present > end > > Which I admit may (habit|superstition). > > -- > 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.