Attribute to be ":kind of" another resource?


#1

Can I have an attribute that is kind of another resource ?

here is my scenario,

I have a resource called BinaryServer and let say it has attributes like
(name, installation_dir, version )

I have another resource called AdminServer

in AdminServes provider I wanna access the Binary Server’s attribute.

I was wondering if I could have an attribute type of BinaryServer,
so I could do this,
new_resource.binary_server.installation_dir

ideas?


#2

you can. you can also get a resource identifier as string like
"template[/foo/bar]", and construct the resource back in your provider,
chef has helper for all this. but in chef resources are generally
decoupled, and communication are done as notifications. this also
decouples what & when to do when a notification is receive. you’ll
complicate all those things, as the order of the consumed resource etc will
matter.

why not hide the other resource as a sub resource ? i.e. construct
BinaryServer inside AdminServer, then AdminServer can expose a
binary_server attribute to customize the underlying BinaryServer , but its
opaque to the consumer.

regards
ranjib

On Tue, Feb 17, 2015 at 9:46 AM, Medya medya.gh@gmail.com wrote:

Can I have an attribute that is kind of another resource ?

here is my scenario,

I have a resource called BinaryServer and let say it has attributes like
(name, installation_dir, version )

I have another resource called AdminServer

in AdminServes provider I wanna access the Binary Server’s attribute.

I was wondering if I could have an attribute type of BinaryServer,
so I could do this,
new_resource.binary_server.installation_dir

ideas?


#3

you can do this pretty easily, i think kind_of just takes a class name as
an argument, so you could just say :kind_of => Chef::Resource::BinaryServer. I do something very similar in the
haproxy-ng cookbook, but via callbacks, as the attribute takes multiples:

https://github.com/nathwill/chef-haproxy-ng/blob/master/libraries/00_haproxy_instance.rb#L66-L69

Regards,

Nathan Williams

On Tue, Feb 17, 2015 at 9:46 AM, Medya medya.gh@gmail.com wrote:

Can I have an attribute that is kind of another resource ?

here is my scenario,

I have a resource called BinaryServer and let say it has attributes like
(name, installation_dir, version )

I have another resource called AdminServer

in AdminServes provider I wanna access the Binary Server’s attribute.

I was wondering if I could have an attribute type of BinaryServer,
so I could do this,
new_resource.binary_server.installation_dir

ideas?