Sha256: bd56125a863510286ecbf51d14f3c7023545894defad1f16b3e081d7227c0d34

Contents?: true

Size: 1.97 KB

Versions: 3

Compression:

Stored size: 1.97 KB

Contents

# 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_file'
require 'chef/provider/machine_file'

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
  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
    end
  end

  def self.inline_resource(action_handler, &block)
    InlineResource.new(action_handler).instance_eval(&block)
  end

  @@enclosing_provisioner = nil
  def self.enclosing_provisioner
    @@enclosing_provisioner
  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

  @@registered_provisioner_classes = {}
  def self.add_registered_provisioner_class(name, provisioner)
    @@registered_provisioner_classes[name] = provisioner
  end

  def self.provisioner_for_node(node)
    provisioner_url = node['normal']['provisioner_output']['provisioner_url']
    cluster_type = provisioner_url.split(':', 2)[0]
    require "chef_metal/provisioner_init/#{cluster_type}_init"
    provisioner_class = @@registered_provisioner_classes[cluster_type]
    provisioner_class.inflate(node)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
chef-metal-0.7 lib/chef_metal.rb
chef-metal-0.6 lib/chef_metal.rb
chef-metal-0.5 lib/chef_metal.rb