Hi Mo,
On Thu, 2011-05-05 at 00:41 -0400, Mo Morsi wrote:
Introduces a generic web puppet resource type to access various
web
apis from puppet. Implements a provider of this type using curl to
issue the requests.
Then uses this provider to issue requests to the conductor api to
create providers and hardware profiles, analyzing the results for
errors
Tricky stuff! Even though curl.rb is considerably more complex than
exec-ing the curl command lines, the resulting web resources are much
nicer. Cool stuff :)
ACK from my FWIW, but some comments inline
diff --git a/recipes/aeolus_recipe/lib/puppet/provider/web/curl.rb
b/recipes/aeolus_recipe/lib/puppet/provider/web/curl.rb
new file mode 100644
index 0000000..b5f4468
--- /dev/null
+++ b/recipes/aeolus_recipe/lib/puppet/provider/web/curl.rb
....
+# Puppet provider definition
+Puppet::Type.type(:web).provide :curl do
+ desc "Use curl to access web resources"
+
+ def http_method
+ @request_method
+ end
+
+ def http_method=(request_method)
+ begin
+ # Set request method and generate a unique session key
+ @request_method = request_method
+ session = "/tmp/#{UUID.new.generate}"
+
+ # Invoke a login request if necessary
...
I'm a bit surprised to see all this happening in http_method=
Care to explain why, just for my own education? :)
+define
aeolus::conductor::provider($type="",$url=""){
+ web{ "provider-$name":
+ uri => "https://localhost/conductor/admin/providers",
+ http_method => 'post',
+ parameters => { 'provider[name]' => $name, 'provider[url]'
=> $url,
+ 'provider[provider_type_codename]' => $type },
+ returns => '200',
+ verify => '.*Provider added.*',
+ follow => true,
+ unless => { 'http_method' => 'get',
+ 'uri' =>
'https://localhost/conductor/admin/providers',
+ 'verify' => ".*$name.*" },
Would something like this be better:
unless => { http_method => 'get',
uri =>
'https://localhost/conductor/admin/providers',
parameters => { 'q' => $name },
verify =>
".*/admin/providers/.*>$name</a>.*" }
i.e. run a search query and use a more specific regexp?
Also, now that I type that ... it looks like "unless" doesn't re-use the
web type, right? i.e. parameters are automatically provided? It'd be
cool if it re-used the same type somehow
+define aeolus::conductor::hwp($memory='', $cpu='',
$storage='', $architecture=''){
+ web{ "hwp-$name":
+ uri => "https://localhost/conductor/admin/hardware_profiles",
+ http_method => 'post',
+ parameters => {'hardware_profile[name]' => $name,
+ 'hardware_profile[memory_attributes][value]' =>
$memory,
+ 'hardware_profile[cpu_attributes][value]' =>
$cpu,
+ 'hardware_profile[storage_attributes][value]' =>
$storage,
+ 'hardware_profile[architecture_attributes][value]' =>
$architecture,
+ 'hardware_profile[memory_attributes][name]' =>
'memory',
+ 'hardware_profile[memory_attributes][unit]' =>
'MB',
+ 'hardware_profile[cpu_attributes][name]' =>
'cpu',
+ 'hardware_profile[cpu_attributes][unit]' =>
'count',
+ 'hardware_profile[storage_attributes][name]' =>
'storage',
+ 'hardware_profile[storage_attributes][unit]' =>
'GB',
+ 'hardware_profile[architecture_attributes][name]' =>
'architecture',
+ 'hardware_profile[architecture_attributes][unit]' =>
'label',
+ 'commit' => 'Save'},
+ returns => '200',
+ #verify => '.*Hardware profile added.*',
+ follow => true,
+ unless => { 'http_method' => 'get',
+ 'uri' =>
'https://localhost/conductor/admin/hardware_profiles',
+ 'verify' => ".*$name.*" },
Is there something weird going on with GET on the hardware_profiles
resource?
Without 'Accept: text/html', I'm seeing:
The error occurred while evaluating nil.[]):
app/controllers/admin/hardware_profiles_controller.rb:206:in
`build_hardware_profile'
app/controllers/admin/hardware_profiles_controller.rb:14:in `index'
app/controllers/admin/hardware_profiles_controller.rb:11:in `index'
compass (0.10.4)
lib/compass/app_integration/rails/actionpack2/action_controller.rb:7:in `process'
i.e. it's following the "format.js" path and breaking. Is that a
conductor bug?
If you supply 'Accept: text/html' does the commented out "verify" above
start working? An accept header seems like a reasonable parameter for
the web type to support
diff --git a/recipes/aeolus_recipe/manifests/defaults.pp
b/recipes/aeolus_recipe/manifests/defaults.pp
index f5c74c3..57b79f6 100644
--- a/recipes/aeolus_recipe/manifests/defaults.pp
+++ b/recipes/aeolus_recipe/manifests/defaults.pp
@@ -8,3 +8,16 @@
Package {provider => 'rpm'}
+$admin_user='admin'
+$admin_password='password'
+
+# Setup the default login/logout targets for web requests
+Web{
+ login => { 'http_method' => 'post',
+ 'uri' =>
'https://localhost/conductor/user_session',
+ 'user_session[login]' => "$admin_user",
+ 'user_session[password]' => "$admin_password",
+ 'commit' => 'submit' },
+ logout => { 'http_method' => 'post',
+ 'uri' =>
'https://localhost/conductor/logout' }
A GET on /logout will work too, a POST isn't needed
Cheers,
Mark.