class Chef::Provisioning::ChefRunData

Attributes

config[R]
current_driver[R]
current_image_options[RW]
current_load_balancer_options[RW]
current_machine_options[RW]
drivers[R]

Public Class Methods

new(config) click to toggle source
# File lib/chef/provisioning/chef_run_data.rb, line 8
def initialize(config)
  @config = config
  @drivers = {}
end

Public Instance Methods

add_machine_options(options, &block) click to toggle source
# File lib/chef/provisioning/chef_run_data.rb, line 79
def add_machine_options(options, &block)
  with_machine_options(Chef::Mixin::DeepMerge.hash_only_merge(current_machine_options, options), &block)
end
connect_to_machine(name, chef_server = nil) click to toggle source
# File lib/chef/provisioning/chef_run_data.rb, line 87
def connect_to_machine(name, chef_server = nil)
  if name.is_a?(ManagedEntry)
    machine_spec = name
  else
    machine_spec = Provisioning.chef_managed_entry_store(chef_server).get(:machine, name)
  end
  Chef::Provisioning.connect_to_machine(machine_spec, config)
end
driver_for(driver) click to toggle source
# File lib/chef/provisioning/chef_run_data.rb, line 83
def driver_for(driver)
  driver.is_a?(String) ? driver_for_url(driver) : driver
end
with_driver(driver, options = nil) { || ... } click to toggle source
# File lib/chef/provisioning/chef_run_data.rb, line 44
def with_driver(driver, options = nil, &block)
  if drivers[driver] && options
    raise "Driver #{driver} has already been created, options #{options} would be ignored!"
  end
  old_driver, old_options = @current_driver, @current_driver_options
  @current_driver, @current_driver_options = driver, options
  if block_given?
    begin
      yield
    ensure
      @current_driver, @current_driver_options = old_driver, old_options
    end
  end
end
with_image_options(value) { || ... } click to toggle source
# File lib/chef/provisioning/chef_run_data.rb, line 32
def with_image_options(value)
  old_value = self.current_image_options
  self.current_image_options = value
  if block_given?
    begin
      yield
    ensure
      self.current_image_options = old_value
    end
  end
end
with_machine_options(value) { || ... } click to toggle source
# File lib/chef/provisioning/chef_run_data.rb, line 20
def with_machine_options(value)
  old_value = self.current_machine_options
  self.current_machine_options = value
  if block_given?
    begin
      yield
    ensure
      self.current_machine_options = old_value
    end
  end
end

Private Instance Methods

driver_for_url(driver_url) click to toggle source
# File lib/chef/provisioning/chef_run_data.rb, line 98
def driver_for_url(driver_url)
  drivers[driver_url] ||= begin
    if driver_url == @current_driver && @current_driver_options
      # Use the driver options if available
      merged_config = Cheffish::MergedConfig.new({ :driver_options => @current_driver_options }, config.to_hash)
      driver = Chef::Provisioning.driver_for_url(driver_url, merged_config)
    else
      driver = Chef::Provisioning.driver_for_url(driver_url, config)
    end
    # Check the canonicalized driver_url from the driver
    if driver.driver_url != driver_url
      if drivers[driver.driver_url] && @current_driver_options
        raise "Canonical driver #{driver.driver_url} for #{driver_url} has already been created!  Current options #{@current_driver_options} would be ignored."
      end
      drivers[driver.driver_url] ||= driver
    else
      driver
    end
  end
end
keys() click to toggle source
# File lib/chef/provisioning/chef_run_data.rb, line 119
def keys
  result = (config.keys || {}).dup
  Array(config.key_path) do |key_path|
    Dir.entries(key_path).each do |key|
      if File.extname(key) == '.pem'
        result[File.basename(key)[0..-5]] ||= key
      end
    end
  end
  result
end