lib/chef_metal.rb in chef-metal-0.9.4 vs lib/chef_metal.rb in chef-metal-0.10
- old
+ new
@@ -1,61 +1,39 @@
# Include recipe basics so require 'chef_metal' will load everything
require 'chef_metal/recipe_dsl'
require 'chef/resource/machine'
require 'chef/provider/machine'
+require 'chef/resource/machine_batch'
+require 'chef/provider/machine_batch'
require 'chef/resource/machine_file'
require 'chef/provider/machine_file'
require 'chef/resource/machine_execute'
require 'chef/provider/machine_execute'
+require 'chef/server_api'
+require 'cheffish/basic_chef_client'
-require 'chef_metal/inline_resource'
-
module ChefMetal
- def self.with_provisioner(provisioner)
- old_provisioner = ChefMetal.enclosing_provisioner
- ChefMetal.enclosing_provisioner = provisioner
- if block_given?
- begin
- yield
- ensure
- ChefMetal.enclosing_provisioner = old_provisioner
- end
- end
+ def self.inline_resource(action_handler, &block)
+ events = ActionHandlerForward.new(action_handler)
+ Cheffish::BasicChefClient.converge_block(nil, events, &block)
end
- def self.with_provisioner_options(provisioner_options)
- old_provisioner_options = ChefMetal.enclosing_provisioner_options
- ChefMetal.enclosing_provisioner_options = provisioner_options
- if block_given?
- begin
- yield
- ensure
- ChefMetal.enclosing_provisioner_options = old_provisioner_options
- end
+ class ActionHandlerForward < Chef::EventDispatch::Base
+ def initialize(action_handler)
+ @action_handler = action_handler
end
- end
- def self.inline_resource(action_handler, &block)
- InlineResource.new(action_handler).instance_eval(&block)
- end
+ attr_reader :action_handler
- @@enclosing_provisioner = nil
- def self.enclosing_provisioner
- @@enclosing_provisioner
+ def resource_update_applied(resource, action, update)
+ prefix = action_handler.should_perform_actions ? "" : "Would "
+ update = Array(update).map { |u| "#{prefix}#{u}"}
+ action_handler.performed_action(update)
+ end
end
- def self.enclosing_provisioner=(provisioner)
- @@enclosing_provisioner = provisioner
- end
- @@enclosing_provisioner_options = nil
- def self.enclosing_provisioner_options
- @@enclosing_provisioner_options
- end
- def self.enclosing_provisioner_options=(provisioner_options)
- @@enclosing_provisioner_options = provisioner_options
- end
-
+ # Helpers for provisioner inflation
@@registered_provisioner_classes = {}
def self.add_registered_provisioner_class(name, provisioner)
@@registered_provisioner_classes[name] = provisioner
end