Hi,

On 20/07/11 22:15, Nan Liu wrote:
> All:
> 
> I know Brice is the expert. Not sure if anyone else wants to dive in
> and give some quick hints on how to extend Puppet 2.7 network devices.

Foreword: the work I did is very basic in terms of code helping support
other devices (beside the transport stuff itself that you apparently
don't need). My point is that I believe we'll see more patterns of
similarities when adding new device types, from which we would refactor
the commonalities.

But that's awesome to have someone else willing to add more devices :)

> 1. Network devices are a bit weird, since they don't collect facts
> through facter, the cisco device facts reside in:
> lib/puppet/util/network_device/cisco/facts.rb

I didn't want to extend Facter with the exact same transport and device
system as I included in puppet just to return a bunch of facts. So for
the moment facts are outside of facter.

> I'm presuming instead of writing custom facts in the regular location,
> simply use lib/puppet/util/network_device/f5/..? Not too sure what's
> the best way to test this without invoking a full puppet run and
> digging through yaml file on server side.

The problem with testing the network device is that you actually need
the said device :)
But you can unit test the facts. In the cisco case I extracted some
textual configs of some of the device I had access to and used this to
feed the spec tests, checking the returned facts matched what I was
expected. I believe you can do the same for F5 (and by that I admit my
total ignorance of those devices).

Note that we might be able to extract the common architecture of facts
extraction from both the cisco and f5 implementation. One reason I
didn't even try was that it's difficult to generalize when you'll have
only one implementation.

> 2. In terms of developing, at the moment I'm writing F5 as puppet
> resources with connectivity hardcoded to simplify testing since I can
> run puppet resource f5_rules and get instant feedback. Not sure if
> anyone can give some tips on testing (perhaps a Brice only question).
> I'm planning to refactor later so it's implemented as a
> network_device.

That's how I first tested the system. I started doing everything in the
provider and the network_device, and was testing with puppet apply.
My pattern for testing was first to manually extract the various bits of
configs from the device, then I created the specs, implemented the
parsing, and then finally checked with puppet apply I was able to apply
configs to the target device.

> 3. I'm repeating over and over again in certain sections, and I'm
> trying to to simplify them (I suppose time to learn metaprogramming in
> Ruby?) for example the way to retrieve resource attributes are pretty
> similar:
> 
>  24   def action_on_service_down
>  25     @@bigip[@@modules].get_action_on_service_down(resource[:name]).first
>  26   end
>  27
>  28   def allow_nat_state
>  29     @@bigip[@@modules].get_allow_nat_state(resource[:name]).first
>  30   end

You can refactor this with a bit of metaprogramming:
%w{on_service_down allow_nat_state}.each do |m|
  define_method(m.to_sym) do
    @@bigip[@@modules].send("get_#{m}", resource[:name]).first
  end
end

It might be possible to even go further with a method_missing
implementation.

> 4. F5 uses icontrol gem via soap to query/manipulate the device, so I
> don't need most of the network_device functionality. I just need to
> parse the device url string to obtain the username/password/ip. That's
> not the problematic part, the issue I'm running into is it's not
> loading the f5 provider:
> 
> class Puppet::Provider::F5 < Puppet::Provider::NetworkDevice
>   def self.device(url='ssh://admin:[email protected]/')
>     Puppet::Util::NetworkDevice::F5::Device.new(url)
>   end
> end
> 
> I was hoping to stub this so I can do testing without a full puppet
> run, not sure if that's the right way. The problem at the moment is it
> simply can't find the provider F5. and I have no idea why it's not
> seeing this file, where should this be placed in the modules
> directory? It's currently in modules f5 lib/puppet/provider/f5.rb:
> Could not run: Could not autoload f5_pool: Could not autoload
> /Users/nan/.puppet/modules/f5/lib/puppet/provider/f5_pool/f5_pool.rb:
> Could not find parent provider F5 of f5_pool

I'm not sure what could be the problem :(
Could it be a case sensitivity issue of the f5.rb file?
Do you have the f5.rb file in lib/puppet/provider?
What's in the f5_pool.rb file?

I'm usually available during CEST day time on #puppet-dev if you need
live discussion.

Hope that helps,
-- 
Brice Figureau
My Blog: http://www.masterzen.fr/

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to