Access Catalog from validate block in custom type

23 views
Skip to first unread message

Gavin Williams

unread,
Mar 6, 2015, 6:18:05 AM3/6/15
to puppet...@googlegroups.com
Morning all

I'm trying to add some validation to a new type I've written[1] for my Puppet-glassfish module[2].

As part of the validation, I need to access the current catalog to make sure that there's no another resources defined with the same :name and :target values.
The reason behind this is that the Glassfish provider command will fail if there is, and I'd like to prevent that by validating at the type level...  

The validate block I've added is here[3], which I've modelled closely on an autorequire block[4]. 
However whenever I try and run the spec tests, it fails with: 'undefined method `catalog` for nil:NilClass'. [5]

I've tried changing line 85 to different values, such as 'catalog.resources', 'self.catalog.resources', '@catalog.resources', '@resource.catalog.resources', and all return the same error... 

So is it possible to access the catalog from within a validate block? 
Or is there a better way to achieve what I'm trying to do? 

Cheers in advance for any replies. 

Regards
Gavin 

Henrik Lindberg

unread,
Mar 6, 2015, 9:25:29 AM3/6/15
to puppet...@googlegroups.com
On 2015-06-03 12:18, Gavin Williams wrote:
> Morning all
>
> I'm trying to add some validation to a new type I've written[1] for my
> Puppet-glassfish module[2].
>
> As part of the validation, I need to access the current catalog to make
> sure that there's no another resources defined with the same /:name/ and
> /:target /values.

If name is the same as title of the resource, then by definition there
will never be two resources with the same title/name in the catalog.
This is enforced by the compiler.

If you need a complex key (name and target), then you could use both as
title, and split it up in the type.

- henrik

>
> --
> 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
> <mailto:puppet-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/66050a1f-b969-4852-b271-8b7526b307cf%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/66050a1f-b969-4852-b271-8b7526b307cf%40googlegroups..com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

Gavin Williams

unread,
Mar 6, 2015, 9:59:07 AM3/6/15
to puppet...@googlegroups.com
Henrik

Cheers for the response. 

I possibly didn't explain it that clearly... This resource is trying to match the name of a different resource with the same target. 

E.g, I was trying to guard against this:  
# JMS resource
jmsresource { 'jms/test':
  ensure => present,
  restype => 'javax.jms.Topic',
  target => 'testCluster',
}

resourceref { 'jms/test':
  ensure => present,
  target => 'testCluster'
}

Trying to do this via the Glassfish CLI would fail. 

However it looks like I was trying to guard against a scenario that isn't going to happen, as the resourceref.exists? matches the resource created by jmsresource
So even if someone does provide the above resources, they won't get an error... 

Cheers
Gavin 

On Friday, 6 March 2015 14:25:29 UTC, Henrik Lindberg wrote:
On 2015-06-03 12:18, Gavin Williams wrote:
> Morning all
>
> I'm trying to add some validation to a new type I've written[1] for my
> Puppet-glassfish module[2].
>
> As part of the validation, I need to access the current catalog to make
> sure that there's no another resources defined with the same /:name/ and
> /:target /values.

If name is the same as title of the resource, then by definition there
will never be two resources with the same title/name in the catalog.
This is enforced by the compiler.

If you need a complex key (name and target), then you could use both as
title, and split it up in the type.

- henrik

>
> --
> 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
Reply all
Reply to author
Forward
0 new messages