Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Chef resource is now fully generic

  • Loading branch information...
commit 508fa50fba229a7bad91f4e6be0f4f17378270b6 1 parent b6ca6c4
Nicolas Szalay authored
Showing with 20 additions and 6 deletions.
  1. +11 −0 clients/generic_chefresource.rb
  2. +9 −6 plugins/agents/chef-resource.rb
11 clients/generic_chefresource.rb
View
@@ -0,0 +1,11 @@
+require 'mcollective'
+include MCollective::RPC
+
+mc = rpcclient("chefresource")
+mc.progress = false
+
+r = [ { "action" => "restart" }, { "supports" => {:status => true } } ]
+
+mc.handle(:resourcename => "cron", :resourcetype => "service", :resourceactions => r).each do |resp|
+ puts resp[:sender] + " => " + resp[:status].inspect
+end
15 plugins/agents/chef-resource.rb
View
@@ -15,7 +15,6 @@ class Chefresource<RPC::Agent
action "handle" do
validate :resourcetype, String
validate :resourcename, String
- validate :resourceaction, String
require 'chef'
require 'chef/client'
@@ -31,11 +30,15 @@ class Chefresource<RPC::Agent
run_context = Chef::RunContext.new(client.node, Chef::CookbookCollection.new(Chef::CookbookLoader.new))
recipe = Chef::Recipe.new("adhoc", "default", run_context)
- resource = recipe.send(request[:resourcetype].to_sym, request[:resourcename])
- resource.send("action",request[:resourceaction])
- # add generic handling of more arguments
-
- Log.instance.debug("Doing '#{request[:resourceaction]}' for resource #{request[:resourcetype]} '#{request[:resourcename]}'")
+ # create the resource
+ resource = recipe.send(request[:resourcetype].to_sym, request[:resourcename])
+ # insert action, attribute, whatever supported by your resource type
+ request[:resourceactions].each { |action|
+ action.each_pair { |k,v|
+ resource.send(k,v)
+ }
+ }
+ Log.instance.debug("Converging for resource #{request[:resourcetype]} '#{request[:resourcename]}'")
status=Chef::Runner.new(run_context).converge
reply["status"] = status
Please sign in to comment.
Something went wrong with that request. Please try again.