Resource Hash from vmware-lib

71 views
Skip to first unread message

Shook Shivers

unread,
Mar 5, 2014, 12:56:08 PM3/5/14
to puppe...@googlegroups.com
I get Error: Could not prefetch zenoss_device provider 'zenoss_device': undefined local variable or method `resource' for Puppet::Type::Zenoss_device::ProviderZenoss_device:Class when using the following

def self.prefetch(r)
        @transport ||= PuppetX::Puppetlabs::Transport.retrieve(:resource_ref => resource[:transport], :catalog => resource.catalog, :provider => 'vsphere')

    p "#{r}"
  end

The above is only for testing purposes

Im writing a type provider for zenoss my first so please be kind and im trying to access the  resource hash but cannot

All id like to know is what module (is it the provider) that will allow me to access this resource hash

I tried accessing it from within a provider but that does not work "resource[:transport]". 

Im using a usefull hack from https://github.com/vmware/vmware-vmware_lib where instead of using a SSH as a connector im using a Rest class i created for connecting to a Zenoss master

I guess the issue here is how do I use this transport type provider

Any clues anyone??

John Bollinger

unread,
Mar 6, 2014, 2:32:06 PM3/6/14
to puppe...@googlegroups.com


If you have not already done so, you should read PuppetLabs's docs on the subject.  In particular, see http://docs.puppetlabs.com/guides/provider_development.html.

Specifically with regard to your issue, however, you should probably be writing an instances() method, not a prefetch() method.  The latter is supplied by Puppet.  Furthermore, neither of those is an instance method of the provider class (how could they be?), so there cannot be any specific resource to refer to unless you select one by some mechanism.  Indeed, choosing which resource instance, if any, to assign to each discovered provider instance is the a large part of the job of the provider class's prefetch() method.

Note, too, that prefetching is an optional behavior.  If it is not feasible for your provider class to identify and enumerate all initially-available instances, then its instances() method should simply return an empty list.  That will have some implications for other aspects of the provider implementation, but it is a reasonable approach.  Not every conceivable resource type can be prefetched (consider File, for example).


John

Nan Liu

unread,
Mar 7, 2014, 10:36:13 AM3/7/14
to puppet-dev
On Wed, Mar 5, 2014 at 11:56 AM, Shook Shivers <shooks...@gmail.com> wrote:
I get Error: Could not prefetch zenoss_device provider 'zenoss_device': undefined local variable or method `resource' for Puppet::Type::Zenoss_device::ProviderZenoss_device:Class when using the following

def self.prefetch(r)
        @transport ||= PuppetX::Puppetlabs::Transport.retrieve(:resource_ref => resource[:transport], :catalog => resource.catalog, :provider => 'vsphere')

    p "#{r}"
  end

You should wrap the transport in a method. The reason Transport.retrieve exists is to allow all providers to reuse the same connection to the same servers (matters more for ssh than something stateless like REST). The provider indicate what type of transport, and in this case this starts a vsphere connection specified here:


This is unlikely what you want based on the description below.

The above is only for testing purposes

Im writing a type provider for zenoss my first so please be kind and im trying to access the  resource hash but cannot

All id like to know is what module (is it the provider) that will allow me to access this resource hash

I tried accessing it from within a provider but that does not work "resource[:transport]". 

Im using a usefull hack from https://github.com/vmware/vmware-vmware_lib where instead of using a SSH as a connector im using a Rest class i created for connecting to a Zenoss master

I guess the issue here is how do I use this transport type provider

Any clues anyone??


There's another prototype with WinRM:

Originally I decided to split the transport provider to multiple modules, since the module author would have much better understanding of their requirements. At this point, maybe a standalone transport modules makes more sense. My goal is to have a module that:

1. provides several built in transport such as ssh, rest, winrm, (suggestions?)
2. allows multiple provider to pass credential (currently specified in the resource, but should allow device.conf and perhaps others on client encrypted credentials).
3. ???

I'm happy to collaborate if your module is opensource, or consult if this is private. Just email me. Thanks,

Nan

Shook Shivers

unread,
Mar 8, 2014, 2:49:51 PM3/8/14
to puppe...@googlegroups.com
In regards to the prefetching the self.instance method of the Provider class I can use one call to provide at least half of the attributes I created for the type (add_device).  Obviously i did nto want this to be an expensive operation. 

I hacked together a ruby script that does pretty much everything in regards to device and class creation, modification and removal.  As i was learnign to put this together it dawned on me that there was no way i could reliably provide connection info without duplicating code for every provider and this i read Nans and Bodes threads and borrowed the code but have come unstuck when in a few places. 

The issue at the moment is getting access to the resource hash - from the provider.  Once thats solved Im almost on a home straight.

So how do i access the resource type.  Im using the provider type to test whether I can access it.  I am also running this without Puppet master.

In clues on how to access the resource hash
Reply all
Reply to author
Forward
0 new messages