How to do Puppet type which autorequire an existing declaration of another type

222 views
Skip to first unread message

Martin Alfke

unread,
May 10, 2015, 1:03:25 PM5/10/15
to puppet...@googlegroups.com
Hi,

I am working on some types and providers for opennebula network management.

I have one type already finished, which creates the network itself.
Each network can have multiple address ranges.

My idea so far:

onevnet { ’testnet’:
ensure => present,

}

onevnet_addressrange { ‘<name>’:
ensure => present,
onevnet => ‘testnet’,

}

How can I enforce that onevent ‘testnet’ has to be declared?
I found auto require but that seems to be optional (or did I miss something).

You can find the actual code on github: https://github.com/tuxmea/opennebula-puppet-module/tree/onevnet_multinet_provider

Please note:
I am not a developer so please don’t start screaming immediately when seeing the code.
I am happy to receive recommendations and ideas.

Thanks in advance,

Martin

Gavin Williams

unread,
May 10, 2015, 2:37:55 PM5/10/15
to puppet...@googlegroups.com
Martin

Autorequire is what you need...

Take a look at my glassfish module [1] for an example that should do what you're after...

Cheers
Gav

[1] https://github.com/fatmcgav/fatmcgav-glassfish/blob/develop/lib/puppet/type/jdbcresource.rb#L100-103

Gavin Williams

unread,
May 10, 2015, 2:40:05 PM5/10/15
to puppet...@googlegroups.com
Ah, re-reading your post, it looks like you're looking to enforce declaration rather than ordering...

You are correct in that autorequire only ensures ordering, not declaration.

Unfortunately I can't help with enforcing declaration.

Gav

Joseph Karns

unread,
May 10, 2015, 6:00:09 PM5/10/15
to puppet...@googlegroups.com
Hello Martin:

To enforce declaration you should be able to do

onevnet_addressrange { '<name>':
ensure => present,
require => Onevnet['testnet'],
....
}

Thanks
Joseph Karns

jcbollinger

unread,
May 11, 2015, 2:17:16 PM5/11/15
to puppet...@googlegroups.com


On Sunday, May 10, 2015 at 8:03:25 AM UTC-5, Martin Alfke wrote:
Hi,

I am working on some types and providers for opennebula network management.

I have one type already finished, which creates the network itself.
Each network can have multiple address ranges.

My idea so far:

onevnet { ’testnet’:
  ensure => present,
  …
}

onevnet_addressrange { ‘<name>’:
  ensure  => present,
  onevnet => ‘testnet’,
  …
}

How can I enforce that onevent ‘testnet’ has to be declared?
I found auto require but that seems to be optional (or did I miss something).


Autorequire is about order-of-application dependencies between resources under Puppet management.  It is not about which resources should be under management in the first place.  For example, autorequire automatically causes a File's parent directory to be managed before the File itself, provided that the parent is under management.

You should consider structuring your type so that instances do not inherently depend on another resource being declared.  A hard dependency such as that is a good sign that your resource is not properly scoped.

If for some reason you must have a hard dependency, then the easiest route to take might be to specify that the plugin type is for your module's internal use only (though you cannot enforce that), and provide a defined type wrapper for public use.  The wrapper can declare a fixed, unconditional relationship with whatever other resources you like, and catalog building will fail if any of those resources is not declared.


John

Martin Alfke

unread,
May 11, 2015, 3:24:19 PM5/11/15
to puppet...@googlegroups.com
Hi John,

many thanks for your explanation.
I will stay with auto require to allow managing resource B without the need for having the depending A resource declared within puppet too.

Best,

Martin
> --
> You received this message because you are subscribed to the Google Groups "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/d0ce5ac8-100a-42ed-90d5-ee5286c7aa7c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages