Hi, is it possible to choose the provider based on property? For example, I''m trying to develop two different providers for same type of resource. If i use path location on the local filesystem I want provider "local" to be chosen, and if I use link property, then I want provider "remote" to be chosen. For example, this definition should chose provider ''local'': resource { ''a'': path => ''/some/local/disk.iso'', } And this definition should chose provider ''remote'': resource { ''a'': link => ''http://example.com/disk.iso'', } Is this possible without manually specifying "provider => remote"? Also, second question. It would be great if puppet could raise error in case when both conflicting properties are set. For example this should yeild an error: resource { ''a'': path => ''/some/local/disk.iso'', link => ''http://example.com/disk.iso'', } Is this possible? If these questions are more suitable to puppet-dev list, I will post them there. Thank you guys. -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
On Wednesday, July 17, 2013 1:29:20 PM UTC-5, Jakov Sosic wrote:> > Hi, > > is it possible to choose the provider based on property? > > For example, I''m trying to develop two different providers for same type > of resource. If i use path location on the local filesystem I want > provider "local" to be chosen, and if I use link property, then I want > provider "remote" to be chosen. > > For example, this definition should chose provider ''local'': > > resource { ''a'': > path => ''/some/local/disk.iso'', > } > > > And this definition should chose provider ''remote'': > > resource { ''a'': > link => ''http://example.com/disk.iso'', > } > > Is this possible without manually specifying "provider => remote"? > >Not to my knowledge, no. This is not the correct provider paradigm. The provider for a given resource type used on a given node, if not specified explicitly, is supposed to be chosen based on the characteristics of the node, not of the resource. You seem to be artificially separating your provider into two pieces. My recommendation would be to create one provider whose behavior varies according to the resource''s properties, instead of trying to make the choice between different providers depend on resource properties.> > Also, second question. It would be great if puppet could raise error in > case when both conflicting properties are set. For example this should > yeild an error: > > resource { ''a'': > path => ''/some/local/disk.iso'', > link => ''http://example.com/disk.iso'', > } > > Is this possible? >I think you can use the property validation hook to accomplish this. It is focused on validating individual properties, and there is no guarantee of which property will be validated first, but all you really need is to raise / check a flag an the resource instance as part of the validation of each of those properties. You raise an ArgumentError if the validation code for either property finds that the flag is already raised. See http://docs.puppetlabs.com/guides/custom_types.html for general details on the property validation hook.> > If these questions are more suitable to puppet-dev list, I will post > them there. Thank you guys. >No, puppet-dev is for discussion of the development of Puppet itself, not for questions about its use. "Development" of Puppet manifests is a usage issue with respect to the Puppet program. John -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
On 07/18/2013 03:07 PM, jcbollinger wrote:> Not to my knowledge, no. > > This is not the correct provider paradigm. The provider for a given > resource type used on a given node, if not specified explicitly, is > supposed to be chosen based on the characteristics of the node, not of > the resource. You seem to be artificially separating your provider into > two pieces. My recommendation would be to create one provider whose > behavior varies according to the resource''s properties, instead of > trying to make the choice between different providers depend on resource > properties.Thing I''m trying to accomplish is to enable the ''cobblerdistro'' provider to be able to add new distro to cobbler either via ''cobbler distro add'' or ''cobbler import''. Those two commands work very differently, and although a result of both is a ''distro'' (in cobbler terms), they are quite different. So, I was thinking maybe to develop separate providers, and the one that is called depends on the params/properties set.> I think you can use the property validation hook to accomplish this. It > is focused on validating individual properties, and there is no > guarantee of which property will be validated first, but all you really > need is to raise / check a flag an the resource instance as part of the > validation of each of those properties. You raise an ArgumentError if > the validation code for either property finds that the flag is already > raised. See http://docs.puppetlabs.com/guides/custom_types.html for > general details on the property validation hook.OK, I will try that.> No, puppet-dev is for discussion of the development of Puppet itself, > not for questions about its use. "Development" of Puppet manifests is a > usage issue with respect to the Puppet program.Although this is a provider discussion and not pure manifest... that''s why I asked. Thank you jcbollinger! -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.