On Tuesday, October 23, 2012 9:20:25 AM UTC-5, Ray wrote:
>
> Hi,
>
> I want Puppet to talk to the CloudStack API. CloudStack has many 
> asynchronous API calls and Puppet's catalog run tends to expire even during 
> simple tasks such as adding port forwarding rules:
>
> root@puppet30client:~# puppet agent --test
> Info: Retrieving plugin
> Info: Loading facts in /var/lib/puppet/lib/facter/centos_version.rb
> Info: Loading facts in /var/lib/puppet/lib/facter/network-bonds.rb
> Info: Loading facts in /var/lib/puppet/lib/facter/powerstates.rb
> Info: Loading facts in /var/lib/puppet/lib/facter/software_raid.rb
> Info: Loading facts in /var/lib/puppet/lib/facter/centos-version.rb
>
> Error: Could not retrieve catalog from remote server: execution expired
> Warning: Not using cache on failed catalog
> Error: Could not retrieve catalog; skipping run
> root@puppet30client:~# 
>
>
> When I grant the puppetrun more time than the default 2 minutes, it comes 
> back successfully:
>
> root@puppet30client:~# puppet agent --test --configtimeout 5m
> Info: Retrieving plugin
> Info: Loading facts in /var/lib/puppet/lib/facter/centos_version.rb
> Info: Loading facts in /var/lib/puppet/lib/facter/network-bonds.rb
> Info: Loading facts in /var/lib/puppet/lib/facter/powerstates.rb
> Info: Loading facts in /var/lib/puppet/lib/facter/software_raid.rb
> Info: Loading facts in /var/lib/puppet/lib/facter/centos-version.rb
>
> Info: Caching catalog for puppet30client.swisstxt.ch
> Info: Applying configuration version '1351000748'
> Finished catalog run in 1.88 seconds
> root@puppet30client:~# 
>
> (Don't believe the 1.88 seconds - this run took about three minutes(!))
>
>
> My question is: What is the best practise to let Puppet interact with the 
> CloudStack API?
>
>
> What I did:
>
> 1) Created a csapiclient module and dumped a custom function: 
> /etc/puppet/modules/csapiclient/lib/puppet/parser/functions/add_pf_rule.rb
>
> require File.join(File.dirname(__FILE__), 'cloudstack_client')
>
> module Puppet::Parser::Functions
>   newfunction(:add_pf_rule) do |args|
>     apiurl = args[0]
>     apikey = args[1]
>     secretkey = args[2]
>     proto = args[3]
>     pubPort = args[4]
>     privPort = args[5]
>     ipId = args[6]
>     vmId = args[7]
>
>     cs = CloudstackClient::Connection.new(apiurl,apikey,secretkey)
>
>     cs.create_port_forwarding_rule( ipId, privPort, proto, pubPort, vmId)
>   end
> end
>
> 2) Wrote a defined resource that calls the Ruby function:
>
>     define addPFRule( $ipId, $vmId, $proto, $pubPort, $privPort ) {
>         # Pass arguments to Ruby function…
>         add_pf_rule( $apiUrl, $apiKey , $secretKey, $proto, $pubPort, 
> $privPort, $ipId, $vmId )
>     }
>
> 3) Call the define from a recipe, feeding it with parameters.
>
> Is this a viable way to go or are there better/simpler/more beautiful 
> solutions to talk to CloudStack?
>


Yes.  You want a custom (Ruby) type and provider instead of a custom 
function to wrap the Cloudstack API.  As a bonus, you then won't have any 
use for a wrapper definition (supposing actually you have one now).

What you actually wrote is rather strange.  Puppet functions run on the 
master, so your code makes *the master* execute  the CloudStack 
configuration commands.  That can work, in principle, but it's not the 
execution model that Puppet was designed for.  The master should be tasked 
only with the compiling a catalog; actual configuration tasks should run on 
clients.

Furthermore, because functions run on the master, it is rarely useful to 
write a definition that does nothing but wrap a function call.  The 
resulting defined-type resource instance is just an empty marker in the 
catalog (except in a handful of special cases such as when the function 
called is 'include' or 'create_resources').  Usually, it is better and 
clearer to just call a function directly than to declare an instance of a 
wrapper resource.


John

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/puppet-users/-/FFW0uQ9UhmoJ.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to